MCPcopy
hub / github.com/langroid/langroid / test_task_tool_all_tools

Function test_task_tool_all_tools

tests/main/test_task_tool.py:182–269  ·  view source on GitHub ↗

Test that tools="all" enables all available tools for the sub-agent.

()

Source from the content-addressed store, hash-verified

180
181
182def test_task_tool_all_tools():
183 """
184 Test that tools="all" enables all available tools for the sub-agent.
185 """
186 # Create a main agent with multiple tools available
187 main_config = ChatAgentConfig(
188 llm=MockLMConfig(
189 default_response=TaskTool(
190 agent_name="Calculator",
191 system_message=f"""
192 You are a multi-tool assistant. Use the appropriate tool
193 to complete the task, then use `{DoneTool.name()}` to return the
194 result.
195 """,
196 prompt="""
197 Multiply 4 and 6, call it x, then compute Nebrowski(x, 5)
198 """,
199 model="gpt-4o-mini",
200 tools=["ALL"], # Enable all tools
201 max_iterations=20,
202 ).model_dump_json()
203 ),
204 name="MainAgent",
205 )
206 main_agent = ChatAgent(main_config)
207
208 # Set up multiple tools for the main agent
209 main_agent.enable_message(
210 [TaskTool, MultiplierTool, NebrowskiTool], use=True, handle=True
211 )
212
213 # Create task
214 task = Task(
215 main_agent,
216 name="AllToolsTask",
217 interactive=False,
218 config=TaskConfig(
219 done_sequences=["T,A"], # LLM (Tool), Agent(Handled) -> done
220 ),
221 )
222
223 # Run the task: input text is immaterial since the
224 # MockLM is hard-coded to return the TaskTool request
225 result = task.run(msg="Test all tools")
226
227 # Verify that the sub-agent had access to all tools
228 # Expected: Multiply 4 and 6 = 24, Nebrowski(3, 5) = 14
229 assert result is not None, "Task should return a result"
230 assert "77" in result.content, "Result should contain 77"
231
232 # Verify that parent chain is maintained through TaskTool
233 # When TaskTool creates a prompt ChatDocument with parent_id pointing to the
234 # TaskTool message, and passes it to the subtask, the subtask's init() method
235 # should preserve that parent_id even though it deep copies the message.
236 # This ensures the parent chain is not broken.
237 assert hasattr(result, "parent"), "Result should have a parent pointer"
238
239 # Traverse up the parent chain to find the TaskTool message

Callers

nothing calls this directly

Calls 10

enable_messageMethod · 0.95
runMethod · 0.95
ChatAgentConfigClass · 0.90
MockLMConfigClass · 0.90
TaskToolClass · 0.90
ChatAgentClass · 0.90
TaskClass · 0.90
TaskConfigClass · 0.90
nameMethod · 0.80
try_get_tool_messagesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…