Skip to content

fix(openclaw): populate agentDir so sub-agent spawns work#523

Open
cmoralestbrain wants to merge 1 commit into
msitarzewski:mainfrom
cmoralestbrain:fix/openclaw-populate-agent-dir
Open

fix(openclaw): populate agentDir so sub-agent spawns work#523
cmoralestbrain wants to merge 1 commit into
msitarzewski:mainfrom
cmoralestbrain:fix/openclaw-populate-agent-dir

Conversation

@cmoralestbrain
Copy link
Copy Markdown

Summary

./scripts/install.sh --tool openclaw registers each agent in OpenClaw's config (via openclaw agents add --workspace <path>) but leaves the inferred agentDir (~/.openclaw/agents/<name>/agent/) empty on disk. The first time a user tries to delegate to one of these agents from the main agent (sessions_spawn(runtime="subagent", agentId=...)), OpenClaw can't find the agent files and the spawn fails.

This PR copies the same 3 files (SOUL.md / AGENTS.md / IDENTITY.md) into the agentDir and passes --agent-dir explicitly to agents add, so the post-install state matches the registered config.

Why it happens

OpenClaw's agents add defaults agentDir to ~/.openclaw/agents/<name>/agent/ when only --workspace is given, but it does not materialize the personality files there — that's left up to the caller. The current install_openclaw only writes them to the agency-agents/ workspace, so spawn is broken until the user manually copies or symlinks.

What's not changed

OpenClaw runtime files (HEARTBEAT.md, TOOLS.md, USER.md, .openclaw/) are created by the gateway on first spawn alongside the 3 curated files, so they are intentionally not copied by the installer.

Test plan

  • Bash syntax check (bash -n scripts/install.sh).
  • Tested on Ubuntu 22.04 with OpenClaw 2026.4.23 against a 184-agent corpus. Without the patch: sessions_spawn(geographer, ...) returns "agentDir does not exist". With the patch: same call succeeds; geographer responds within the spawn turn.
  • Idempotent: re-running install.sh --tool openclaw overwrites the same files (no duplication, no orphans).

Scope

Only the install_openclaw function. Other targets (claude-code, cursor, aider, etc.) are untouched.

`openclaw agents add --workspace <path>` registers `agentDir` (defaulting
to `~/.openclaw/agents/<name>/agent/`) but does not create or populate
that directory. Sub-agent spawns then fail with "agentDir does not
exist" the first time the user tries to delegate to one of the agents.

This patch:

1. Copies SOUL.md / AGENTS.md / IDENTITY.md into the agent state dir in
   addition to the workspace (3 extra `cp` calls per agent).
2. Passes `--agent-dir` explicitly to `openclaw agents add` so the
   registration matches what was just created on disk, even if a future
   OpenClaw release changes the default derivation.

OpenClaw runtime files (HEARTBEAT.md / TOOLS.md / USER.md / `.openclaw/`)
are created by the gateway on first spawn alongside the curated 3, so
they are intentionally not copied here.

Tested on a fresh Ubuntu 22.04 VM with OpenClaw 2026.4.23 and the
upstream `claude-code` + `openclaw` workspaces. Without the patch, the
first `sessions_spawn(runtime="subagent", agentId=...)` from the main
agent fails. With the patch, spawn succeeds end-to-end.
@bensl84
Copy link
Copy Markdown

bensl84 commented May 20, 2026

Closing — this is my personal fork (bensl84/agency-agents). The canonical project lives at https://github.com/msitarzewski/agency-agents — please re-open your PR there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants