Skip to content

πŸ—‚οΈ fix: Scope Handoff Agent Context Docs - #13167

Merged
danny-avila merged 3 commits into
devfrom
danny-avila/fix-agent-context-handoff-docs
May 18, 2026
Merged

danny-avila merged 3 commits into
devfrom
danny-avila/fix-agent-context-handoff-docs

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

I fixed agent context document scoping so shared run files remain available to every agent while each primary, handoff, or direct agent only receives its own permanent context documents.

  • Split primed resources into request attachments and agent context attachments while keeping the legacy attachments field for compatibility.
  • Passed per-agent context attachments into AgentClient for the primary agent and discovered handoff agents.
  • Applied shared run context, memory context, and each agent's scoped context through additional instructions so token budgeting and pruning include the injected document text.
  • Added regression coverage for direct context-doc chats, handoff context separation, and request attachment sharing without leaking Agent B docs into Agent A.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Ran npm run build:data-provider
  • Ran npm run build:data-schemas
  • Ran npm run build:api
  • Ran cd packages/api && npx jest src/agents/resources.test.ts src/agents/__tests__/initialize.test.ts --runInBand
  • Ran cd api && npx jest server/controllers/agents/client.test.js server/services/Endpoints/agents/initialize.spec.js --runInBand

Test Configuration:

  • Node.js v20.19.5
  • Jest targeted package and API suites

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI review requested due to automatic review settings May 17, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes multi-agent attachment scoping for the Agents endpoint by separating shared run attachments (safe to share across agents in the same run) from agent-scoped context documents (per-agent permanent context), and ensuring the scoped document text is injected into each agent’s dynamic instructions so token budgeting/pruning accounts for it.

Changes:

  • Split primeResources output into requestAttachments (shared run files) vs agentContextAttachments (per-agent context-doc files), while keeping legacy attachments for compatibility.
  • Plumb requestAttachments + an agentContextAttachmentsByAgentId map through initializeClient β†’ AgentClient, and inject per-agent scoped doc text via additional_instructions.
  • Add regression tests covering direct context-doc chats, handoff scoping isolation, and shared request attachment behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/api/src/agents/resources.ts Enhances resource priming to return both shared request attachments and agent-scoped context attachments.
packages/api/src/agents/resources.test.ts Updates/extends unit tests validating the new attachment split behavior.
packages/api/src/agents/initialize.ts Adopts new primeResources fields, adds compatibility behavior, and exposes both attachment groups on InitializedAgent.
packages/api/src/agents/tests/initialize.test.ts Adds coverage ensuring initializeAgent preserves separation of request vs context attachments.
api/server/services/Endpoints/agents/initialize.js Collects per-agent context attachments and passes shared vs scoped attachment data into AgentClient.
api/server/services/Endpoints/agents/initialize.spec.js Adds regression assertions for request attachment sharing and per-agent context isolation.
api/server/controllers/agents/client.js Injects per-agent scoped context-doc text into each agent’s run context (without leaking across agents).
api/server/controllers/agents/client.test.js Adds tests ensuring shared request context is applied to all agents while scoped docs remain isolated per agent.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: πŸš€ deployed

The LibreChat-pr-13167 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila changed the title 🧭 fix: Scope Handoff Agent Context Docs πŸ—‚οΈ fix: Scope Handoff Agent Context Docs May 18, 2026
@danny-avila
danny-avila changed the base branch from main to dev May 18, 2026 13:19
@danny-avila
danny-avila marked this pull request as ready for review May 18, 2026 13:20

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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: 13bbd7f930

ℹ️ 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".

Comment thread packages/api/src/agents/resources.ts
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: πŸš€ deployed

The LibreChat-pr-13167 index is now live on the MCP server.
Deploy run

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ 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".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: πŸš€ deployed

The LibreChat-pr-13167 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ 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".

@danny-avila danny-avila linked an issue May 18, 2026 that may be closed by this pull request
1 task done
@danny-avila
danny-avila merged commit 68eac10 into dev May 18, 2026
12 checks passed
@danny-avila
danny-avila deleted the danny-avila/fix-agent-context-handoff-docs branch May 18, 2026 19:36
patricia2510 pushed a commit to lexaeon-org/libre-chat that referenced this pull request May 21, 2026
* fix: Scope agent context docs to handoff agents

* fix: Deduplicate scoped request context

* refactor: Extract agent attachment helpers
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request May 22, 2026
* fix: Scope agent context docs to handoff agents

* fix: Deduplicate scoped request context

* refactor: Extract agent attachment helpers
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
* fix: Scope agent context docs to handoff agents

* fix: Deduplicate scoped request context

* refactor: Extract agent attachment helpers
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.

[Bug]: Agent Context Document not loaded after handoff

2 participants