Skip to content

feat: add run-scoped file sharing for subagents - #15848

Draft
usnavy13 wants to merge 8 commits into
danny-avila:devfrom
usnavy13:feat/run-scoped-subagent-files
Draft

feat: add run-scoped file sharing for subagents#15848
usnavy13 wants to merge 8 commits into
danny-avila:devfrom
usnavy13:feat/run-scoped-subagent-files

Conversation

@usnavy13

@usnavy13 usnavy13 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Subagents currently cannot reliably consume the files attached to the current message or return generated files as durable conversation attachments. This adds opt-in, run-scoped sharing on top of unified upload (#15763): authorized children receive the current message's files, can inspect and refine private sandbox outputs across multiple code calls, and explicitly publish a chosen output version for the parent and user.

Fixes #14261.

SDK dependency included: danny-avila/agents#539 is merged and published in @librechat/agents 3.8.6. Both dependency manifests require ^3.8.6, and the lockfile installs registry version 3.8.6, which exposes SUBAGENT_CONTEXT_VERSION = 1. A normal locked install includes the required adapter; no local SDK build is needed.

How it works

The host owns file authorization, persistence and cleanup; the SDK carries a distinct execution context through child runs and tool dispatch.

sequenceDiagram
    participant User
    participant Parent
    participant Child
    participant Files as Run catalog and file storage
    User->>Parent: Attach a PDF and request delegated analysis
    Parent->>Child: Delegate with authorized current-message files
    Child->>Files: Lazily provision input for search or code
    Child->>Child: Generate, inspect and refine private output versions
    Child->>Files: list_run_files, then publish_artifact(artifact_id)
    Files-->>Parent: Durable file ID and conversation attachment
    Parent-->>User: Downloadable CSV or report
Loading
  • packages/api/src/agents/files/ owns the run manifest, per-execution sandbox context, immutable private snapshots and SDK adapter. Existing provider/text delivery and lazy search/code provisioning remain the input paths; agent setup files keep their existing scope.
  • list_run_files and publish_artifact are added only to participating delegating agents and child executions. Generated files remain private until publication succeeds. Separate artifact IDs select immutable versions, including versions of the same filename; a parent cannot publish a child's private outputs.
  • Publication uses the existing upload/storage/preview pipeline and records user, tenant, conversation, run, execution and producing-agent provenance. Authorized parent chains receive published files; sibling access additionally requires deployment permission and explicit recipients. Retries return the same durable file ID without recreating a deleted file.
  • Model attachment budgets count resolved, deduplicated model-bound files and permanent child context. Inputs explicitly routed only to tools retain upload/content-policy checks without consuming the model attachment budget.
  • Unrelated tool batches reuse the initialized authorized catalog. File-consuming batches and explicit catalog reads refresh publications to honor external deletion; overlapping preparations wait for an in-flight refresh before provisioning resources.
  • Completion, cancellation, expiry and approval pauses remove private snapshots. Durable published files retain normal retention/deletion behavior and can be downloaded from the conversation or Files panel and attached to a later message. Concurrent child executions remain isolated.
  • endpoints.agents.fileSharing exposes the deployment toggle, sibling policy, file count, private-byte budget and lifetime in librechat.yaml. The localized Share files with subagents agent setting also requires opt-in. Both toggles default off and existing saved agents need no migration.

Current support is foreground chat delegation with managed code environments and teams using the same provider, endpoint, model and Responses API setting. Shared-file runs reject detached/background execution, attached workstation environments and entry points without the host adapter. Configuration, lifecycle and support details are in docs/run_files.md.

Change Type

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

Verified locally at LibreChat 4bd39ebe8cc794b98d11f4b7106067f2e1026448, including upstream dev at e7dea565d1fdf6f90ecae8945a8efd614a93c954, using a clean registry install of SDK 3.8.6:

  • 830 focused tests passed across 24 suites covering run files, encoding, provisioning, publication, lifecycle, tools, handlers and attachment initialization. Regression coverage includes tool-only budgets, inferred model delivery, permanent context, failed refresh retries, external deletion and concurrent preparation ordering.
  • All five workspace npx tsc --noEmit checks passed. Formatting, package/dependency validation, circular dependency checks, config migration and i18n checks passed.
  • Clean locked npm ci, package builds and the production application build passed. The installed SDK version, capability version and registry integrity are verified before the checks; manifests and lockfile remain unchanged.
  • All eight file-sharing browser cases passed with memory and all eight with Redis, with no skips or flaky retries. These exercise native/text input delivery, lazy search/code access, nested delegation, sibling authorization, concurrent runs, cancellation, checkpoint restoration, private output versions, reload and downloads.
  • Exact npm run lighthouse passed with the 250 ms Mongo query penalty: median LCP 3,847 ms / 4,500 ms, CLS 0.0371 / 0.1, TBT 96 ms / 500 ms. All three cold navigations rendered the seeded conversation transcript.

Current feature validation uses the published npm package throughout, without replacing its files or rebuilding SDK source.

GitHub CI at this head completed with 31 successful checks, five skipped and no failures. All executed workflows passed, including backend/frontend tests, typechecks, static checks, integrations, production Docker smoke and Lighthouse. Remote Playwright and Bombadil were skipped by their contributor-association guards; the local file-sharing browser results above cover both memory and Redis.

Earlier broader validation at LibreChat dc656be12a7a6c224342c710028f8892c4ff4a31 with the development SDK at c5f3f99e covered all six unit workspaces (31,381 passing tests, 27 existing skips, combining full runs and successful focused retries), 229 browser cases per memory/Redis topology, Redis standalone/cluster and agent Mongo/Redis integrations, S3-compatible storage, Redis transport, MCP topologies and production Docker runtime checks. Those complete selections were not all repeated locally at the current head.

The branch also repairs fixtures exercised by those checks: partial mocks retain real exports, Redis teardown closes both clients, LibreOffice has a real PPTX and malformed OOXML fixture, and deployment-skill download assertions compare checked-out bytes across LF/CRLF formats.

Earlier optional validation recorded seven Langfuse admin expectations failing identically at the branch base. Non-blocking Bombadil exploration failed a sidebar navigation property after list reordering; its assertion retained the old row number although the requested conversation opened. The relevant code matched base, but that exploratory run remains failed. Those optional checks were not repeated with SDK 3.8.6. Three browser cases require stateful/paired Code API protocols unavailable locally. Other credential/protocol guards and upstream secret-backed accessibility review remain unverified.

Test Configuration

Node 24.16.0 / npm 11.13.0; isolated Linux runs, Chrome and disposable MongoDB/Redis. Browser scenarios use the real app and released SDK 3.8.6 with deterministic model, Code API and RAG fixtures. Earlier SDK live-provider checks used Azure OpenAI.

Run npm ci and follow the run-file setup and the browser harness setup, then run from the LibreChat root:

npm run e2e:mock -- run-files.spec.ts run-files-delivery.spec.ts run-files-lifecycle.spec.ts
npm run e2e:mock:redis -- run-files.spec.ts run-files-delivery.spec.ts run-files-lifecycle.spec.ts
npm run static-checks:full -- --against origin/dev
npm run lighthouse

Use the canonical upstream dev ref if your remote is named differently. In a live session, enable deployment file sharing and the parent agent's subagent setting, attach a PDF, and ask a child to analyze it, refine a CSV in another code call, then publish the selected version. Verify download and follow-up attachment reuse; an agent without sharing enabled should not receive the two tools.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes in this repository
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my feature works
  • Local unit tests pass with my changes (existing skips and optional failures noted above)
  • The companion SDK change has been merged, published and pinned in this repository
  • A pull request for the user-facing documentation has been submitted to LibreChat-AI/librechat.ai

Delegate current-message files through authorized execution catalogs and publish selected immutable code-output versions through the existing file pipeline.

Requires the companion agents SDK context adapter before the dependency can be released and pinned.
Keep citations and other non-sandbox artifacts on their existing delivery path while retaining private code outputs and inspected images until publication.

Cover native and text delivery, nested and sibling authorization, concurrent runs, cancellation cleanup, and checkpoint recovery through the browser harness.
@danny-avila

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-12T14:48:57.222850Z 4bd39eb Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: dc656be12a

ℹ️ 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/run.ts
Comment thread packages/api/src/agents/files/manifest.ts
Comment thread packages/api/src/agents/files/encode.ts Outdated
Repository owner deleted a comment from chatgpt-codex-connector Bot Sep 12, 2026
@danny-avila

Copy link
Copy Markdown
Owner

@codex review the latest head

@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: 4bd39ebe8c

ℹ️ 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 on lines +748 to +752
const outputPersistence = createCodeOutputPersistence({
publication,
claim: claimCodeFile,
commit: commitCodeFile,
});

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 Move publication behavior out of the CJS service

Move this publication persistence orchestration into packages/api and leave process.js as a thin adapter. The change makes an /api CJS module select and coordinate the publication-specific claim/commit path, directly violating the repository boundary that newly added branches, validation, and service calls belong in the TypeScript workspace; retaining it here also leaves this new storage behavior outside that workspace's typechecked boundary.

AGENTS.md reference: AGENTS.md:L53-L57

Useful? React with 👍 / 👎.

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.

2 participants