diff --git a/src/smolagents/agents.py b/src/smolagents/agents.py index 73b2647..50ff864 100644 --- a/src/smolagents/agents.py +++ b/src/smolagents/agents.py @@ -625,9 +625,9 @@ You have been provided with these additional arguments, that you can access usin self.memory.replay(self.logger, detailed=detailed) def __call__(self, task: str, **kwargs): - """ - This method is called only by a manager agent. - Adds additional prompting for the managed agent, runs it, and wraps the output. + """Adds additional prompting for the managed agent, runs it, and wraps the output. + + This method is called only by a managed agent. """ full_task = populate_template( self.prompt_templates["managed_agent"]["task"], diff --git a/tests/test_agents.py b/tests/test_agents.py index b097132..ed885a9 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -772,6 +772,26 @@ class TestMultiStepAgent: assert "text" in content +class TestCodeAgent: + @pytest.mark.parametrize("provide_run_summary", [False, True]) + def test_call_with_provide_run_summary(self, provide_run_summary): + agent = CodeAgent(tools=[], model=MagicMock(), provide_run_summary=provide_run_summary) + assert agent.provide_run_summary is provide_run_summary + agent.managed_agent_prompt = "Task: {task}" + agent.name = "test_agent" + agent.run = MagicMock(return_value="Test output") + agent.write_memory_to_messages = MagicMock(return_value=[{"content": "Test summary"}]) + + result = agent("Test request") + expected_summary = "Here is the final answer from your managed agent 'test_agent':\nTest output" + if provide_run_summary: + expected_summary += ( + "\n\nFor more detail, find below a summary of this agent's work:\n" + "\n\nTest summary\n---\n" + ) + assert result == expected_summary + + @pytest.fixture def prompt_templates(): return {