OpenClaw

OpenClaw Agents & Model Providers👨‍💻

Agents are the AI personas in OpenClaw that process incoming messages. Each agent has a model provider, a system prompt, optional tools, and memory configuration. OpenClaw supports multiple model providers -- Anthropic (Claude), OpenAI (GPT), Ollama (local models), OpenRouter, and any OpenAI-compatible endpoint. You can run multiple agents simultaneously, each specialized for a different task, and configure failover chains so your agents stay available even when a provider goes down.

Key Takeaways

  • 1An agent is defined by four core components: a model (which LLM to use), a system prompt (how to behave), tools (what actions it can take), and memory (how much context to retain across messages).
  • 2Model providers are specified in `provider:model-name` format. Examples: `anthropic:claude-sonnet-4-20250514`, `openai:gpt-4o`, `ollama:llama3.1:70b`. This lets you mix providers across different agents in the same Gateway.
  • 3Failover chains provide high availability. If the primary model is unavailable, OpenClaw automatically falls back to the next model in the chain. This is critical for production deployments where downtime is unacceptable.
  • 4Each agent has its own isolated workspace at `~/.openclaw/agents/<agentId>/`. This directory contains the agent's bootstrap files (SOUL.md, AGENTS.md, MEMORY.md), sessions, and auth profiles. Agents never share state.
  • 5Local models via Ollama eliminate API costs and keep all data on your infrastructure. Use `openclaw models scan` to discover available local models and `ollama:model-name` to reference them in agent configuration.
  • 6Multiple agents can run simultaneously in the same Gateway. Each handles different types of messages based on routing rules and bindings. A coding agent, a support agent, and a DevOps agent can all coexist.

Master openclaw agents & model providers

Take the Introduction to OpenClaw course with hands-on lessons and challenges.

Examples

Basic agent configuration with model and tools

json

This defines two agents: a coder using Claude Sonnet and a support agent using GPT-4o. Each has its own workspace and agent directory. The workspace holds bootstrap files (SOUL.md, MEMORY.md) and the agentDir stores runtime state.

Model failover chain for high availability

json

If Claude is unavailable (API error, rate limit, outage), OpenClaw automatically tries GPT-4o next. If that also fails, it falls back to the local Ollama model. This three-tier failover ensures the agent is always responsive, even during provider outages.

Connecting Ollama as a local model provider

bash

Ollama models must be downloaded before OpenClaw can use them. The models scan command discovers all available models across configured providers. Use ollama:model-name in your agent config to reference local models.

Agent with tools and memory configuration

json

The DevOps agent has memory disabled because each command is independent -- there is no conversational context to track. The assistant agent has memory enabled with 100 messages of context, allowing it to reference previous conversations. Tools are scoped per agent: the DevOps agent can run SSH commands and Docker operations, while the assistant can only execute code.

Custom OpenAI-compatible endpoint (vLLM, LiteLLM)

json

Any endpoint that implements the OpenAI chat completions API can be used as a provider. This includes vLLM, LiteLLM, and custom inference servers. The agent uses the vLLM-hosted model as primary and falls back to Claude if the custom server is unavailable.

Common Mistakes

Mistake:

Configuring a single generic agent to handle all types of messages instead of creating specialized agents

Fix:

Specialized agents with focused system prompts and tools perform significantly better than one agent trying to do everything. Create a coding agent, a support agent, and a DevOps agent instead of a single 'do-everything' agent.

Mistake:

Referencing an Ollama model that has not been pulled yet, causing the agent to fail with a model-not-found error

Fix:

Always run `ollama pull model-name` before configuring an agent to use it. Use `openclaw models scan` to verify the model is available.

Mistake:

Setting memory maxMessages too high, causing slow response times and high token usage as the context grows

Fix:

Start with 20-30 messages for conversational agents and increase only if needed. For stateless command-response agents (DevOps, alerts), disable memory entirely.

Mistake:

Using the same agentId for agents that serve different purposes, creating workspace conflicts and confused behavior

Fix:

Each agent needs a unique agentId. Use descriptive names like 'coder', 'support-us', or 'deploy-bot' that clearly communicate the agent's purpose.

Best Practices

  • Name agents by their role: 'coder', 'support', 'onboarding', 'devops'. Descriptive names make configuration readable and debugging easier.
  • Match model power to task complexity. Use lightweight models (GPT-4o-mini) for simple tasks like routing and classification. Use powerful models (Claude Sonnet, GPT-4o) for tasks requiring deep reasoning.
  • Always configure a failover chain for production agents. A three-tier chain (cloud primary, cloud secondary, local fallback) provides resilience against any single provider outage.
  • Scope tools to the minimum each agent needs. A code review agent should not have SSH access. A deployment agent should not have code writing tools. Follow the principle of least privilege.
  • Back up agent workspace directories regularly. Each workspace contains irreplaceable data: SOUL.md persona definitions, MEMORY.md knowledge, and session history.
  • Use `openclaw models scan` regularly to check which models are available and their sizes before configuring agents.

Summary

OpenClaw agents are AI personas defined by a model, system prompt, tools, and memory. Multiple providers (Anthropic, OpenAI, Ollama, custom endpoints) can be used across agents in the same Gateway. Failover chains ensure high availability. Each agent has an isolated workspace with its own bootstrap files and session store. For production, specialize your agents by role, match model power to task complexity, configure failover, and follow least-privilege for tool access.

Practice OpenClaw with hands-on challenges

Learn openclaw agents & model providers hands-on in your IDE

Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.

Related Concepts

Related Cheatsheets

Master OpenClaw with Stanza

Interactive lessons and challenges, right in your code editor.

Check the free courses. No credit card.