Skip to content

πŸ› fix(agentDocuments): add progressive disclosure PolicyLoad mode#13571

Merged
nekomeowww merged 2 commits intocanaryfrom
feat/progressive-disclosure-policy-load
Apr 4, 2026
Merged

πŸ› fix(agentDocuments): add progressive disclosure PolicyLoad mode#13571
nekomeowww merged 2 commits intocanaryfrom
feat/progressive-disclosure-policy-load

Conversation

@arvinxx
Copy link
Copy Markdown
Member

@arvinxx arvinxx commented Apr 4, 2026

πŸ’» Change Type

  • ✨ feat

πŸ”— Related Issue

Fixes LOBE-6702

πŸ”€ Description of Change

Add a new PolicyLoad.PROGRESSIVE mode for agent document prompt injection. Instead of injecting full document content into the prompt (which is costly for many/large documents), progressive mode injects only a lightweight index showing each document's title and description.

Key changes:

  • New PolicyLoad.PROGRESSIVE = 'progressive' enum value
  • Progressive documents are formatted as an <agent_documents_index> block with title + description per entry
  • New documents now default to PROGRESSIVE instead of ALWAYS β€” reducing token usage out of the box
  • Full content remains accessible via readDocument tool (on-demand)
  • Existing ALWAYS documents are unaffected (backward compatible)

Files changed (11):

  • packages/agent-templates/src/types.ts β€” enum addition
  • packages/context-engine/.../shared.ts β€” progressive index formatting in combineDocuments
  • packages/database/.../permission.ts β€” allow PROGRESSIVE in auto-load gate
  • packages/database/.../agentDocument.ts β€” default policyLoad β†’ PROGRESSIVE
  • packages/database/.../policy.ts β€” support mode: 'progressive' in tool policy composition
  • packages/database/.../types.ts β€” add 'progressive' to ToolUpdateLoadRule.mode
  • src/services/agentDocument.ts β€” pass description + policyLoad to context
  • src/server/.../RuntimeExecutors.ts β€” same for server-side mapping

πŸ§ͺ How to Test

  • Added/updated tests
# Permission tests (7 tests)
cd packages/database && bunx vitest run src/models/agentDocuments/policy/__tests__/checks.test.ts

# Injection formatting tests (14 tests)
cd packages/context-engine && bunx vitest run src/providers/__tests__/AgentDocumentInjector.test.ts

# Document creation default tests (14 tests)
cd packages/database && bunx vitest run src/models/agentDocuments/__tests__/agentDocument.test.ts

πŸ“ Additional Information

No database migration needed β€” policy_load is varchar(30) and accepts the new 'progressive' string value. The Drizzle schema .default() is left unchanged to avoid migration; only the application-level default in create() is updated.

πŸ€– Generated with Claude Code

Add PolicyLoad.PROGRESSIVE that injects only document title and description
as a lightweight file index instead of full content. New documents default
to this mode, reducing token usage for agents with many/large documents.

Fixes LOBE-6702

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 4, 2026 3:37pm

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
βœ… Project coverage is 66.64%. Comparing base (a7e3d19) to head (2a1d1b4).
⚠️ Report is 4 commits behind head on canary.

Additional details and impacted files
@@           Coverage Diff            @@
##           canary   #13571    +/-   ##
========================================
  Coverage   66.64%   66.64%            
========================================
  Files        1997     1997            
  Lines      165699   165726    +27     
  Branches    16847    16098   -749     
========================================
+ Hits       110428   110455    +27     
  Misses      55147    55147            
  Partials      124      124            
Flag Coverage Ξ”
app 58.50% <66.66%> (-0.01%) ⬇️
database 92.60% <100.00%> (+0.02%) ⬆️
packages/agent-runtime 88.98% <ΓΈ> (ΓΈ)
packages/context-engine 85.51% <100.00%> (+0.11%) ⬆️
packages/conversation-flow 92.36% <ΓΈ> (ΓΈ)
packages/file-loaders 87.02% <ΓΈ> (ΓΈ)
packages/memory-user-memory 66.68% <ΓΈ> (ΓΈ)
packages/model-bank 99.85% <ΓΈ> (ΓΈ)
packages/model-runtime 84.66% <ΓΈ> (ΓΈ)
packages/prompts 65.80% <ΓΈ> (ΓΈ)
packages/python-interpreter 92.90% <ΓΈ> (ΓΈ)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (ΓΈ)
packages/utils 90.02% <ΓΈ> (ΓΈ)
packages/web-crawler 88.82% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Ξ”
Store 67.10% <ΓΈ> (ΓΈ)
Services 51.55% <100.00%> (+0.01%) ⬆️
Server 65.97% <50.00%> (-0.02%) ⬇️
Libs 51.03% <ΓΈ> (ΓΈ)
Utils 91.01% <ΓΈ> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx changed the title ✨ feat(agentDocuments): add progressive disclosure PolicyLoad mode πŸ› fix(agentDocuments): add progressive disclosure PolicyLoad mode Apr 4, 2026
@lobehubbot
Copy link
Copy Markdown
Member

πŸ‘‹ Assigning reviewers for this PR.

This PR adds a PolicyLoad.PROGRESSIVE mode touching context-engine, database models, agent-runtime, and services.

cc @nekomeowww @tjx666 β€” could you take a look? The changes affect agent document injection logic and database policy models.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71fc2c4ba5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

agentId,
createdAt,
policyLoad: PolicyLoad.ALWAYS,
policyLoad: PolicyLoad.PROGRESSIVE,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Persist progressive loadMode for newly created documents

Setting policyLoad to PROGRESSIVE here without also recording policy.context.loadMode = 'progressive' creates an inconsistency with composeToolPolicyUpdate: when updateLoadRule is later called without rule.mode (the current API shape), it falls back to 'always' and silently flips these docs back to full-content autoload. In practice, any load-rule edit on a newly created doc can disable the progressive behavior and reintroduce higher token usage.

Useful? React with πŸ‘Β / πŸ‘Ž.

…ule updates

composeToolPolicyUpdate used to fallback to 'always' when rule.mode was
omitted, silently flipping progressive docs back to full-content autoload.
Now it preserves the existing policyLoad when no explicit mode is provided.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nekomeowww nekomeowww merged commit 5b03f00 into canary Apr 4, 2026
36 checks passed
@nekomeowww nekomeowww deleted the feat/progressive-disclosure-policy-load branch April 4, 2026 17:23
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