Skip to main content

Agency Class

The Agency class orchestrates a collection of Agent instances based on entry points and communication flows.
Note: CommunicationFlowEntry is a type alias defined in agency_swarm.agency.core that accepts (Agent, Agent) tuples, AgentFlow chains, or those accompanied by a custom SendMessage tool class.
Advanced Note: Handoff from agency_swarm is the Agency Swarm communication-flow class. SDKHandoff exposes the raw OpenAI Agents SDK handoff type for advanced interoperability.

Key Attributes

  • agents (dict[str, Agent]): Dictionary mapping agent names to their instances
  • entry_points (list[Agent]): Agents designated as entry points for external interaction
  • thread_manager (ThreadManager): Manager responsible for handling conversation threads
  • event_stream_merger (EventStreamMerger): Aggregates streaming events from concurrent agent runs
  • persistence_hooks (PersistenceHooks | None): Optional hooks for loading/saving thread state
  • shared_instructions (str | None): Instructions prepended to every agent’s system prompt
  • shared_tools (list[Tool] | None): Tool instances or BaseTool classes shared with all agents
  • shared_tools_folder (str | None): Path to folder containing shared tool files
  • shared_files_folder (str | None): Path to folder of files shared via a common vector store
  • shared_mcp_servers (list[Any] | None): MCP server instances attached to all agents
  • user_context (dict[str, Any]): Shared user-defined context accessible within MasterContext
  • send_message_tool_class (type | None): Fallback SendMessage tool when no flow-specific tool is set

Key Methods

Agent Class

The Agent class extends the base agents.Agent with capabilities for multi-agent collaboration within an Agency.

Key Attributes

  • files_folder (str | Path | None): Local folder for file management and vector stores
  • tools_folder (str | Path | None): Directory for automatic tool discovery and loading
  • schemas_folder (str | Path | None): Folder scanned for OpenAPI schemas to auto-generate tools
  • api_headers / api_params (dict): Per-schema metadata applied when generating tools
  • description (str | None): Agent role description for dynamic send_message tools
  • include_search_results (bool): Whether FileSearchTool responses include citation context
  • include_web_search_sources (bool): Whether WebSearchTool responses include source URLs
  • validation_attempts (int): Retry count for output guardrail enforcement
  • raise_input_guardrail_error (bool): Controls input guardrail mode—False for non-strict (guidance as assistant), True for strict (raises exceptions).
  • system_reminders (list[SystemReminder]): Transient reminders injected before model calls. Plain strings and callables run before the first model call of each top-level user turn.
  • handoff_reminder (str | None): Custom reminder appended to handoff prompts
  • tool_concurrency_manager (ToolConcurrencyManager): Coordinates concurrent tool execution
  • voice (str | None): Realtime session voice used when this agent is the entry agent. A session keeps one voice from start to finish, so a voice set on any other agent is not heard.

Core Execution Methods

Tool Management

File Management