Core Concepts
Understand the fundamental architecture and components that power the MARSYS framework.
Overview
MARSYS is built on a layered architecture where each component has a specific responsibility. Understanding these core concepts will help you build sophisticated multi-agent systems effectively.
Architecture Overview
The MARSYS architecture consists of several interconnected layers:
- Orchestration Layer: Orchestra (High-level API), Topology Controller, Execution Coordinator
- Execution Layer: Branch Executor, Step Executor, Branch Spawner
- Validation & Routing: Validation Processor, Router, Rules Engine
- Agent Layer: Agent Registry, Agent Pools, Agents
- Infrastructure: Communication Manager, State Manager, Memory Manager
Concept Categories
Core Components
These are the fundamental building blocks of every MARSYS application:
Agents
The autonomous units that perform tasks and make decisions
Memory
How agents store and recall information across conversations
Tools
Functions and capabilities that extend agent abilities
Models
LLM configurations and provider integrations
Messages
Standardized communication format between components
Communication
Inter-agent messaging and user interaction patterns
Advanced Topics
Advanced concepts for building sophisticated systems:
Topology
Define complex agent interaction patterns and workflows
State Management
Persistent state and workflow checkpointing
Error Handling
Comprehensive error recovery and retry strategies
Custom Agents
Building specialized agent types for specific needs
Learning Agents
Agents that adapt and improve through fine-tuning
Browser Automation
Web scraping and interaction capabilities
Learning Path
For Beginners
- Start with Agents to understand the basic building blocks
- Learn about Memory and how agents retain information
- Explore Tools to extend agent capabilities
- Understand Communication patterns
For Intermediate Users
- Master Topology for complex workflows
- Implement Error Handling for production systems
- Explore State Management for persistence
- Learn Custom Agents development
For Advanced Users
- Build Learning Agents with adaptation
- Implement Browser Automation for web tasks
- Design complex topologies with dynamic branching
- Optimize performance with agent pools
Key Design Principles
1. Pure Agent Logic
Agents implement pure _run() methods without side effects:
async def _run(self, prompt, context, **kwargs):# Pure logic - no memory manipulation# No logging, no state changes# Just process and returnmessages = self._prepare_messages(prompt)response = await self.model.run(messages)return Message(role="assistant", content=response.content)
2. Centralized Validation
All response processing happens in one place:
# ValidationProcessor handles ALL parsing- JSON responses- Structured data- Tool calls- Agent invocations- Error classification
3. Dynamic Branching
Branches created at runtime for parallel execution:
# Agents decide parallelism dynamically{"next_action": "parallel_invoke","agents": ["A", "B", "C"], # Spawns 3 branches"agent_requests": {...}}
4. Branch Isolation
Each branch maintains independent state:
- Separate memory contexts
- Individual execution traces
- Isolated metadata
- Independent status tracking
5. Topology-Driven Routing
All routing decisions based on topology:
topology = {"agents": ["A", "B", "C"],"flows": ["A -> B", "B -> C"], # Defines allowed paths"rules": [...] # Additional constraints}
Core Execution Flow
Understanding the execution flow is crucial:
1. Task Submission
result = await Orchestra.run(task, topology)
2. Topology Analysis
- Identify entry points
- Detect convergence nodes
- Validate agent permissions
- Apply rules
3. Branch Creation
- Initial branches at entry points
- Dynamic spawning for parallel work
- Parent-child relationships
4. Step Execution
Validate → Route → Execute → Process → Continue
5. Convergence
- Wait for child branches
- Aggregate results
- Resume parent execution
6. Completion
- Extract final response
- Return OrchestraResult
Agent Communication Patterns
Sequential
A → B → C → Final
Parallel
┌→ B →┐A →─┼→ C →┼→ E└→ D →┘
Conversation
A ⟷ B (multiple rounds)
Hierarchical
Manager/ \Lead1 Lead2/ \ / \W1 W2 W3 W4
Error Recovery Strategies
MARSYS provides multiple levels of error handling:
1. Step-Level Retry
Automatic retry with exponential backoff
2. Error Classification
Different strategies for different error types:
- Rate Limits: Wait and retry
- Invalid Input: Route to user
- API Errors: Fallback models
- Timeouts: Cancel and recover
3. User Recovery
Route errors to User node for manual intervention
4. Graceful Degradation
Continue with partial results when possible
Performance Considerations
Agent Pools
Use pools for true parallelism:
pool = AgentPool(agent_class=BrowserAgent, num_instances=3)
Memory Management
Choose appropriate retention:
single_run: Stateless, minimal memorysession: Balanced for most use casespersistent: Long-term learning
Timeout Configuration
Set appropriate timeouts:
- Step timeout: Individual operations
- Branch timeout: Complete workflows
- Convergence timeout: Parallel coordination
Status Verbosity
Adjust output for performance:
QUIET: Production (minimal overhead)NORMAL: DevelopmentVERBOSE: Debugging
Next Steps
Ready to dive deeper into specific concepts?
- Learn About Agents - Start with the fundamental building blocks
- Explore Topologies - Design complex interaction patterns
- API Reference - Detailed class and method documentation
- See Examples - Learn from real-world implementations
Best Starting Point
If you're new to MARSYS, start with the Agents documentation to understand the fundamental building blocks of the framework.