From 966f87707ff4b337bc2294d46505e0cc752cf0dc Mon Sep 17 00:00:00 2001 From: mjn96 Date: Wed, 20 May 2026 17:55:08 +0800 Subject: [PATCH] feat(tools): support GraphAgent in AgentTool Add GraphAgent support in _run_async_impl so that when the wrapped agent is a GraphAgent, the tool result is retrieved from tool_context.state using STATE_KEY_LAST_RESPONSE. --- trpc_agent_sdk/tools/_agent_tool.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trpc_agent_sdk/tools/_agent_tool.py b/trpc_agent_sdk/tools/_agent_tool.py index c45f09f..78ba4ad 100644 --- a/trpc_agent_sdk/tools/_agent_tool.py +++ b/trpc_agent_sdk/tools/_agent_tool.py @@ -136,6 +136,7 @@ async def _run_async_impl( ) -> Any: try: from trpc_agent_sdk.agents import LlmAgent + from trpc_agent_sdk.dsl.graph import GraphAgent, STATE_KEY_LAST_RESPONSE if self.skip_summarization: tool_context.event_actions.skip_summarization = True if isinstance(self.agent, LlmAgent) and self.agent.input_schema: @@ -206,6 +207,8 @@ async def _run_async_impl( merged_text = '\n'.join([p.text for p in last_event.content.parts if p.text]) repaired = json_repair_string(merged_text) tool_result = self.agent.output_schema.model_validate_json(repaired).model_dump(exclude_none=True) + elif isinstance(self.agent, GraphAgent): + tool_result = tool_context.state.get(STATE_KEY_LAST_RESPONSE, '') else: tool_result = '\n'.join([p.text for p in last_event.content.parts if p.text]) return tool_result