Skip to content

Commit d7367a9

Browse files
declan-scaleclaude
andcommitted
refactor(harness)!: consolidate the Pydantic-AI harness, remove tracing handler
Collapse _pydantic_ai_async / _pydantic_ai_tracing into _pydantic_ai_sync (convert helper) and _pydantic_ai_turn (stream_pydantic_ai_events). Span tracing is derived from the canonical stream by UnifiedEmitter, so create_pydantic_ai_tracing_handler is removed. BREAKING CHANGE: create_pydantic_ai_tracing_handler is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 86da19c commit d7367a9

11 files changed

Lines changed: 240 additions & 1001 deletions

src/agentex/lib/adk/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
emit_langgraph_messages,
1212
convert_langgraph_to_agentex_events,
1313
)
14-
from agentex.lib.adk._modules._pydantic_ai_async import stream_pydantic_ai_events
14+
from agentex.lib.adk._modules._pydantic_ai_turn import PydanticAITurn, stream_pydantic_ai_events
1515
from agentex.lib.adk._modules._pydantic_ai_sync import convert_pydantic_ai_to_agentex_events
16-
from agentex.lib.adk._modules._pydantic_ai_tracing import create_pydantic_ai_tracing_handler
17-
from agentex.lib.adk._modules._pydantic_ai_turn import PydanticAITurn
1816
from agentex.lib.adk._modules._claude_code_sync import convert_claude_code_to_agentex_events
1917
from agentex.lib.adk._modules._claude_code_turn import (
2018
ClaudeCodeTurn,
@@ -75,7 +73,6 @@
7573
# Pydantic AI
7674
"stream_pydantic_ai_events",
7775
"convert_pydantic_ai_to_agentex_events",
78-
"create_pydantic_ai_tracing_handler",
7976
"PydanticAITurn",
8077
# Claude Code
8178
"convert_claude_code_to_agentex_events",

src/agentex/lib/adk/_modules/_pydantic_ai_async.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/agentex/lib/adk/_modules/_pydantic_ai_sync.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@ async def handle_message_send(params):
4141

4242
import json
4343
import inspect
44-
from typing import TYPE_CHECKING, Any, Callable, AsyncIterator
44+
from typing import Any, Callable, AsyncIterator
4545

4646
from pydantic_ai.run import AgentRunResultEvent
47-
48-
if TYPE_CHECKING:
49-
from agentex.lib.adk._modules._pydantic_ai_tracing import (
50-
AgentexPydanticAITracingHandler,
51-
)
5247
from pydantic_ai.messages import (
5348
TextPart,
5449
PartEndEvent,
@@ -124,7 +119,6 @@ def _tool_return_content(result: ToolReturnPart | Any) -> Any:
124119

125120
async def convert_pydantic_ai_to_agentex_events(
126121
stream_response: AsyncIterator[Any],
127-
tracing_handler: "AgentexPydanticAITracingHandler | None" = None,
128122
on_result: Callable[[AgentRunResultEvent], Any] | None = None,
129123
) -> AsyncIterator[StreamTaskMessageStart | StreamTaskMessageDelta | StreamTaskMessageFull | StreamTaskMessageDone]:
130124
"""Convert a Pydantic AI agent event stream into Agentex stream events.
@@ -148,11 +142,6 @@ async def convert_pydantic_ai_to_agentex_events(
148142
stream_response: The async iterator yielded by Pydantic AI's
149143
``agent.run_stream_events(...)`` context manager (or a stream of
150144
``AgentStreamEvent`` items received in an ``event_stream_handler``).
151-
tracing_handler: Optional handler from
152-
``create_pydantic_ai_tracing_handler(...)``. When provided, each
153-
tool call in the run is also recorded as an Agentex child span
154-
beneath the handler's configured ``parent_span_id``. Streaming
155-
behavior is unchanged when omitted.
156145
on_result: Optional callback invoked with the terminal
157146
``AgentRunResultEvent`` when the run completes. Both sync and
158147
async callables are accepted. No ``StreamTaskMessage*`` events are
@@ -306,26 +295,6 @@ async def convert_pydantic_ai_to_agentex_events(
306295
if message_index is None:
307296
continue
308297
yield StreamTaskMessageDone(type="done", index=message_index)
309-
# Tool-call parts end with the model's full args known. Open a
310-
# tracing child span for the tool execution now; close it when
311-
# FunctionToolResultEvent arrives below.
312-
if tracing_handler is not None and isinstance(event.part, ToolCallPart) and event.part.tool_call_id:
313-
args: dict[str, Any] | str | None
314-
raw_args = event.part.args
315-
if isinstance(raw_args, dict):
316-
args = dict(raw_args)
317-
elif isinstance(raw_args, str):
318-
try:
319-
args = json.loads(raw_args) if raw_args else {}
320-
except json.JSONDecodeError:
321-
args = {"_raw": raw_args}
322-
else:
323-
args = {}
324-
await tracing_handler.on_tool_start(
325-
tool_call_id=event.part.tool_call_id,
326-
tool_name=event.part.tool_name,
327-
arguments=args,
328-
)
329298

330299
elif isinstance(event, FunctionToolResultEvent):
331300
result = event.part
@@ -345,11 +314,6 @@ async def convert_pydantic_ai_to_agentex_events(
345314
content=content_payload,
346315
),
347316
)
348-
if tracing_handler is not None and tool_call_id:
349-
await tracing_handler.on_tool_end(
350-
tool_call_id=tool_call_id,
351-
result=content_payload,
352-
)
353317

354318
elif isinstance(event, (FunctionToolCallEvent, FinalResultEvent, AgentRunResultEvent)):
355319
# Already covered by PartStart/PartDelta/PartEnd events above, or

src/agentex/lib/adk/_modules/_pydantic_ai_tracing.py

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)