Overview
Theswarms.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
default:"None"
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 Model Context Protocol (MCP) servers.MultipleMCPConnections
Manages multiple MCP server connections.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-4.1"
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
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
- Type Safety: Always use the provided schemas for type-safe data handling
- Validation: Leverage Pydantic’s validation to catch errors early
- Serialization: Use
.model_dump()and.model_dump_json()for serialization - Step Tracking: Track all agent steps for debugging and analysis
- Token Monitoring: Monitor token usage through UsageInfo schemas
- MCP Configuration: Use MCPConnection schemas for consistent tool integration
Schema Inheritance
All schemas inherit from Pydantic’sBaseModel, providing:
- Automatic validation
- JSON serialization/deserialization
- Schema generation
- IDE autocomplete support
- Type checking