@@ -219,6 +219,8 @@ class Agent(
219
219
def __init__ (
220
220
self ,
221
221
llm : LLM [LLMClientOptionsT ],
222
+ name : str | None = None ,
223
+ description : str | None = None ,
222
224
prompt : str | type [Prompt [PromptInputT , PromptOutputT ]] | Prompt [PromptInputT , PromptOutputT ] | None = None ,
223
225
* ,
224
226
history : ChatFormat | None = None ,
@@ -232,6 +234,8 @@ def __init__(
232
234
233
235
Args:
234
236
llm: The LLM to run the agent.
237
+ name: Optional name of the agent. Used to identify the agent instance.
238
+ description: Optional description of the agent.
235
239
prompt: The prompt for the agent. Can be:
236
240
- str: A string prompt that will be used as system message when combined with string input,
237
241
or as the user message when no input is provided during run().
@@ -248,7 +252,17 @@ def __init__(
248
252
self .id = uuid .uuid4 ().hex [:8 ]
249
253
self .llm = llm
250
254
self .prompt = prompt
251
- self .tools = [Tool .from_callable (tool ) for tool in tools or []]
255
+ self .name = name
256
+ self .description = description
257
+ self .tools = []
258
+ for tool in tools or []:
259
+ if isinstance (tool , tuple ):
260
+ agent , kwargs = tool
261
+ self .tools .append (Tool .from_agent (agent , ** kwargs ))
262
+ elif isinstance (tool , Agent ):
263
+ self .tools .append (Tool .from_agent (tool ))
264
+ else :
265
+ self .tools .append (Tool .from_callable (tool ))
252
266
self .mcp_servers = mcp_servers or []
253
267
self .history = history or []
254
268
self .keep_history = keep_history
@@ -555,7 +569,10 @@ async def _get_all_tools(self) -> dict[str, Tool]:
555
569
return tools_mapping
556
570
557
571
async def _execute_tool (
558
- self , tool_call : ToolCall , tools_mapping : dict [str , Tool ], context : AgentRunContext | None = None
572
+ self ,
573
+ tool_call : ToolCall ,
574
+ tools_mapping : dict [str , Tool ],
575
+ context : AgentRunContext | None = None ,
559
576
) -> ToolCallResult :
560
577
if tool_call .type != "function" :
561
578
raise AgentToolNotSupportedError (tool_call .type )
@@ -577,10 +594,22 @@ async def _execute_tool(
577
594
else tool .on_tool_call (** call_args )
578
595
)
579
596
597
+ if isinstance (tool_output , AgentResultStreaming ):
598
+ async for _ in tool_output :
599
+ pass
600
+
601
+ tool_output = {
602
+ "content" : tool_output .content ,
603
+ "metadata" : tool_output .metadata ,
604
+ "tool_calls" : tool_output .tool_calls ,
605
+ "usage" : tool_output .usage ,
606
+ }
607
+
580
608
outputs .result = {
581
609
"tool_output" : tool_output ,
582
610
"tool_call_id" : tool_call .id ,
583
611
}
612
+
584
613
except Exception as e :
585
614
outputs .result = {
586
615
"error" : str (e ),
@@ -758,3 +787,16 @@ def from_pydantic_ai(cls, pydantic_ai_agent: "PydanticAIAgent") -> Self:
758
787
tools = [tool .function for _ , tool in pydantic_ai_agent ._function_tools .items ()],
759
788
mcp_servers = cast (list [MCPServer ], mcp_servers ),
760
789
)
790
+
791
+ def to_tool (self , name : str | None = None , description : str | None = None ) -> Tool :
792
+ """
793
+ Convert the agent into a Tool instance.
794
+
795
+ Args:
796
+ name: Optional override for the tool name.
797
+ description: Optional override for the tool description.
798
+
799
+ Returns:
800
+ Tool instance representing the agent.
801
+ """
802
+ return Tool .from_agent (self , name = name or self .name , description = description or self .description )
0 commit comments