Skip to content

Commit dae06a2

Browse files
authored
fix: add self-knowledge docs rule to system prompt (#90882)
Summary: - This PR replaces the generated Documentation prompt wording with self-knowledge docs-authority guidance and updates prompt tests plus the system-prompt docs. - PR surface: Source 0, Tests +27, Docs +6. Total +33 across 4 files. - Reproducibility: yes. from source for the prompt gap: current main and v2026.6.8 have only broad docs-first ... ledge failure example. I did not run a fresh current-main live model conversation in this read-only review. Automerge notes: - PR branch already contained follow-up commit before automerge: fix: strengthen self-knowledge docs prompt - PR branch already contained follow-up commit before automerge: test: narrow cli prompt tool assertion - PR branch already contained follow-up commit before automerge: fix: condense self-knowledge docs prompt - PR branch already contained follow-up commit before automerge: fix: clarify self-knowledge docs authority - PR branch already contained follow-up commit before automerge: Merge branch 'main' into sutrah/self-knowledge-docs-prompt Validation: - ClawSweeper review passed for head 88a7db5. - Required merge gates passed before the squash merge. Prepared head SHA: 88a7db5 Review: #90882 (comment) Co-authored-by: Sutra Hsing <sutrahsing@163.com> Co-authored-by: sutra <sutrahsing@163.com>
1 parent 52948a1 commit dae06a2

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

docs/concepts/system-prompt.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,15 @@ The same section also includes the OpenClaw source location. Git checkouts expos
315315
source root so the agent can inspect code directly. Package installs include the GitHub
316316
source URL and tell the agent to review source there whenever the docs are incomplete or
317317
stale. The prompt also notes the public docs mirror, community Discord, and ClawHub
318-
([https://clawhub.ai](https://clawhub.ai)) for skills discovery. It tells the model to
319-
consult docs first for OpenClaw behavior, commands, configuration, or architecture, and to
320-
run `openclaw status` itself when possible (asking the user only when it lacks access).
318+
([https://clawhub.ai](https://clawhub.ai)) for skills discovery. It frames docs as the
319+
authority for OpenClaw self-knowledge before the model understands how OpenClaw works,
320+
including memory/daily notes, sessions, tools, Gateway, config, commands, or project
321+
context. The prompt tells the model to use local docs (or the docs mirror when local docs
322+
are unavailable) first, and to treat AGENTS.md, project context, workspace/profile/memory
323+
notes, and `memory_search` as instruction context or user memory rather than OpenClaw
324+
design or implementation knowledge. If docs are silent or stale, the model should say so
325+
and inspect source. The prompt also tells the model to run `openclaw status` itself when
326+
possible, asking the user only when it lacks access.
321327
For configuration specifically, it points agents to the `gateway` tool action
322328
`config.schema.lookup` for exact field-level docs and constraints, then to
323329
`docs/gateway/configuration.md` and `docs/gateway/configuration-reference.md`

src/agents/cli-runner/prepare.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
21852185
expect(createMcpLoopbackServerConfig).not.toHaveBeenCalled();
21862186
expect(resolveMcpLoopbackScopedTools).not.toHaveBeenCalled();
21872187
expect(context.systemPrompt).not.toContain("## Memory Recall");
2188-
expect(context.systemPrompt).not.toContain("memory_search");
2188+
expect(context.systemPrompt).not.toMatch(/^- memory_search\b/m);
21892189
expect(context.systemPromptReport.tools.entries).toEqual([]);
21902190
expect(context.promptToolNamesHash).toBeUndefined();
21912191
expect(context.preparedBackend.env).toBeUndefined();

src/agents/system-prompt.test.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ describe("buildAgentSystemPrompt", () => {
507507
expect(prompt).toContain("If a skill's <version> differs from a previous turn");
508508
expect(prompt).toContain("If several apply, choose the most specific.");
509509
expect(prompt).toContain("Docs: /tmp/openclaw/docs");
510-
expect(prompt).toContain("OpenClaw behavior/config/architecture: read local docs first.");
510+
expect(prompt).toContain(
511+
"Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use `Read` or search local docs first; treat AGENTS.md/project context, workspace/profile/memory notes, and `memory_search` as instruction context or user memory, not OpenClaw design/implementation knowledge.",
512+
);
511513
});
512514

513515
it("includes docs guidance when docsPath is provided", () => {
@@ -520,8 +522,30 @@ describe("buildAgentSystemPrompt", () => {
520522
expect(prompt).toContain("## Documentation");
521523
expect(prompt).toContain("Docs: /tmp/openclaw/docs");
522524
expect(prompt).toContain("Source: /tmp/openclaw");
523-
expect(prompt).toContain("OpenClaw behavior/config/architecture: read local docs first.");
524-
expect(prompt).toContain("If docs are stale/incomplete, inspect local source.");
525+
expect(prompt).toContain(
526+
"Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use `read` or search local docs first; treat AGENTS.md/project context, workspace/profile/memory notes, and `memory_search` as instruction context or user memory, not OpenClaw design/implementation knowledge.",
527+
);
528+
expect(prompt).toContain("If docs are silent/stale, say so and inspect local source.");
529+
});
530+
531+
it("keeps self-knowledge docs guidance concise and authoritative", () => {
532+
const prompt = buildAgentSystemPrompt({
533+
workspaceDir: "/tmp/openclaw",
534+
docsPath: "/tmp/openclaw/docs",
535+
sourcePath: "/tmp/openclaw",
536+
toolNames: ["read", "memory_search"],
537+
});
538+
const docsStart = prompt.indexOf("## Documentation");
539+
const nextSection = prompt.indexOf("\n## ", docsStart + 1);
540+
const docsSection = prompt.slice(docsStart, nextSection);
541+
542+
expect(prompt).toContain(
543+
"Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use `read` or search local docs first; treat AGENTS.md/project context, workspace/profile/memory notes, and `memory_search` as instruction context or user memory, not OpenClaw design/implementation knowledge.",
544+
);
545+
expect(docsSection.length).toBeLessThan(840);
546+
expect(prompt).not.toContain("Self-knowledge rule: for questions about");
547+
expect(prompt).not.toContain("Treat questions about daily notes");
548+
expect(prompt).not.toContain("never answer from AGENTS.md/project context");
525549
});
526550

527551
it("falls back to public docs and GitHub source guidance when local docs are unavailable", () => {
@@ -531,7 +555,10 @@ describe("buildAgentSystemPrompt", () => {
531555

532556
expect(prompt).toContain("Docs: https://docs.openclaw.ai");
533557
expect(prompt).toContain("Source: https://github.com/openclaw/openclaw");
534-
expect(prompt).toContain("If docs are stale/incomplete, inspect GitHub source.");
558+
expect(prompt).toContain(
559+
"Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use the docs mirror first when web tooling is available; treat AGENTS.md/project context, workspace/profile/memory notes, and `memory_search` as instruction context or user memory, not OpenClaw design/implementation knowledge.",
560+
);
561+
expect(prompt).toContain("If docs are silent/stale, say so and inspect GitHub source.");
535562
});
536563

537564
it("includes workspace notes when provided", () => {

src/agents/system-prompt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ function buildDocsSection(params: {
610610
docsPath ? "Mirror: https://docs.openclaw.ai" : undefined,
611611
sourcePath ? `Source: ${sourcePath}` : "Source: https://github.com/openclaw/openclaw",
612612
docsPath
613-
? "OpenClaw behavior/config/architecture: read local docs first."
614-
: "OpenClaw behavior/config/architecture: read docs mirror first.",
613+
? `Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use \`${params.readToolName}\` or search local docs first; treat AGENTS.md/project context, workspace/profile/memory notes, and \`memory_search\` as instruction context or user memory, not OpenClaw design/implementation knowledge.`
614+
: "Docs are authoritative for OpenClaw self-knowledge: before understanding how OpenClaw works (memory/daily notes, sessions, tools, Gateway, config, commands, project context), use the docs mirror first when web tooling is available; treat AGENTS.md/project context, workspace/profile/memory notes, and `memory_search` as instruction context or user memory, not OpenClaw design/implementation knowledge.",
615615
"Config fields: use `gateway` action `config.schema.lookup`; broader config docs: `docs/gateway/configuration.md`, `docs/gateway/configuration-reference.md`.",
616616
sourcePath
617-
? "If docs are stale/incomplete, inspect local source."
618-
: "If docs are stale/incomplete, inspect GitHub source.",
617+
? "If docs are silent/stale, say so and inspect local source."
618+
: "If docs are silent/stale, say so and inspect GitHub source.",
619619
"Diagnosing issues: run `openclaw status` when possible; ask user only if blocked.",
620620
"",
621621
];

0 commit comments

Comments
 (0)