Skip to main content
LocalAgent runs the agent execution loop locally in your process, supporting any LLM via litellm routing and optional cloud compute for tool sandboxing.
The user sends a message; LocalAgent runs the loop on your machine and returns the model response.

Quick Start

1

Simplest Usage

Create a local agent with minimal configuration:
2

With Cloud Compute Sandbox

Use cloud compute for secure tool execution:

How It Works


Choosing an LLM

Use OpenAI models with API key authentication:

Choosing a Compute Backend

Execute tools in local subprocess (fastest, least secure):

Compute Selection Guide


Configuration Options

LocalAgent API Reference

Complete LocalAgent configuration options

LocalAgentConfig Reference

Configuration object parameters

Common Patterns

Switching LLMs

Change LLM providers without touching other code:

Tool Execution

Configure tools for different execution environments:

Multi-turn Conversations

Maintain conversation state locally:

Usage Tracking

Monitor local agent resource usage:

Migrating from ManagedAgent

Update deprecated factory patterns to use the new canonical classes:

Best Practices

Choose compute backends based on your trust and security requirements:
  • Use local subprocess for development and trusted environments
  • Use Docker for moderate isolation with good performance
  • Use cloud providers (E2B, Modal) for maximum security and isolation
  • Match compute choice to your specific use case (Modal for ML, Flyio for edge)
Use litellm prefixes correctly for different providers:
  • Always include provider prefix for Gemini: gemini/gemini-2.0-flash
  • Always include provider prefix for Ollama: ollama/llama3
  • OpenAI models can omit prefix: gpt-4o or openai/gpt-4o
  • Test model availability before production deployment
Use the new canonical LocalAgent class instead of the deprecated factory:
  • Avoid the provider= parameter entirely on LocalAgent constructors
  • Use config.model= to specify LLM models with appropriate litellm prefixes
  • Use compute= to specify sandboxing backends separately from LLM choice
  • This provides cleaner separation of concerns and better maintainability
Properly configure API keys and credentials:
  • Set LLM provider keys (OPENAI_API_KEY, GOOGLE_API_KEY, etc.)
  • Set compute provider keys (E2B_API_KEY, MODAL_TOKEN, etc.)
  • Use environment variable management tools for production deployments
  • Test authentication before deploying to avoid runtime failures

Hosted Agent

Run entire agent loops on Anthropic’s managed runtime

Sandbox

Tool execution sandboxing options

ManagedAgent Persistence

Database integration patterns

Session Info

Session metadata and usage tracking