Skip to content

Add create_triage_agent helper function#69

Open
alpnix wants to merge 1 commit intoopenai:mainfrom
alpnix:fix/add-create-triage-agent
Open

Add create_triage_agent helper function#69
alpnix wants to merge 1 commit intoopenai:mainfrom
alpnix:fix/add-create-triage-agent

Conversation

@alpnix
Copy link

@alpnix alpnix commented Mar 14, 2026

Summary

Implements the missing create_triage_agent function that is referenced in the personal_shopper example but was never implemented in the codebase.

Changes

  • Added new swarm/agents.py module with create_triage_agent helper function
  • Updated swarm/__init__.py to export the new function
  • Function dynamically generates transfer functions for routing conversations to sub-agents
  • Supports optional backlinks for returning to the triage agent

Implementation Details

  • Follows existing code style and conventions from core.py and util.py
  • Uses proper type hints and comprehensive docstrings
  • Handles agent name to function name conversion (spaces to underscores, lowercase)
  • Avoids mutating original agent function lists when adding backlinks

Testing

  • Verified syntax with py_compile
  • Tested logic with standalone unit tests
  • Follows the pattern used in the airline example but provides a cleaner API

Fixes

Closes #57
Closes #49

Example Usage

from swarm import Agent
from swarm.agents import create_triage_agent

sales_agent = Agent(name="Sales Agent", instructions="Handle sales")
refunds_agent = Agent(name="Refunds Agent", instructions="Handle refunds")

triage = create_triage_agent(
    name="Triage Agent",
    instructions="Route users to the right agent",
    agents=[sales_agent, refunds_agent],
    add_backlinks=True
)

Implements the missing create_triage_agent function referenced in the
personal_shopper example (examples/personal_shopper/main.py).

This helper function:
- Dynamically generates transfer functions for routing to sub-agents
- Supports optional backlinks for returning to the triage agent
- Follows existing code style and conventions from core.py
- Uses proper type hints and documentation

Fixes openai#57, openai#49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no create_triage_agent the class create_triage_agent from the swarm.agents module is missing.

1 participant