Models¶
The Bedrock Swarm framework provides a flexible model abstraction layer for working with different Amazon Bedrock models. This section documents the available model implementations and their configurations.
Model Architecture¶
The model system follows a layered architecture:
graph TD
A[Model Factory] --> B[Bedrock Model]
B --> C[Claude Model]
B --> D[Titan Model]
A --> E[Model Registry]
E --> F[Model Configurations]
Core Components¶
- Model Factory
- Central point for model creation
- Handles model registration
- Manages configurations
-
Provides model validation
-
Bedrock Model
- Abstract interface for all models
- Defines common operations
- Handles token management
-
Provides error handling
-
Model Implementations
- Claude Model (Anthropic)
- Titan Model (Amazon)
- Custom model implementations
Model Registry¶
The model registry maintains configurations for supported models:
BEDROCK_MODEL_REGISTRY = {
"us.anthropic.claude-3-5-sonnet": {
"20241022-v2:0": {
"class": ClaudeModel,
"config": {
"max_tokens": 200000,
"default_tokens": 4096,
},
}
},
"amazon.titan-text-express": {
"v1": {
"class": TitanModel,
"config": {
"max_tokens": 8000,
"default_tokens": 2048,
},
}
}
}
Model Operations¶
Models support these core operations:
- Request Formatting
- System prompt integration
- Message formatting
- Parameter validation
-
Token counting
-
Response Processing
- Content extraction
- Stream handling
- Error processing
-
Token tracking
-
Error Handling
- Token limit validation
- API error handling
- Response parsing
- Retry logic
Model Selection¶
Choose models based on these factors:
- Capabilities
- Context window size
- Response quality
- Specialized features
-
Performance characteristics
-
Resource Requirements
- Token usage
- Response time
- Cost considerations
-
Memory usage
-
Integration Needs
- API compatibility
- Tool support
- Stream processing
- Error handling
Best Practices¶
-
Model Configuration
-
Token Management
-
Error Handling
Model Integration¶
Integrate models with agents:
from bedrock_swarm.agents import BedrockAgent
from bedrock_swarm.models.factory import ModelFactory
# Create agent with model
agent = BedrockAgent(
name="calculator",
model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
tools=[CalculatorTool()],
system_prompt="You are a calculation specialist."
)
# Model is automatically created and configured
response = agent.process_message("Calculate 2 + 2")