@@ -41,14 +41,9 @@ async def handle_message_send(params):
4141
4242import json
4343import inspect
44- from typing import TYPE_CHECKING , Any , Callable , AsyncIterator
44+ from typing import Any , Callable , AsyncIterator
4545
4646from pydantic_ai .run import AgentRunResultEvent
47-
48- if TYPE_CHECKING :
49- from agentex .lib .adk ._modules ._pydantic_ai_tracing import (
50- AgentexPydanticAITracingHandler ,
51- )
5247from pydantic_ai .messages import (
5348 TextPart ,
5449 PartEndEvent ,
@@ -124,7 +119,6 @@ def _tool_return_content(result: ToolReturnPart | Any) -> Any:
124119
125120async 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
0 commit comments