Test that when MockAgent uses TaskTool, it properly spawns a sub-agent that can use tools and complete tasks.
()
| 22 | |
| 23 | |
| 24 | def 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 | |
| 74 | class NebrowskiTool(ToolMessage): |
nothing calls this directly
no test coverage detected
searching dependent graphs…