openclaw - ✅(Solved) Fix Per-agent contextInjection override [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#76046Fetched 2026-05-03 04:42:56
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
2
Timeline (top)
referenced ×4commented ×1cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #76054: feat(agents): allow per-agent contextInjection override in agents.list[]

Description (problem / solution / changelog)

Problem

agents.defaults.contextInjection is the only place to configure context injection mode. There is no per-agent override. This forces all agents on a host to share the same injection strategy, even when they have different rule-strictness needs.

For example, a general-purpose agent benefits from continuation-skip (token savings), while a strict agent with prescriptive rules needs always to prevent rule drift on continuation turns.

Fix

Add contextInjection to the per-agent config (agents.list[]), with fallback resolution:

per-agent override → agents.defaults.contextInjection → 'always'

Config example

{
  "agents": {
    "defaults": { "contextInjection": "continuation-skip" },
    "list": [
      { "id": "main" },
      { "id": "strict-agent", "contextInjection": "always" }
    ]
  }
}

Changes

  • zod-schema.agent-runtime.ts: Add contextInjection enum to AgentEntrySchema
  • bootstrap-files.ts: Update resolveContextInjectionMode to accept optional agentId and check per-agent config first
  • compact.ts, attempt.ts: Pass agent ID to the resolver
  • schema.help.ts, schema.labels.ts: Add help text and label for the new field
  • bootstrap-files.test.ts: Add 4 test cases for per-agent resolution, fallback, and backward compatibility
  • CHANGELOG.md: Add entry

Testing

All 62 tests in bootstrap-files.test.ts pass, including the new per-agent override tests:

  • Per-agent override honored when agentId matches
  • Falls back to defaults when agentId doesn't match
  • Falls back to defaults when per-agent contextInjection is not set
  • Backward compatible when no agentId is provided

Closes #76046

Changed files

  • docs/.generated/config-baseline.sha256 (modified, +2/-2)
  • src/agents/bootstrap-files.test.ts (modified, +53/-0)
  • src/agents/bootstrap-files.ts (modified, +10/-1)
  • src/agents/pi-embedded-runner/compact.ts (modified, +1/-1)
  • src/agents/pi-embedded-runner/run/attempt.ts (modified, +1/-1)
  • src/config/schema.base.generated.ts (modified, +12/-0)
  • src/config/schema.help.ts (modified, +2/-0)
  • src/config/schema.labels.ts (modified, +1/-0)
  • src/config/types.agents.ts (modified, +2/-0)
  • src/config/zod-schema.agent-runtime.ts (modified, +1/-0)

Code Example

{
  \"agents\": {
    \"defaults\": {
      \"contextInjection\": \"continuation-skip\"
    },
    \"list\": [
      { \"id\": \"main\" },
      { \"id\": \"krishna\", \"contextInjection\": \"always\" }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Problem

agents.defaults.contextInjection is the only place this setting can be configured. There is no per-agent override (agents.list[].contextInjection).

This becomes load-bearing for setups that run multiple agents with different rule-strictness needs:

  • A general-purpose main agent benefits from continuation-skip — most rules are advisory, multi-turn conversations are common, token cost matters.
  • A specialized agent with prescriptive rules (anti-fallback guards, mandatory tool sequences, safety constraints) needs always so the rules are present in the system prompt on every turn — otherwise rules drift on continuation turns and the LLM falls back to its pre-trained defaults.

Today the only options are:

  • Use continuation-skip globally and accept rule drift on the strict agent.
  • Use always globally and pay the bootstrap re-injection cost on every turn for every agent.

Neither is great when the agents have genuinely different needs.

Concrete example (driving this request)

Krishna is an EM operating system agent with a strict capture flow:

  1. MCP-only writes (no local file fallback for captures)
  2. Mandatory tool order: read entities → list threads → run matcher → present match → wait for explicit ack → commit on ack
  3. Anti-fallback rules in TOOLS.md ("never write captures to workspace memory files")

Under continuation-skip, turn 2+ of any session drops these rules from the system prompt. The LLM, no longer seeing the anti-fallback rules, drifts toward its pre-trained instinct: write a memory file, search local memory, etc. This was reproducible — turn 1 of a clean session followed the rules perfectly; turn 2 silently auto-logged to inbox without the required user prompt. Switching the default to always fixed it but now applies to all three agents on the host.

Proposal

Allow contextInjection in the per-agent config block, falling back to agents.defaults.contextInjection when unset:

{
  \"agents\": {
    \"defaults\": {
      \"contextInjection\": \"continuation-skip\"
    },
    \"list\": [
      { \"id\": \"main\" },
      { \"id\": \"krishna\", \"contextInjection\": \"always\" }
    ]
  }
}

Resolution order: per-agent override → defaults → "always" (code default).

Implementation pointers

The current resolver is single-source:

```ts // src/agents/bootstrap-files.ts export function resolveContextInjectionMode(config?: OpenClawConfig): AgentContextInjection { return config?.agents?.defaults?.contextInjection ?? "always"; } ```

Needs to take an `agentId` and look up the per-agent override first. Schema additions in `src/config/types.agents.ts` (AgentConfig) and `src/config/zod-schema.agent-runtime.ts` (AgentEntrySchema). Help text in `src/config/schema.help.ts`.

The same pattern would benefit `bootstrapMaxChars`, `bootstrapTotalMaxChars`, and `bootstrapPromptTruncationWarning` if the maintainers want to broaden the scope, since those are also in `agents.defaults` only.

Acceptance

extent analysis

TL;DR

To address the issue, allow contextInjection in the per-agent config block, falling back to agents.defaults.contextInjection when unset.

Guidance

  • Introduce a per-agent override for contextInjection in the agent config block, as proposed in the issue.
  • Update the resolveContextInjectionMode function to take an agentId and look up the per-agent override first, before falling back to the default value.
  • Add schema additions in src/config/types.agents.ts and src/config/zod-schema.agent-runtime.ts to support the new per-agent override.
  • Consider applying the same pattern to other settings like bootstrapMaxChars, bootstrapTotalMaxChars, and bootstrapPromptTruncationWarning for broader flexibility.

Example

{
  "agents": {
    "defaults": {
      "contextInjection": "continuation-skip"
    },
    "list": [
      { "id": "main" },
      { "id": "krishna", "contextInjection": "always" }
    ]
  }
}

Notes

The proposed solution requires updates to the configuration schema and the resolveContextInjectionMode function. The changes should be backwards-compatible, ensuring that existing configurations without per-agent overrides continue to work as expected.

Recommendation

Apply the workaround by introducing per-agent overrides for contextInjection, as this allows for more flexibility in configuring different agents with varying rule-strictness needs.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING