Documentation Index
Fetch the complete documentation index at: https://docs.yourhq.ai/llms.txt
Use this file to discover all available pages before exploring further.
Agents
How the agent system works, how to provision agents, and how to write custom templates.What an agent is
In HQ, an agent is a long-lived workspace made of:- A git branch on the gateway’s local repo (
workspace-slug/agent-slug). Holds the agent’s identity files, memory, skills, and any artifacts it produces. - A Chrome profile on the gateway (persistent cookies, logged-in sessions, extensions).
- An OpenClaw session — the runtime. Handles prompt assembly, tool calls, conversation state.
- A messaging channel — Telegram, Discord, Slack, or none. Each agent can be bound to one channel for conversational I/O.
- A row in the Supabase
agentstable — the metadata, includinggateway_id(which gateway runs it),reports_to_id(its manager), andmetaJSONB for template-specific config. - A usage budget row in
agent_budgetsonce usage is configured or first recorded.
The template library
templates/ is the catalog of starting points:
default/— minimal baseline that every custom agent inherits fromanalytics/,assistant/,chief-of-staff/,cmo/,cofounder/,crm-researcher/,designer/,market-researcher/,newsletter-editor/,newsletter-writer/,sales-copywriter/,script-writer/,social-strategist/,social-writer/
template/<name> branch in its local bare repo on first boot.
Template structure
add-agent.sh forks the chosen template branch into the agent’s personal branch, then patches:
agent.json— setsslug,name,description,emoji,channelUSER.md— replacesUSER_NAME_HERE,PREFERRED_NAME_HERE,TIMEZONE_HEREwith the workspace owner’s profileIDENTITY.md— updates the Name/Emoji section to the new agent’s identity
update command so the gateway reloads the agent with fresh config.
Provisioning flow
- UI → Agents → New Agent.
- Wizard step 1: pick a template. Templates load from
/api/agents/templates(baked into the UI image from thetemplates/directory at build time). - Step 2: name, slug (auto-generated from name), emoji, optional description override, and optional manager.
- Step 3: choose a messaging channel (Telegram, Discord, Slack, or None) and enter the required credentials.
- Click Create.
createAgentWithBranchinapps/ui/src/app/dashboard/agents/actions.tsvalidates the slug, checks uniqueness, inserts theagentsrow, and enqueues anagent_commandsrow withaction=provision.
- The runner’s Supabase Realtime subscription fires.
- Runner calls
lease_command(p_gateway_slug=<gateway-id>)to atomically claim it. - Runner builds the shell command and invokes
gateway/scripts/add-agent.sh. add-agent.sh:- Creates a new branch from the template branch in the bare repo.
- Creates a git worktree at
/home/openclaw/.openclaw/workspace-<agent-slug>/. - Patches
agent.json,USER.md,IDENTITY.md. - Appends a bindings entry to
openclaw.jsonfor the chosen channel (Telegram account, Discord bot, Slack socket, or no binding). - Creates a Chrome desktop shortcut for the new browser profile.
- Links shared auth directories (so all agents share model tokens).
- Runner restarts the gateway container so openclaw picks up the new agent.
- Agent appears as
onlinein the UI within ~60 seconds.
Channel pairing
After provisioning, the next step depends on the channel: Telegram or Discord (DM pairing):- Send a message to your bot (Telegram DM or Discord DM).
- Bot replies with a 6-digit pairing code.
- In the UI, open the agent’s detail page → Pairing Code field → paste code → Submit.
- Runner executes
openclaw pairing approve <channel> <code>. - Next message triggers the agent.
- Runner logs:
docker compose logs runner | grep pairing - Gateway logs:
docker compose logs gateway | grep <channel> - openclaw.json in the gateway-state volume has the correct
bindingsentry
Customizing agents after creation
Two paths: In the UI file browser (Phase 1):- Agents → [agent] → Files tab → browse the agent’s git branch.
- Edit
IDENTITY.md,MEMORY.md,TOOLS.md, any skill file. - Save. The UI auto-enqueues an
updatecommand. Gateway reloads the agent.
- “Remember that I prefer short-form responses.” → agent updates its own
MEMORY.md(with your approval). - “Learn to summarize in three bullets.” → agent updates
SKILL.mdor adds a new skill.
Sync model (git)
Every agent lives on its own git branch. File changes land on disk immediately, but aren’t saved to git until someone commits. HQ’s sync model is event-driven, not polled. Commits are triggered by meaningful events:- Provisioning —
add-agent.shcommits the initial branch when an agent is created (“feat: initialize agent<slug>”). - UI file-browser edits —
files_api.pycommits on every file write (“edit via UI:<path>”) or create/delete. - Agent-initiated saves — the agent calls
save_progress(alias for./scripts/git-sync.sh) when it does something meaningful: learned a preference, produced an artifact, updated a skill. Commit messages likelearned: <what>,done: <what>,skill: <what>.
post-commit git hook on the bare repo that async-pushes every commit to origin if a remote is configured. You never call git push manually. Works offline — commits land locally, push retries next boot or sweep.
The backup sweep runs inside the runner every GIT_SYNC_INTERVAL seconds (default 30 min). It:
- Commits any dirty worktrees with “autosync: uncommitted changes at
<timestamp>” - Pushes all branches (belt-and-suspenders — catches missed pushes)
- Fetches from origin and fast-forwards branches that moved on the remote (only when the local worktree is clean; we never stomp on in-progress edits)
GIT_REMOTE_URL (any git host), or GITHUB_TOKEN + GITHUB_REPO_OWNER + GITHUB_REPO_NAME (GitHub shorthand). See CONFIGURATION.md → Git remote sync for details.
Disabling the sweep: set GIT_SYNC_INTERVAL=0. Event-driven commits and the post-commit push hook still work; only the periodic safety net turns off.
Writing a new template
-
Copy
templates/default/: -
Edit
templates/your-role/agent.json:Themodelfield is optional — agents use whatever default provider/model is configured in Settings → Connections. You can override per-agent from the agent detail page. -
Edit
IDENTITY.md— this is the prose that gets prepended to every prompt. Voice, domain knowledge, how they talk. Seetemplates/cofounder/IDENTITY.mdfor a good example. -
Edit
SOUL.md— core beliefs. Goals. Non-negotiables. What the agent refuses to do. -
Leave
USER.mdalone — the placeholder tokens (USER_NAME_HERE, etc.) are filled in at provision time. -
Write starting memories in
MEMORY.md— e.g. “The user’s company is in early-stage SaaS. They prefer short outputs.” -
Add role-specific skills in
skills/. A skill is a markdown file describing a procedure. Examples:skills/outreach/draft-cold-email.mdskills/content/weekly-newsletter.mdskills/research/competitor-analysis.md
-
Rebuild the templates index so the UI sees your new template:
Commit the updated
apps/ui/src/generated/templates.ts. -
Build and test (only needed if developing;
docker compose up -dalone is fine for published images):Go to Agents → New Agent → your template should appear. -
Provision a test agent against it. Iterate on
IDENTITY.mdand skills until it behaves right. - Open a PR if it’s generally useful.
Org chart and delegation
Agents can report to other agents. Thereports_to_id field creates a lightweight org chart in the agent list and on each agent detail page.
When an agent has a manager or direct reports, the HQ bootstrap plugin injects a “Your Position” section into runtime context. That context tells the agent:
- Who its manager is.
- Which agents report to it.
- To delegate by creating assigned tasks for direct reports.
- To escalate by creating high-priority tasks for its manager.
- To ask the human before routing work to peer agents outside the direct hierarchy.
Usage budgets
HQ records model usage for each agent inagent_usage and keeps a current-period rollup in agent_budgets.
Budget controls live on the agent detail page. Per-agent settings include:
- Monthly limit in USD.
- Soft warning threshold percentage.
- Whether to hard-stop the agent after exceeding the limit.
- Period timezone.
Skills and tools
Agents have access to (via openclaw):- Browser — a dedicated Chrome profile they can drive. Visit pages, screenshot, click, type. Persistent cookies.
- Messaging channel — Telegram, Discord, or Slack — send/receive messages with their paired user.
- HQ database — read/write contacts, tasks, documents, interactions via the service role.
- MCP servers — any MCP server you configure. Slack, GitHub, Notion, Google Calendar, etc.
- Shell — scoped to their workspace directory.
TOOLS.md in a template documents which tools the agent should reach for in which situations. The browser tool, for example, is automatically registered as a capability (openclaw’s browser plugin is always loaded), and TOOLS.md tells the agent when to use it without being asked.
Agent memory model
Agents wake up fresh each session. Continuity comes from files in their branch:MEMORY.md— curated long-term memory. Durable truths: user preferences, ongoing projects, important context. Updated sparingly.memory/YYYY-MM-DD.md— daily notes. What happened today. Updated every session.history/YYYY-MM-DD_topic.md— operational narratives for meaningful work. Multi-step changes, architecture decisions, lessons learned.
AGENTS.md prompts the agent to read these on every session start. The agent maintains them itself — the user doesn’t usually touch them.
For shared knowledge across agents, use Supabase documents (agents read/write the documents table).
Agent-to-agent
Agents see the same database, so they can see each other’s tasks and documents. Coordination patterns:- @-mentions in comments — mentioning
@agent-slugin a task or document comment enqueues an inbox item for that agent via theenqueue_comment_mentionstrigger. Dispatcher wakes the agent. - Automation rules —
automation_rulestable can fire inbox items on CRM events. Agent A writes a contact update → rule creates inbox item for agent B. - Task assignment — assigning a task to an agent enqueues an inbox item (via
enqueue_task_assignmenttrigger).
Debugging an agent
- Check the agent’s Chrome window — noVNC into the gateway; you’ll see Chrome with the agent’s profile. Right-click → Agents → click their window.
- Check command history — Settings → System → Commands tab. Filter by status or gateway.
- Check inbox history — Settings → System → Inbox tab. See what triggered each wake and its status.
- Check audit log — Settings → System → Audit Log tab. Filter by module, action, or actor type.
- Tail runner logs —
docker compose logs -f runnerwhile the agent works. - Tail gateway logs —
docker compose logs -f gateway | grep <agent-slug>for openclaw-side traces. - Read the agent’s branch — file browser in the UI, or
docker compose exec gateway bash→cd ~/.openclaw/workspace-<slug>→ inspect directly.