-
Notifications
You must be signed in to change notification settings - Fork 167
Multi Agent
weego edited this page May 28, 2026
·
1 revision
LightSwarm is LightAgent's lightweight multi-agent helper. It registers named agents and lets a selected entry agent route work to another registered agent when the task matches that agent's role.
from LightAgent import LightAgent, LightSwarm
front_desk = LightAgent(
name="FrontDesk",
instructions="You route users to the right specialist.",
role="Front desk assistant.",
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
)
hr_agent = LightAgent(
name="HR",
instructions="You answer HR onboarding, leave, and benefits questions.",
role="HR specialist.",
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
)
it_agent = LightAgent(
name="IT",
instructions="You answer technical support questions.",
role="IT support specialist.",
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
)
swarm = LightSwarm()
swarm.register_agent(front_desk, hr_agent, it_agent)
response = swarm.run(
agent=front_desk,
query="I need help with employee onboarding.",
stream=False,
)
print(response)- Give each agent a unique
name. - Keep
instructionsandrolefocused. - Start the run from an entry agent, usually a router or front-desk agent.
- Use specialized tools and memory per agent when roles need different capabilities.
- Keep high-risk actions behind explicit tools and guardrails.
Use debug=True or trace=True when diagnosing routing:
result = front_desk.run(
"I need help with employee onboarding.",
light_swarm=swarm,
result_format="object",
trace=True,
)
print(result.content)
print(result.trace)Common issues:
- The target agent name is ambiguous.
- The entry agent is not registered in the swarm.
- Agent roles overlap too much.
- The model provider has weak tool or reasoning behavior.
More detail: Multi-agent failure map.
LightAgent Wiki - see the repository, releases, and issues.
- Home
- Quick Start
- Core Concepts
- API Reference
- Examples Cookbook
- Migration Guide
- Tools
- Tool Generator
- Memory
- MCP
- Skills
- LightFlow
- Tree of Thought
- Self-Learning
- Multi-Agent
- Tracing and Debugging
- Langfuse Observability
- Model Providers
- browser-use Integration
- Testing and CI
- Deployment Guide
- Architecture
- Security
- Known Limitations
- FAQ
- FAQ 中文
- Roadmap
- Release Process
- Contributing