Skip to main content

Overview

The swarms.schemas module provides Pydantic BaseModel schemas for structured data validation, API interactions, and agent step tracking. These schemas ensure type safety and data consistency across the Swarms framework.

Agent Step Schemas

Step

Represents a single execution step in an agent’s workflow.
str
default:"uuid.uuid4().hex"
Unique identifier for the task step
float
default:"current_time"
Time taken to complete the task step
AgentChatCompletionResponse
required
Agent’s response for this step

ManySteps

Tracks multiple execution steps and agent run metadata.
str
required
Unique identifier of the agent
str
required
Name of the agent
str
required
Description of the task being executed
Any
required
Maximum number of execution loops
str
default:"uuid.uuid4().hex"
Unique identifier for this execution run
List[Union[Step, Any]]
default:"[]"
List of execution steps
str
required
Complete execution history as a string
int
required
Total number of tokens consumed
str
required
Token that caused execution to stop
bool
required
Whether the task was interactive
bool
required
Whether dynamic temperature adjustment was enabled

MCP Schemas

MCPConnection

Defines connection parameters for a Model Context Protocol (MCP) server reachable over HTTP/SSE.
str
default:"mcp"
The type of connection
str
default:"http://localhost:8000/mcp"
The URL endpoint for the MCP server
Dict[Any, Any]
default:"None"
Dictionary containing configuration settings for MCP tools
str
default:"None"
Authentication token for accessing the MCP server
str
default:"streamable_http"
The transport protocol to use for the MCP server
Dict[str, str]
default:"None"
Headers to send to the MCP server
int
default:"10"
Timeout (in seconds) for the MCP server
This model allows extra fields (extra = "allow"), so additional keys will not raise a validation error, but only the fields above are read by the framework.

MultipleMCPConnections

Manages multiple MCP server connections.

Planner/Worker Schemas

Schemas used by PlannerWorkerSwarm to represent tasks in the shared task queue.

TaskPriority

IntEnum of task priority levels: LOW = 0, NORMAL = 1, HIGH = 2, CRITICAL = 3.

PlannerTaskStatus

str, Enum of task statuses: PENDING, CLAIMED, RUNNING, COMPLETED, FAILED, CANCELLED.

PlannerTask

A single task in the shared planner-worker task queue.
str
default:"ptask-{uuid}"
Unique task identifier
str
required
Short, descriptive title of the task
str
required
Detailed description of what needs to be done
TaskPriority
default:"NORMAL"
Task priority level
List[str]
default:"[]"
List of task IDs that must complete before this task can start
str
default:"None"
ID of the parent task if decomposed from a larger task
PlannerTaskStatus
default:"PENDING"
Current task status
str
default:"None"
Name of the worker agent that claimed this task
str
default:"None"
Result of task execution
str
default:"None"
Error message if task failed
int
default:"0"
Number of retry attempts so far
int
default:"2"
Maximum retry attempts before permanent failure
int
default:"0"
Optimistic concurrency version counter

PlannerTaskOutput

A single task definition as output from a planner agent.
str
required
Short, descriptive title
str
required
Detailed description of what a worker agent should do
int
default:"1"
Priority: 0=LOW, 1=NORMAL, 2=HIGH, 3=CRITICAL
List[str]
default:"[]"
Titles of other tasks in this plan that must complete first

PlannerTaskSpec

Structured output from a planner agent: a plan narrative plus a list of concrete tasks.
str
required
Narrative explanation of the plan
List[PlannerTaskOutput]
required
List of concrete tasks to add to the queue

CycleVerdict

Structured output from the judge agent after evaluating a planning cycle.
bool
required
True if the overall goal has been satisfactorily achieved
int
required
Quality score 0-10 of the combined results
str
required
Summary assessment of the cycle results
List[str]
default:"[]"
Specific gaps or issues that need addressing in a follow-up cycle
str
default:"None"
Instructions for the planner if another cycle is needed
bool
default:"False"
True if accumulated drift requires discarding all prior tasks and restarting from the original goal

Base Schemas

ModelCard

Metadata about a machine learning model.
str
required
Model identifier
str
default:"model"
Object type (always “model”)
int
default:"current_timestamp"
Unix timestamp of model creation
str
default:"owner"
Model owner/organization
str
default:"None"
Root model identifier
str
default:"None"
Parent model identifier
list
default:"None"
Model permissions

ChatMessageInput

Input message for chat completions.
str
required
Role of message sender: ‘user’, ‘assistant’, or ‘system’
Union[str, List[ContentItem]]
required
Message content (text or multi-modal)

ChatCompletionRequest

Request schema for chat completions.
str
default:"gpt-5.4"
Model to use for completion
List[ChatMessageInput]
required
List of messages in the conversation
float
default:"0.8"
Sampling temperature (0.0 to 2.0)
float
default:"0.8"
Nucleus sampling parameter
int
default:"4000"
Maximum tokens to generate
bool
default:"False"
Enable streaming responses
float
default:"1.0"
Penalty for token repetition
bool
default:"False"
Whether to echo the prompt in addition to the completion

ChatCompletionResponse

Response schema for chat completions.
str
required
Model used for completion
Literal['chat.completion', 'chat.completion.chunk']
required
Response object type
List[Union[ChatCompletionResponseChoice, ChatCompletionResponseStreamChoice]]
required
List of completion choices
int
default:"current_timestamp"
Unix timestamp of response creation

AgentChatCompletionResponse

Agent-specific chat completion response with tracking metadata.
str
default:"agent-{uuid}"
Unique identifier for this agent response
str
required
Name of the agent that generated the response
Literal['chat.completion', 'chat.completion.chunk']
default:"None"
Response object type
ChatCompletionResponseChoice
default:"None"
Completion choice data
int
default:"current_timestamp"
Unix timestamp of response creation

UsageInfo

Token usage information for API calls.
int
default:"0"
Number of tokens in the prompt
int
default:"0"
Total tokens used (prompt + completion)
int
default:"0"
Number of tokens in the completion

Example: Complete Agent Tracking

Example: MCP Connection Setup

Best Practices

  1. Type Safety: Always use the provided schemas for type-safe data handling
  2. Validation: Leverage Pydantic’s validation to catch errors early
  3. Serialization: Use .model_dump() and .model_dump_json() for serialization
  4. Step Tracking: Track all agent steps for debugging and analysis
  5. Token Monitoring: Monitor token usage through UsageInfo schemas
  6. MCP Configuration: Use MCPConnection schemas for consistent tool integration

Schema Inheritance

All schemas inherit from Pydantic’s BaseModel, providing:
  • Automatic validation
  • JSON serialization/deserialization
  • Schema generation
  • IDE autocomplete support
  • Type checking