For the same shape without a vendor cloud — run the whole agent in a Docker container you own — see Self-Hosted Agent (Docker). For a provider-by-provider guide, see HostedAgent Compute Runtimes.
Quick Start
1
Simple Usage
Create a hosted agent with minimal configuration:
2
With Tools and Multi-Turn
Enable agent tools and demonstrate session continuity:
How It Works
When to Use HostedAgent vs LocalAgent
Which provider should I pick?
anthropic is one entry in the backend registry; every registered compute runtime is another.
provider="daytona" requires daytona-sdk and DAYTONA_API_KEY. Memory in ComputeConfig is specified as memory_mb (megabytes) and is converted to Daytona’s native GiB unit automatically (minimum 1 GiB). File uploads via execute_in_compute() copy the local file’s contents to the remote path — this was fixed in PR #4074; earlier versions wrote the path string to a file named after the content.Which providers resolve vs raise
Registered compute runtimes resolve; LLM routing names raise aValueError that points at LocalAgent.
For
openai, gemini, ollama, and local, use LocalAgent instead:
Configuration Options
HostedAgent API Reference
Complete HostedAgent configuration options
HostedAgentConfig Reference
Configuration object parameters
Common Patterns
Multi-turn Conversation
Anthropic maintains session state in the cloud between calls:Usage Tracking
Retrieve session information and usage metrics:Session Management
List and manage active sessions:Pluggable Provider Backends
HostedAgent uses ManagedBackendRegistry to look up provider backends — third-party packages can register new providers via the praisonai.managed_backends entry-point group.
dockeris now a built-in provider alongsideanthropic, resolved through the same registry (no plugin needed).HostedAgent(provider="docker")runs the whole agent in a local container — see Self-Hosted Agent (Docker).
Entry-point registration
A pip-installable package can publish a newHostedAgent provider by declaring an entry point:
pip install e2b-praisonai, HostedAgent(provider="e2b") resolves it automatically — no core change needed.
Factory semantics
For non-Anthropic backends,HostedAgent.__new__ acts as a factory — it returns the resolved backend instance directly. Python skips __init__ when __new__ returns a non-cls instance, so callers get the real backend’s methods rather than Anthropic-inherited ones:
Programmatic registration
Register a backend without an entry point for testing or embedding:Error message
WhenHostedAgent(provider="unknown") is called with an unregistered provider, the error lists available backends:
Migrating from ManagedAgent
Replace the deprecatedManagedAgent factory with the new canonical class:
Best Practices
Managing API Costs
Managing API Costs
- Use
claude-haiku-4-5for simple tasks to minimize costs - Implement usage tracking with
retrieve_session()to monitor token consumption - Set appropriate tool policies to control execution overhead
- Archive old sessions to avoid accumulating state storage costs
Choosing Tools
Choosing Tools
- Use
agent_toolset_20260401for general-purpose tool access - Specify minimal tool sets to reduce complexity and cost
- Test tool combinations in development before production deployment
- Review tool execution logs via session metadata
Session Reuse
Session Reuse
- Reuse sessions for related conversations to maintain context
- Implement session ID management for user-specific contexts
- Use
resume_session()to continue conversations across application restarts - Archive sessions when conversations are complete
Error Handling
Error Handling
- Handle
ValueErrorfor unsupported providers gracefully - Implement retry logic for transient network issues
- Use
interrupt()to stop long-running operations - Monitor session status and handle error states appropriately
Related
HostedAgent Compute Runtimes
Run the whole loop in Docker, E2B, Modal, Daytona, Fly.io, or Tenki
Placement — where does my agent run?
Agent(run_on="daytona") is the short form of this factorySelf-Hosted Agent (Docker)
run_on="docker" — the whole agent in a container you ownWhere Does It Run
Ask any agent where its thinking and tools actually execute
Local Agent
Run agent loops locally with any LLM
Managed Backend Plugins
Add new HostedAgent providers via entry points
ManagedAgent Persistence
Database integration with hosted agents
Session Info
Session metadata and usage tracking

