Skip to content

Conversation

@JackYPCOnline
Copy link
Contributor

Description

Rewrite this unit test to verify swarm session management behavior.
Now this test resume from where it stopped.

Related Issues

Documentation PR

Type of Change

Bug fix
New feature
Breaking change
Documentation update
Other (please describe):

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • [ x] I ran hatch run prepare

Checklist

  • [ x] I have read the CONTRIBUTING document
  • [ x] I have added any necessary tests that prove my fix is effective or my feature works
  • [ x] I have updated the documentation accordingly
  • [ x] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • [ x] My changes generate no new warnings
  • [ x] Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@JackYPCOnline JackYPCOnline marked this pull request as ready for review November 7, 2025 18:49
@github-actions github-actions bot added the size/m label Nov 7, 2025
@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!


# Clean up
session_manager.delete_session(session_id)
# Create fresh agent instances for the second swarm to avoid tool conflicts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would fail if we didn't do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't create a new instance, it won't fire MultiAgentInitializedEvent then we are not reading saved session, lead to we always restart from researcher

Copy link
Member

@dbschmigelski dbschmigelski Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is this not a valid pattern for customers?

app = FastAPI()

agent_1 = Agent(...)
agent_2= Agent(...)
agent_3 = Agent(...)

@app.post("/chat/")
async def chat(request: Request):
    swarm = Swarm([agent_1, agent_2, agent_3], session=session_id or uuidv4())
    swarm(request.message)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid. this creates new instances every call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It creates a new Swarm instance, not agent instances.

Your test is recreating both the Swarm and the agents

Copy link
Contributor Author

@JackYPCOnline JackYPCOnline Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my bad, I should clarify this clearly:

  1. Swarm agent has handoff_tool, so when we reuse agent instance it casue tools name conflicts.
  2. I overlooked your question, what I wanna say is, for session management purpose, we need new swarm instance for firing MuliagentIntilizedEvent.
  3. new agent instances requierd is not related to session manager, it related to tool registry.

So, pattern is invalid, you will need new agent instances for satisfying diffrent tool name restriction.

Copy link
Member

@dbschmigelski dbschmigelski Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swarm agent has handoff_tool, so when we reuse agent instance it casue tools name conflicts.

is this a bug we should fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is our Swarm design, under def _inject_swarm_tools(self) -> None:
To your question, yes I think we should allow user reuse agent instances, then we need to fix it in separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks let me take a look at _inject_swarm_tools

Copy link
Member

@dbschmigelski dbschmigelski Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we need a tracking ticket for this.

It seems like the following would fail which is surprising.

agent_1 = Agent()
agent_2 = Agent()

swarm_1 = Swarm(agent_1, agent_2)
swarm_2 = Swarm(agent_1, agent_2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants