-
Notifications
You must be signed in to change notification settings - Fork 118
feat: add host-owned context for subagent executions #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danny-avila
merged 13 commits into
LibreChat-AI:main
from
usnavy13:feat/run-scoped-subagent-files
Sep 12, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1d339dc
feat: add host-owned subagent execution context
usnavy13 c5f3f99
test: use Azure model defaults in live fixtures
usnavy13 1083640
fix: preserve subagent retry lifecycle state
danny-avila 0ccac63
fix: close subagent retry lifecycle gaps
danny-avila c0e724d
fix: retain detached delivery and refreshed files
danny-avila 015ddc8
fix: bound delivery retries and preserve batch refreshes
danny-avila c79b98f
fix: isolate batch baselines and abort delivery
danny-avila 8e48935
fix: preserve eager file baselines
danny-avila c1efd7a
fix: snapshot eager baselines before dispatch
danny-avila 3f5b0b5
fix: preserve mismatched eager inputs and abort prepare
danny-avila e2350fe
fix: retain delayed eager refreshes and cancellation
danny-avila a18f2a1
fix: preserve session refresh and retry state
danny-avila 00c78b1
fix: preserve completed work through reauthorization
danny-avila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Host-owned subagent context | ||
|
|
||
| `Run.create({ subagentContext })` lets a host authorize an individual child | ||
| execution, supply its initial messages, partition its tool sessions, and project | ||
| its successful result. The SDK exports `SUBAGENT_CONTEXT_VERSION = 1` so hosts | ||
| can reject an unsupported installation before enabling features that depend on | ||
| execution identity. | ||
|
|
||
| `prepare(input)` runs before the child graph is constructed or invoked. Its input | ||
| contains the SDK-owned `executionContext`, `parentThreadId`, `memberAgentIds`, an | ||
| abort `signal`, and a `resumed` marker. The last ancestry entry's `subagentRunId` | ||
| identifies this execution; saved agent IDs alone do not distinguish concurrent | ||
| copies of an agent. Nested children inherit the adapter and receive their full | ||
| ancestry. A graph subagent has one execution identity and multiple member IDs. | ||
|
|
||
| Preparation may return: | ||
|
|
||
| - `messages`: actual LangChain messages appended after the task description for | ||
| a fresh child. They may contain multimodal file content. Existing checkpoint | ||
| messages are preserved on resume without inserting these messages again. | ||
| - `configurable`: host runtime context. SDK run, thread, checkpoint, and execution | ||
| identities cannot be replaced through this object. | ||
| - `agentSessions`: entries keyed by child member ID, each replacing that member's | ||
| `codeSessionKey` and `initialSessions`. Omitting `initialSessions` in an entry | ||
| clears inherited session seeds. Unknown members are rejected. A paused live | ||
| graph cannot change its session partition when it resumes. | ||
|
|
||
| The SDK calls preparation again when a completed execution is retried and when a | ||
| host rebuilds a paused execution, allowing the host to reauthorize access. Make | ||
| authorization idempotent for the execution identity. An ordinary preparation | ||
| failure prevents child execution and produces a generic failure result. Aborting | ||
| the supplied signal instead propagates as an execution error, so callers must | ||
| handle it as cancellation rather than as a normal subagent result. | ||
|
|
||
| `complete(input, result)` runs after successful child work. It returns the text | ||
| delivered to the parent and can append durable file references. The SDK retains | ||
| the original completed result if delivery fails, so retrying delivery does not | ||
| repeat model or tool side effects. Completion must be idempotent. Failed and | ||
| cancelled child work does not invoke completion. | ||
|
|
||
| The same canonical `executionContext` reaches child tool hooks, | ||
| `ToolExecuteBatchRequest.executionContext`, and the `configurable.executionContext` | ||
| and `metadata.executionContext` of direct tool calls. Root tools have no child | ||
| context. Event-driven hosts should use the batch field as authority and overwrite | ||
| inherited configurable or metadata values before invoking tools and handling | ||
| their artifacts. | ||
|
|
||
| The adapter does not implement file authorization, storage, publication, or | ||
| sandbox isolation. In particular, `codeSessionKey` partitions the SDK's transient | ||
| session map; the host must also assign a private runtime workspace and prevent | ||
| inherited runtime hints or direct tool implementations from bypassing that | ||
| workspace. Published files and any private artifact recovery remain the host's | ||
| responsibility. The host must reconstruct its adapter and authorization when resuming. The SDK | ||
| does not replay private artifacts to the host when restoring a checkpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a child graph triggers summarization, its
PreCompactandPostCompactcalls insrc/summarization/node.tsstill construct hook inputs withoutexecutionContext(lines 920-929 and 1327-1339). Consequently, hosts relying on this newly exposed lineage cannot correlate or authorize compact lifecycle hooks for concurrent copies of the same saved agent, even though tool, preemption, and subagent start/stop hooks receive it. Thread the graph's subagent execution context through both compact hook inputs.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propagated the canonical child execution context through both PreCompact and PostCompact hooks in commit 1083640, with focused compaction-hook coverage.