Quick Start
How It Works
| Component | Location | Purpose |
|---|---|---|
| Agent Loop | Anthropic Cloud | Complete execution environment |
| Tools | Anthropic Cloud | Sandboxed tool execution |
| LLM | Anthropic Cloud | Claude model processing |
| Session State | Anthropic Cloud | Persistent conversation context |
When to Use HostedAgent vs LocalAgent
Configuration Options
HostedAgent API Reference
Complete HostedAgent configuration options
HostedAgentConfig Reference
Configuration object parameters
| Option | Type | Default | Description |
|---|---|---|---|
model | str | "claude-haiku-4-5" | Claude model to use |
system | str | "You are a helpful coding assistant." | System prompt |
name | str | "Agent" | Agent display name |
tools | List[Dict] | [{"type": "agent_toolset_20260401"}] | Available tools |
packages | Dict | None | Package dependencies |
networking | Dict | Unrestricted | Network configuration |
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: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
Local Agent
Run agent loops locally with any LLM
ManagedAgent Persistence
Database integration with hosted agents
Session Info
Session metadata and usage tracking
Managed CLI
Command-line tools for hosted resources

