Agent Squad Documentation
repository·main·Indexed 27 days ago
https://github.com/2fastlabs/agent-squadA flexible, lightweight open-source framework for orchestrating multiple AI agents across Python, TypeScript, and Swift runtimes. It supports cloud-based and on-device orchestration for Apple platforms, featuring the AgentSquad orchestrator for intent-based routing, SupervisorAgent for hierarchical team coordination, and GroundedAgent for anti-hallucination patterns.
What's inside Agent Squad
- Agent Squad is a flexible framework designed for managing multiple AI agents, intelligently routing user queries, and handling complex conversations. It enables developers to build scalable, modular AI applications that maintain coherent dialogues across multiple domains by delegating tasks to specialized agents while preserving context. It supports various deployment environments, including AWS Lambda, local environments, and other cloud platforms.
Overview of Agent Squad runtimes
mainAgent Squad is a multi-agent orchestration framework available in two primary runtime tracks:
Python / TypeScript
Designed for server and cloud environments. Features include:
- Orchestration with Bedrock, Anthropic, and OpenAI classifiers.
- Streaming responses.
- Storage backends for Lambda, DynamoDB, and SQL.
- Support for retrievers.
- Available via
npmandPyPI.
Swift
Designed for Apple platforms (iOS 16+ / macOS 14+). Features include:
- On-device agent orchestration.
- MCP (Model Context Protocol) tools.
- Realtime voice support.
- Rich Tool UIs.
- SwiftData storage and built-in tracing.
- Available via GitHub.
Understand the Agent Squad Orchestration Flow
mainThe Agent Squad framework uses an orchestrator to route user queries to specialized agents. The process follows these steps:
- Request Initiation: User sends a request to the orchestrator.
- Classification: A
Classifieranalyzes the request, agent descriptions, and global conversation history (across all agents for the currentuserIdandsessionId) to identify the target agent. - Agent Selection: The
Classifierreturns the name of the selected agent. - Request Routing: The input is routed to the chosen agent.
- Agent Processing: The agent processes the request using its own specific conversation history (ensuring isolation from other agents).
- Response Generation: The agent generates a response (standard or streaming).
- Conversation Storage: The orchestrator automatically saves the input and response to the configured
storagefor the specificuserIdandsessionId. - Response Delivery: The response is delivered to the user.
This architecture allows the
Classifierto have a global view for routing, while individual agents maintain private context for task execution.Understand the role of Retrievers in Agent Squad
mainIn Agent Squad, a Retriever is a component used to fetch relevant information from a large corpus of data or a database in response to a query. They are used to enhance LLM performance by providing external knowledge that is not present in the model's training data.
Key functions include:
- Improving Context and Relevance: Providing specific context that the LLM cannot generate from internal knowledge alone.
- Memory Augmentation: Acting as an extended memory for up-to-date or highly detailed information.
- Efficiency: Allowing the system to pull only necessary information on-demand rather than requiring model retraining on large datasets.
Prevent hallucinations with GroundedAgent
mainThe
GroundedAgentis an anti-hallucination pattern available in Python, TypeScript, and Swift. It uses two LLMs to ensure accuracy:- Gatherer: Calls tools and retrieves raw data but does not communicate with the user.
- Presenter: Receives only the curated tool output and writes the final reply. It has no access to tool transcripts or chat history, preventing it from inventing information (like prices or availability) not present in the fetched data.
Coordinate teams with SupervisorAgent
mainTheSupervisorAgentuses an agent-as-tools architecture to coordinate a team of specialized agents. It can execute sub-agent queries in parallel, manage shared context, and dynamically delegate subtasks to the appropriate team members. ASupervisorAgentcan itself be registered as an agent within a classifier to create hierarchical multi-agent teams.Understand Agent Squad conversation storage concepts
mainThe Agent Squad System uses a storage system to preserve context across interactions by saving both user messages and assistant responses.
Conversations are uniquely identified by a composite key consisting of:
userIdsessionIdagentId
All storage backends must implement the
ConversationStorageinterface.Understand the Swift Tracing Pipeline
mainAgent Squad uses an OpenTelemetry-style tracing pipeline for Swift. The pipeline consists of three layers that can be swapped independently:
- Tracer: Opens spans.
- SpanProcessor: Assembles and batches spans.
- TraceExporter: Ships finished
TraceEventrecords to a backend.
Recommended Configurations
- Local Development: Use
OSLogTracerto write directly toos.Logger(viewable in Console.app or Instruments) without network configuration. - Production: Use
ProcessingTracer+BatchSpanProcessor+OTLPExporterto post OTLP/HTTP JSON to compatible collectors like Langfuse, Datadog, Grafana, or Honeycomb.
Understand the OpenAIGroundedVoiceAssistant turn structure
mainA tool-using turn follows a two-phase execution model:
- Gather Phase: The gatherer response runs text-only (it never speaks). It calls tools and accumulates results. The session emits
.state(.thinking)during this phase. - Present Phase: Tool results are curated by the
curatorand passed to an isolated presenter response. The presenter speaks from the curated block only. The session emits.state(.presenting).
Direct Response Path: If no tools are called, the gatherer's accumulated text is used for a direct response where the model speaks from conversation history without grounding. This path is governed by
directInstructionsand emits.state(.speaking).- Gather Phase: The gatherer response runs text-only (it never speaks). It calls tools and accumulates results. The session emits
Supported Agent Types in Agent Squad
mainThe framework supports a variety of built-in agents and allows for custom implementations.
Built-in Agents:
Bedrock LLM Agent: Uses Amazon Bedrock's API.Amazon Bedrock Agent: Interfaces with existing Amazon Bedrock Agents.Amazon Lex Bot: Implements logic to call Amazon Lex chatbots.Lambda Agent: Invokes AWS Lambda functions (useful for integrating Python-based agents into the system).OpenAI Agent: Uses OpenAI models like GPT-3.5 and GPT-4.
You can also create custom agents to meet specific requirements.
Use AWS Lambda Powertools for logging in TypeScript
mainTo use AWS Lambda Powertools for logging with Agent Squad, follow these steps:
Install the package:
npm install @aws-lambda-powertools/loggerInitialize the Logger and pass it to the
AgentSquadinstance via theloggeroption.
import { Logger } from "@aws-lambda-powertools/logger"; const logger = new Logger({ logLevel: "INFO", serviceName: "MyOrchestratorService" }); const orchestrator = new AgentSquad({ storage: storage, config: { LOG_AGENT_CHAT: true, LOG_CLASSIFIER_CHAT: true, LOG_CLASSIFIER_RAW_OUTPUT: true, LOG_CLASSIFIER_OUTPUT: true, LOG_EXECUTION_TIMES: true, }, logger: logger, });Configure AWS Authentication for Bedrock
mainAgent Squad uses Amazon Bedrock by default for classification and agent responses. You must have the AWS CLI installed and configured on your machine.
- Install AWS CLI.
- Configure credentials via
aws configure. - Verify access by running:
aws sts get-caller-identity - Ensure you have requested model access in the AWS Bedrock console for the models you intend to use (e.g., Claude 3.5 Sonnet, Claude 3 Haiku).