Synopsis
Description
Theserve
command starts a local FastAPI server that automatically deploys your agent with database persistence, port allocation, and capacity management. It’s the primary command for local development and testing.
Options
Option | Description | Default |
---|---|---|
--port , -p | Preferred port (auto-allocated if unavailable) | Auto-allocated |
--host , -h | Host to bind server to | 127.0.0.1 |
--debug | Run server in debug mode | false |
--replace | Replace existing agent with this agent ID | None |
--no-animation | Skip startup animation | false |
--animation-style | Animation style (field, ascii, minimal, quick) | field |
Auto Port Allocation
The serve command automatically allocates ports starting from 8450:- Port Range: 8450-8454 (supports up to 5 agents)
- Automatic Detection: Finds next available port if preferred port is busy
- Conflict Resolution: Never conflicts with existing agents
Database Integration
Eachserve
command automatically:
- Registers agent in local SQLite database
- Manages capacity (maximum 5 agents)
- Persists deployments between restarts
- Tracks usage statistics
Capacity Management
Examples
Basic Usage
Advanced Usage
Startup Process
The serve command follows this process:1
Startup Animation
Displays robotic runner animation (customizable with
--animation-style
)2
Capacity Check
Verifies database capacity (5 agents max) or handles replacement
3
Agent Registration
Registers agent in database with unique ID and allocated port
4
Server Start
Starts FastAPI server with automatic configuration
Available Endpoints
Once running, your agent exposes these REST and WebSocket endpoints:REST Endpoints
Endpoint | Method | Description |
---|---|---|
/ | GET | Agent information and status |
/health | GET | Health check |
/api/v1/agents/{agent_id}/run/{tag} | POST | Execute agent entrypoint |
/docs | GET | Interactive API documentation |
/redoc | GET | Alternative API documentation |
WebSocket Endpoints
Endpoint | Protocol | Description |
---|---|---|
/api/v1/agents/{agent_id}/stream/{tag} | WebSocket | Stream agent responses |
Testing Your Agent
Health Check
Execute Agent
Using Python SDK
Using CLI
Output Information
Successful Startup
Capacity Warning
Replacement Success
Agent Configuration
The serve command reads fromrunagent.config.json
:
Development Features
Automatic Framework Detection
Database Persistence
- Agent registrations persist between restarts
- Usage statistics are tracked
- Port allocations are remembered
Error Handling
Clear error messages for common issues:Integration with Other Commands
Database Management
Execution
Animation Styles
Customize the startup animation:Troubleshooting
Database Capacity Issues
Database Capacity Issues
Port Allocation Problems
Port Allocation Problems
The serve command handles port conflicts automatically:
- Starts from port 8450
- Increments if port is busy
- Shows allocated address in output
- Maximum 5 agents (ports 8450-8454)
Agent Configuration Errors
Agent Configuration Errors
Import/Module Errors
Import/Module Errors
Best Practices
- Monitor Capacity: Regularly check
runagent db-status --capacity
- Clean Up: Remove unused agents to free database slots
- Use Replace: When at capacity, replace oldest agents rather than failing
- Test Locally: Always test with
serve
before remote deployment - Version Control: Keep
runagent.config.json
in version control
Performance Notes
- Single Process: Each agent runs in a single FastAPI process
- Port Per Agent: Each agent gets its own port for isolation
- Database Tracking: Minimal overhead for registration and tracking
- Auto Cleanup: Detect and handle stale agent registrations
See Also
runagent run
- Execute deployed agentsrunagent db-status
- Check database statusrunagent delete
- Remove agentsrunagent deploy
- Remote deployment (coming soon)runagent logs
- View logs (coming soon)