MCPcopy
hub / github.com/langroid/langroid / test_task_tool_mock_main_agent

Function test_task_tool_mock_main_agent

tests/main/test_task_tool.py:24–71  ·  view source on GitHub ↗

Test that when MockAgent uses TaskTool, it properly spawns a sub-agent that can use tools and complete tasks.

()

Source from the content-addressed store, hash-verified

22
23
24def test_task_tool_mock_main_agent():
25 """
26 Test that when MockAgent uses TaskTool, it properly spawns a sub-agent
27 that can use tools and complete tasks.
28 """
29
30 # Configure the main agent to use TaskTool:
31 # The MockLM has a fixed response, which is the TaskTool request
32 main_config = ChatAgentConfig(
33 llm=MockLMConfig(
34 default_response=TaskTool(
35 system_message=f"""
36 You are a calculator assistant. When asked to
37 calculate, use the TOOL `{MultiplierTool.name()}` to multiply the
38 numbers, then use the TOOL `{DoneTool.name()}` to return the result
39 """,
40 prompt="Multiply 5 and 7",
41 model="gpt-4.1-mini",
42 tools=["multiplier_tool"],
43 max_iterations=5,
44 ).model_dump_json()
45 ),
46 name="MainAgent",
47 )
48 main_agent = ChatAgent(main_config)
49
50 # Enable TaskTool and MultiplierTool for the main agent.
51 # The MultiplierTool must be enabled for the main agent,
52 # since the TaskTool handler will create a sub-agent that uses it,
53 # and the handler only has access to tools enabled for the main agent.
54 main_agent.enable_message([TaskTool, MultiplierTool], use=True, handle=True)
55
56 # Create main task that stops after handling the task_tool
57 task = Task(
58 main_agent,
59 name="MainTask",
60 interactive=False,
61 config=TaskConfig(
62 done_sequences=["T,A"], # LLM (Tool (TaskTool)), Agent(Handled) -> done
63 ),
64 )
65
66 # Run the task
67 result = task.run(msg="Please calculate something")
68
69 # The result should be from the sub-agent's execution
70 assert result is not None, "Task should return a result"
71 assert "35" in result.content, "Result should contain the multiplication result"
72
73
74class NebrowskiTool(ToolMessage):

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…