|
1 | | -from __future__ import annotations |
2 | | - |
3 | | -from enum import Enum |
4 | | -from typing import Any |
5 | | - |
6 | | -from pydantic import Field, BaseModel |
7 | | - |
8 | | -from agentex.types.task import Task |
9 | | -from agentex.types.agent import Agent |
10 | | -from agentex.types.event import Event |
11 | | -from agentex.types.task_message_content import TaskMessageContent |
12 | | - |
13 | | - |
14 | | -class RPCMethod(str, Enum): |
15 | | - """Available JSON-RPC methods for agent communication.""" |
16 | | - |
17 | | - EVENT_SEND = "event/send" |
18 | | - MESSAGE_SEND = "message/send" |
19 | | - TASK_CANCEL = "task/cancel" |
20 | | - TASK_CREATE = "task/create" |
21 | | - |
22 | | - |
23 | | -class CreateTaskParams(BaseModel): |
24 | | - """Parameters for task/create method. |
25 | | -
|
26 | | - Attributes: |
27 | | - agent: The agent that the task was sent to. |
28 | | - task: The task to be created. |
29 | | - params: The parameters for the task as inputted by the user. |
30 | | - request: Additional request context including headers forwarded to this agent. |
31 | | - """ |
32 | | - |
33 | | - agent: Agent = Field(..., description="The agent that the task was sent to") |
34 | | - task: Task = Field(..., description="The task to be created") |
35 | | - params: dict[str, Any] | None = Field( |
36 | | - None, |
37 | | - description="The parameters for the task as inputted by the user", |
38 | | - ) |
39 | | - request: dict[str, Any] | None = Field( |
40 | | - default=None, |
41 | | - description="Additional request context including headers forwarded to this agent", |
42 | | - ) |
43 | | - |
44 | | - |
45 | | -class SendMessageParams(BaseModel): |
46 | | - """Parameters for message/send method. |
47 | | -
|
48 | | - Attributes: |
49 | | - agent: The agent that the message was sent to. |
50 | | - task: The task that the message was sent to. |
51 | | - content: The message that was sent to the agent. |
52 | | - stream: Whether to stream the message back to the agentex server from the agent. |
53 | | - request: Additional request context including headers forwarded to this agent. |
54 | | - """ |
55 | | - |
56 | | - agent: Agent = Field(..., description="The agent that the message was sent to") |
57 | | - task: Task = Field(..., description="The task that the message was sent to") |
58 | | - content: TaskMessageContent = Field( |
59 | | - ..., description="The message that was sent to the agent" |
60 | | - ) |
61 | | - stream: bool = Field( |
62 | | - False, |
63 | | - description="Whether to stream the message back to the agentex server from the agent", |
64 | | - ) |
65 | | - request: dict[str, Any] | None = Field( |
66 | | - default=None, |
67 | | - description="Additional request context including headers forwarded to this agent", |
68 | | - ) |
69 | | - |
70 | | - |
71 | | -class SendEventParams(BaseModel): |
72 | | - """Parameters for event/send method. |
73 | | -
|
74 | | - Attributes: |
75 | | - agent: The agent that the event was sent to. |
76 | | - task: The task that the message was sent to. |
77 | | - event: The event that was sent to the agent. |
78 | | - request: Additional request context including headers forwarded to this agent. |
79 | | - """ |
80 | | - |
81 | | - agent: Agent = Field(..., description="The agent that the event was sent to") |
82 | | - task: Task = Field(..., description="The task that the message was sent to") |
83 | | - event: Event = Field(..., description="The event that was sent to the agent") |
84 | | - request: dict[str, Any] | None = Field( |
85 | | - default=None, |
86 | | - description="Additional request context including headers forwarded to this agent", |
87 | | - ) |
88 | | - |
89 | | - |
90 | | -class CancelTaskParams(BaseModel): |
91 | | - """Parameters for task/cancel method. |
92 | | -
|
93 | | - Attributes: |
94 | | - agent: The agent that the task was sent to. |
95 | | - task: The task that was cancelled. |
96 | | - request: Additional request context including headers forwarded to this agent. |
97 | | - """ |
98 | | - |
99 | | - agent: Agent = Field(..., description="The agent that the task was sent to") |
100 | | - task: Task = Field(..., description="The task that was cancelled") |
101 | | - request: dict[str, Any] | None = Field( |
102 | | - default=None, |
103 | | - description="Additional request context including headers forwarded to this agent", |
104 | | - ) |
105 | | - |
106 | | - |
107 | | -RPC_SYNC_METHODS = [ |
108 | | - RPCMethod.MESSAGE_SEND, |
109 | | -] |
110 | | - |
111 | | -PARAMS_MODEL_BY_METHOD: dict[RPCMethod, type[BaseModel]] = { |
112 | | - RPCMethod.EVENT_SEND: SendEventParams, |
113 | | - RPCMethod.TASK_CANCEL: CancelTaskParams, |
114 | | - RPCMethod.MESSAGE_SEND: SendMessageParams, |
115 | | - RPCMethod.TASK_CREATE: CreateTaskParams, |
116 | | -} |
| 1 | +"""Back-compat shim. The canonical location is :mod:`agentex.protocol.acp`. |
| 2 | +
|
| 3 | +Kept here so existing ``from agentex.lib.types.acp import ...`` imports |
| 4 | +continue to work. New code should import from the canonical path. |
| 5 | +""" |
| 6 | + |
| 7 | +from agentex.protocol.acp import ( # noqa: F401 |
| 8 | + RPCMethod, |
| 9 | + SendEventParams, |
| 10 | + CancelTaskParams, |
| 11 | + CreateTaskParams, |
| 12 | + SendMessageParams, |
| 13 | +) |
0 commit comments