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 compute= to run tools in a cloud sandbox while thinking stays local:
LocalAgent uses compute= to place its tools on a provider. To share one sandbox across a whole flow or team, use AgentFlow(run_on=…). See Placement.

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):
Local subprocess compute validates every packages={"pip": [...]} entry against a strict allowlist. Only PEP 508 requirement specifiers are accepted — name, extras, version bounds, and comments (characters A-Z a-z 0-9 . _ - [ ] < > = , ~ ! + and spaces).Pip options with a leading dash are rejected: --upgrade, --pre, -r requirements.txt, -e ./pkg. An invalid entry raises:
Rewrite options as plain specifiers:

Compute Selection Guide

File-based defaults

Instead of passing image / packages / env as kwargs on every call, commit them to a .praisonai/environment.yaml. Every compute= backend loads it automatically; kwargs still win when provided.
Repo-committed .praisonai/environment.yaml — image, packages, setup, resources
The docker backend also caches the provisioned environment across runs — see Environment Capture.

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:

Multi-tenant safety

Two LocalAgent instances with different API keys stay isolated in the same process.
PraisonAI passes api_key and base_url directly to the inner agent, so credentials never leak into os.environ or a spawned subprocess. Each instance keeps its own key, even when many run in the same process.

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

Where Does It Run

Ask any agent where its thinking and tools actually execute

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