Skip to main content
HostedAgent runs the complete agent execution loop on Anthropic’s managed infrastructure, providing seamless cloud-based agent processing with built-in tools and session management.
The user sends a request; the full agent loop runs on Anthropic’s hosted runtime.

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


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.

Entry-point registration

A pip-installable package can publish a new HostedAgent provider by declaring an entry point:
After 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

When HostedAgent(provider="unknown") is called with an unregistered provider, the error lists available backends:
Cross-reference: Managed Backend Plugins — full guide to authoring and publishing provider backends.

Migrating from ManagedAgent

Replace the deprecated ManagedAgent factory with the new canonical class:

Best Practices

  • Use claude-haiku-4-5 for 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
  • Use agent_toolset_20260401 for 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
  • 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
  • Handle ValueError for 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

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