Skip to content

Commit 7590970

Browse files
refactor(types): promote protocol types to agentex.protocol.*
Moves the JSON-RPC envelope types and ACP method-param types out of the hand-authored ADK overlay (agentex.lib.types.*) into a new canonical location at agentex.protocol.*. Back-compat shims at the old paths re-export the same classes, so existing imports continue to work. Motivation: The existing layout puts protocol-shape types under agentex.lib.types. That means a REST-only consumer who just wants typed JSON-RPC envelopes (e.g. egp-api-backend, which today hand-rolls a ~600-line gateway constructing `{"jsonrpc": "2.0", "method": "task/create", ...}` dicts by hand) can't import the types without pulling in the full heavy ADK runtime (~31 deps including temporalio, fastapi, claude-agent-sdk, etc.). This is the first step toward letting that consumer drop hand-rolled dict literals in favor of typed CreateTaskParams / SendMessageParams / SendEventParams / JSONRPCRequest / JSONRPCResponse models, ahead of the forthcoming slim-package split (a separate PR). Scope: - Move src/agentex/lib/types/acp.py → src/agentex/protocol/acp.py - Move src/agentex/lib/types/json_rpc.py → src/agentex/protocol/json_rpc.py - json_rpc.py: switch from `agentex.lib.utils.model_utils.BaseModel` (which transitively imports pyyaml) to `pydantic.BaseModel` directly. These classes don't use any model_utils extensions (from_yaml, to_json, populate_by_name) so the swap is behavior-preserving. - Add re-export shims at the old paths so existing `from agentex.lib.types.{acp,json_rpc} import ...` imports continue to work. Identity check confirms the shimmed and canonical classes are the same objects. - Update all internal usages within agentex.lib.* to import from the canonical path (9 files in src/agentex/lib + 1 in tests/). Files moved use only pydantic + agentex.types.{Task,Agent,Event, TaskMessageContent} — all slim-safe deps. Other agentex.lib.types.* modules with heavier deps (fastacp pulls temporal, converters pulls openai-agents) are left in place. Verified locally: - ruff check . → All checks passed - Wheel build → ships both agentex/protocol/* and shims at agentex/lib/types/{acp,json_rpc}.py - Import test from a fresh editable install: both canonical and shim paths resolve to the same class objects (identity-checked) Zero install-time impact for existing consumers — same import paths keep working. Tracking: AGX1-292 (the slim/heavy split that motivates this refactor lands as a follow-up PR). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 38ed338 commit 7590970

15 files changed

Lines changed: 217 additions & 177 deletions

File tree

src/agentex/lib/core/temporal/services/temporal_task_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from agentex.types.task import Task
77
from agentex.types.agent import Agent
88
from agentex.types.event import Event
9-
from agentex.lib.types.acp import SendEventParams, CreateTaskParams
9+
from agentex.protocol.acp import SendEventParams, CreateTaskParams
1010
from agentex.lib.environment_variables import EnvironmentVariables
1111
from agentex.lib.core.clients.temporal.types import WorkflowState
1212
from agentex.lib.core.temporal.types.workflow import SignalName

src/agentex/lib/core/temporal/workflows/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from temporalio import workflow
44

5-
from agentex.lib.types.acp import SendEventParams, CreateTaskParams
5+
from agentex.protocol.acp import SendEventParams, CreateTaskParams
66
from agentex.lib.utils.logging import make_logger
77
from agentex.lib.core.temporal.types.workflow import SignalName
88

src/agentex/lib/sdk/fastacp/base/base_acp_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from starlette.types import Send, Scope, ASGIApp, Receive
1515
from fastapi.responses import StreamingResponse
1616

17-
from agentex.lib.types.acp import (
17+
from agentex.protocol.acp import (
1818
RPC_SYNC_METHODS,
1919
PARAMS_MODEL_BY_METHOD,
2020
RPCMethod,
@@ -24,7 +24,7 @@
2424
SendMessageParams,
2525
)
2626
from agentex.lib.utils.logging import make_logger, ctx_var_request_id
27-
from agentex.lib.types.json_rpc import JSONRPCError, JSONRPCRequest, JSONRPCResponse
27+
from agentex.protocol.json_rpc import JSONRPCError, JSONRPCRequest, JSONRPCResponse
2828
from agentex.lib.utils.model_utils import BaseModel
2929
from agentex.lib.utils.registration import register_agent
3030

src/agentex/lib/sdk/fastacp/impl/async_base_acp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22
from typing_extensions import override
33

4-
from agentex.lib.types.acp import (
4+
from agentex.protocol.acp import (
55
SendEventParams,
66
CancelTaskParams,
77
CreateTaskParams,

src/agentex/lib/sdk/fastacp/impl/sync_acp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, override
44
from collections.abc import AsyncGenerator
55

6-
from agentex.lib.types.acp import SendMessageParams
6+
from agentex.protocol.acp import SendMessageParams
77
from agentex.lib.utils.logging import make_logger
88
from agentex.types.task_message_delta import TextDelta
99
from agentex.types.task_message_update import (

src/agentex/lib/sdk/fastacp/impl/temporal_acp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fastapi import FastAPI
77
from temporalio.converter import PayloadCodec
88

9-
from agentex.lib.types.acp import (
9+
from agentex.protocol.acp import (
1010
SendEventParams,
1111
CancelTaskParams,
1212
CreateTaskParams,

src/agentex/lib/sdk/fastacp/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
from agentex.types.task import Task
1515
from agentex.types.agent import Agent
16-
from agentex.lib.types.acp import (
16+
from agentex.protocol.acp import (
1717
CancelTaskParams,
1818
CreateTaskParams,
1919
SendMessageParams,
2020
)
21-
from agentex.lib.types.json_rpc import JSONRPCRequest
21+
from agentex.protocol.json_rpc import JSONRPCRequest
2222
from agentex.types.task_message import TaskMessageContent
2323
from agentex.types.task_message_content import TextContent
2424
from agentex.lib.sdk.fastacp.impl.sync_acp import SyncACP

src/agentex/lib/sdk/fastacp/tests/test_base_acp_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from fastapi.testclient import TestClient
77

8-
from agentex.lib.types.acp import (
8+
from agentex.protocol.acp import (
99
RPCMethod,
1010
SendEventParams,
1111
CancelTaskParams,

src/agentex/lib/sdk/fastacp/tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import httpx
66
import pytest
77

8-
from agentex.lib.types.acp import (
8+
from agentex.protocol.acp import (
99
RPCMethod,
1010
SendEventParams,
1111
CancelTaskParams,

src/agentex/lib/types/acp.py

Lines changed: 13 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,13 @@
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

Comments
 (0)