@@ -19,21 +19,19 @@ from dotenv import load_dotenv
1919
2020load_dotenv()
2121
22- from project.agent import create_agent
22+ from project.agent import MODEL_NAME, create_agent
2323from pydantic_ai.run import AgentRunResultEvent
2424from pydantic_ai.messages import ModelMessagesTypeAdapter
2525
2626import agentex.lib.adk as adk
27- from agentex.lib.adk import (
28- stream_pydantic_ai_events,
29- create_pydantic_ai_tracing_handler,
30- )
3127from agentex.protocol.acp import SendEventParams, CancelTaskParams, CreateTaskParams
28+ from agentex.lib.core.harness import UnifiedEmitter
3229from agentex.lib.types.fastacp import AsyncACPConfig
3330from agentex.lib.types.tracing import SGPTracingProcessorConfig
3431from agentex.lib.utils.logging import make_logger
3532from agentex.lib.utils.model_utils import BaseModel
3633from agentex.lib.sdk.fastacp.fastacp import FastACP
34+ from agentex.lib.adk import PydanticAITurn
3735from agentex.lib.core.tracing.tracing_processor_manager import add_tracing_processor_config
3836
3937logger = make_logger(__name__)
@@ -125,15 +123,17 @@ async def handle_task_event_send(params: SendEventParams):
125123 input={"message": user_message},
126124 data={"__span_type__": "AGENT_WORKFLOW"},
127125 ) as turn_span:
128- tracing_handler = create_pydantic_ai_tracing_handler(
126+ # Construct the UnifiedEmitter from the ACP context so tracing is
127+ # automatic and messages are auto-sent to the task stream (Redis).
128+ emitter = UnifiedEmitter(
129+ task_id=task_id,
129130 trace_id=task_id,
130131 parent_span_id=turn_span.id if turn_span else None,
131- task_id=task_id,
132132 )
133133
134134 # Wrap the pydantic-ai event stream so we can capture the final
135135 # AgentRunResultEvent (which carries the full message list for the
136- # next turn) without changing the streaming-helper's signature .
136+ # next turn) before forwarding events to the emitter .
137137 captured_messages: list[Any] = []
138138
139139 async def tee_messages(upstream) -> AsyncIterator[Any]:
@@ -143,9 +143,8 @@ async def handle_task_event_send(params: SendEventParams):
143143 yield event
144144
145145 async with agent.run_stream_events(user_message, message_history=previous_messages) as stream:
146- final_output = await stream_pydantic_ai_events(
147- tee_messages(stream), task_id, tracing_handler=tracing_handler
148- )
146+ turn = PydanticAITurn(tee_messages(stream), model=MODEL_NAME)
147+ result = await emitter.auto_send_turn(turn)
149148
150149 # Save the updated message history so the next turn picks up here.
151150 if captured_messages:
@@ -158,7 +157,7 @@ async def handle_task_event_send(params: SendEventParams):
158157 )
159158
160159 if turn_span:
161- turn_span.output = {"final_output": final_output }
160+ turn_span.output = {"final_output": result.final_text }
162161
163162
164163@acp.on_task_cancel
0 commit comments