Fix-swarm-handoff (#4198)

* fix select speaker for swarm

* Fix max-turn = 1 for swarm
This commit is contained in:
Eric Zhu
2024-11-15 10:02:59 -08:00
committed by GitHub
parent c6d69ab4c1
commit 78019dd2dc
4 changed files with 50 additions and 8 deletions

View File

@@ -791,3 +791,27 @@ async def test_swarm_handoff_using_tool_calls(monkeypatch: pytest.MonkeyPatch) -
else:
assert message == result.messages[index]
index += 1
@pytest.mark.asyncio
async def test_swarm_pause_and_resume() -> None:
first_agent = _HandOffAgent("first_agent", description="first agent", next_agent="second_agent")
second_agent = _HandOffAgent("second_agent", description="second agent", next_agent="third_agent")
third_agent = _HandOffAgent("third_agent", description="third agent", next_agent="first_agent")
team = Swarm([second_agent, first_agent, third_agent], max_turns=1)
result = await team.run(task="task")
assert len(result.messages) == 2
assert result.messages[0].content == "task"
assert result.messages[1].content == "Transferred to third_agent."
# Resume with a new task.
result = await team.run(task="new task")
assert len(result.messages) == 2
assert result.messages[0].content == "new task"
assert result.messages[1].content == "Transferred to first_agent."
# Resume with the same task.
result = await team.run()
assert len(result.messages) == 1
assert result.messages[0].content == "Transferred to second_agent."