openclaw - 💡(How to fix) Fix [Feature]: Support "Core Logic + External References" Architecture to Mitigate Context Bloat in Complex Agents [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#76981Fetched 2026-05-04 04:59:47
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Timeline (top)
closed ×1commented ×1labeled ×1

Support "Core Logic + External References" Architecture to Mitigate Context Bloat in Complex Agents

Error Message

I have observed a pattern where a single Agent's instruction file can balloon to 3,000+ words, containing every specific script command, JSON schema, and error-handling step for various sub-tasks. (Plus 50 more lines of error handling and JSON schemas for rollback)

Root Cause

This "Monolithic Prompt" approach causes three critical issues: 1. Context Saturation: Every time the Agent is spawned, the entire massive instruction set is loaded into the context window. This wastes valuable token capacity and increases latency. 2. Attention Dilution: LLMs struggle to focus when instructions are too dense. Critical "Red-line Rules" or specific API formats often get ignored because they are buried in irrelevant details for the current phase. 3. Maintenance Nightmare: Updating a single script parameter or data schema requires modifying the massive core file. If multiple agents share a logic, it must be duplicated across all of them, leading to version drift.

Fix Action

Fix / Workaround

  • Current Workaround: Users manually maintain small reference.md files and tell the Agent to read them via prompt engineering (e.g., "Always read file X before task Y").
    • Limitation: This relies entirely on the LLM's instruction-following capability. If OpenClaw supported a native imports or lazy_load configuration in the agent manifest, it would be much more robust and enforceable by the system.
RAW_BUFFERClick to expand / collapse

Summary

Support "Core Logic + External References" Architecture to Mitigate Context Bloat in Complex Agents

Problem to solve

As OpenClaw is increasingly used for complex, multi-phase workflows (e.g., long-running data pipelines, comprehensive code reviews, or automated DevOps tasks), the Agent configuration files ([AGENTS.md](http://agents.md/), [SOUL.md](http://soul.md/)) tend to grow rapidly.

I have observed a pattern where a single Agent's instruction file can balloon to 3,000+ words, containing every specific script command, JSON schema, and error-handling step for various sub-tasks.    

This "Monolithic Prompt" approach causes three critical issues:
1.  Context Saturation: Every time the Agent is spawned, the entire massive instruction set is loaded into the context window. This wastes valuable token capacity and increases latency.
2.  Attention Dilution: LLMs struggle to focus when instructions are too dense. Critical "Red-line Rules" or specific API formats often get ignored because they are buried in irrelevant details for the current phase.
3.  Maintenance Nightmare: Updating a single script parameter or data schema requires modifying the massive core file. If multiple agents share a logic, it must be duplicated across all of them, leading to version drift.

Proposed solution

 I propose implementing a "Core + External References" Architecture (Index-based Lazy Loading) natively in OpenClaw:

1.  Separation of Concerns:
    - Core Files ([AGENTS.md](http://agents.md/)): Should ONLY contain the agent's identity, core decision-making principles, red-line safety rules, and indexes/hooks pointing to external reference files.
    - Reference Files (references/ or skills/): Store heavy, phase-specific details such as exact shell commands, JSON response schemas, large forbidden-word lists, and complex sub-routines.

2.  Lazy Loading Mechanism:
    - Allow agents to be instructed to read specific reference files only when relevant.
    - Instead of loading 2,000 words of deployment scripts at startup, the Agent loads them only when the "Deploy" phase is triggered.

3.  Generic Use Case Example:

    Scenario: An Agent responsible for a complex CI/CD pipeline.

    Current State (Bloated):
    markdown
    ## Deployment Phase
    1. Run: curl -X POST https://api.example.com/deploy -H "Auth: Bearer $TOKEN" -d '{"service": "core-api", "tag": "latest"}'
    2. If 403, check credentials in /etc/secrets...
    3. Wait for 30s, then poll /health endpoint...
    (Plus 50 more lines of error handling and JSON schemas for rollback)


    Proposed State (Optimized):
    markdown
    ## Core Rules
    - Identity: You are the CI/CD Automation Agent.
    - Reference Rule: Before executing any deployment step, YOU MUST read references/[deployment_playbook.md](http://deployment_playbook.md/) to get the current API endpoints and schemas. Do not rely on memory.

    ## Workflow
    - Phase 1: Build & Test
    - Phase 2: Deploy (Ref: references/[deployment_playbook.md](http://deployment_playbook.md/))
    - Phase 3: Verify (Ref: references/[health_check_standards.md](http://health_check_standards.md/))

Alternatives considered

- Current Workaround: Users manually maintain small [reference.md](http://reference.md/) files and tell the Agent to read them via prompt engineering (e.g., "Always read file X before task Y").
- Limitation: This relies entirely on the LLM's instruction-following capability. If OpenClaw supported a native imports or lazy_load configuration in the agent manifest, it would be much more robust and enforceable by the system.

Impact

.....

Evidence/examples

This architectural pattern ("Core Index + External Library") has been proven effective in other multi-agent frameworks. It typically reduces the loaded context per session by 60-70% while significantly increasing the accuracy of command execution, as the Agent is copying from a clean reference file rather than recalling from a compressed prompt.

Additional information

This architectural pattern ("Core Index + External Library") has been proven effective in other multi-agent frameworks. It typically reduces the loaded context per session by 60-70% while significantly increasing the accuracy of command execution, as the Agent is copying from a clean reference file rather than recalling from a compressed prompt.

(Note: This analysis was generated by AI agent based on source code review)

extent analysis

TL;DR

Implement a "Core + External References" Architecture to mitigate context bloat in complex agents by separating core logic from external references and using lazy loading.

Guidance

  • Separate core files from reference files to reduce context saturation and attention dilution.
  • Use lazy loading to load reference files only when relevant, instead of loading all files at startup.
  • Update agent configuration files to point to external reference files using indexes or hooks.
  • Test the new architecture with a generic use case, such as a CI/CD pipeline, to verify its effectiveness.

Example

## Core Rules
- Identity: You are the CI/CD Automation Agent.
- Reference Rule: Before executing any deployment step, YOU MUST read references/deployment_playbook.md to get the current API endpoints and schemas.

## Workflow
- Phase 1: Build & Test
- Phase 2: Deploy (Ref: references/deployment_playbook.md)
- Phase 3: Verify (Ref: references/health_check_standards.md)

Notes

The proposed architecture has been proven effective in other multi-agent frameworks, reducing loaded context per session by 60-70% and increasing accuracy of command execution.

Recommendation

Apply the proposed "Core + External References" Architecture to mitigate context bloat and improve agent performance, as it has been proven effective in other multi-agent frameworks.

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

openclaw - 💡(How to fix) Fix [Feature]: Support "Core Logic + External References" Architecture to Mitigate Context Bloat in Complex Agents [1 comments, 2 participants]