@@ -103,6 +103,13 @@ Multi-Agent(多智能体)系统将复杂应用分解为多个专业化智能
103103定义 Tools:
104104
105105``` py
106+ from pydantic import Field
107+ from pydantic.dataclasses import dataclass
108+
109+ from astrbot.core.agent.run_context import ContextWrapper
110+ from astrbot.core.agent.tool import FunctionTool, ToolExecResult
111+ from astrbot.core.astr_agent_context import AstrAgentContext
112+
106113@dataclass
107114class AssignAgentTool (FunctionTool[AstrAgentContext]):
108115 """ Main agent uses this tool to decide which sub-agent to delegate a task to."""
@@ -124,7 +131,7 @@ class AssignAgentTool(FunctionTool[AstrAgentContext]):
124131
125132 async def call (
126133 self , context : ContextWrapper[AstrAgentContext], ** kwargs
127- ) -> str | CallToolResult :
134+ ) -> ToolExecResult :
128135 # Here you would implement the actual agent assignment logic.
129136 # For demonstration purposes, we'll return a dummy response.
130137 return " Based on the query, you should assign agent 1."
@@ -151,7 +158,7 @@ class WeatherTool(FunctionTool[AstrAgentContext]):
151158
152159 async def call (
153160 self , context : ContextWrapper[AstrAgentContext], ** kwargs
154- ) -> str | CallToolResult :
161+ ) -> ToolExecResult :
155162 city = kwargs[" city" ]
156163 # Here you would implement the actual weather fetching logic.
157164 # For demonstration purposes, we'll return a dummy response.
@@ -179,7 +186,7 @@ class SubAgent1(FunctionTool[AstrAgentContext]):
179186
180187 async def call (
181188 self , context : ContextWrapper[AstrAgentContext], ** kwargs
182- ) -> str | CallToolResult :
189+ ) -> ToolExecResult :
183190 ctx = context.context.context
184191 event = context.context.event
185192 logger.info(f " the llm context messages: { context.messages} " )
@@ -216,7 +223,7 @@ class SubAgent2(FunctionTool[AstrAgentContext]):
216223
217224 async def call (
218225 self , context : ContextWrapper[AstrAgentContext], ** kwargs
219- ) -> str | CallToolResult :
226+ ) -> ToolExecResult :
220227 return " I am useless :(, you shouldn't call me :("
221228```
222229
0 commit comments