Skip to content

fix(sdk): rework state constructor in forking - #5981

Open
Hunter Lovell (hntrl) wants to merge 8 commits into
bengret/feat-subagent-forkingfrom
hunter/subagent-state-prop
Open

fix(sdk): rework state constructor in forking#5981
Hunter Lovell (hntrl) wants to merge 8 commits into
bengret/feat-subagent-forkingfrom
hunter/subagent-state-prop

Conversation

@hntrl

Copy link
Copy Markdown
Member
  • instead of forking via attributing messages through middleware state, we instead rework how subagent state gets propagated in task.invoke for forked subagents
  • also does some type guard cleanups, and moves summarization back to where it was to minimize diff to main in the stacked PR
  • also some slight drive by prompt hardening

alt implementation for fix addressed in 7b2302b

@github-actions github-actions Bot added deepagents Related to the `deepagents` SDK / agent harness fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: M 200-499 LOC labels Aug 29, 2026

@open-swe open-swe Bot 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.

Open SWE Review found 3 potential issues.

Open in WebView Open SWE trace

Comment on lines +722 to +724
subagent_state = {
**runtime.state,
_FORKED_CONTEXT_KEY: True,

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.

🟠 Forks leak parent-private state fields

Spreading all of runtime.state here bypasses private_state_keys, even though those keys are computed from the parent middleware/state schemas specifically to prevent private channels from reaching subagents. A parent middleware can store credentials or other internal data in a PrivateStateAttr; invoking any mode="fork" subagent now places that value in the child state (including a user-supplied compiled runnable), whereas isolated subagents still filter it. Build the fork snapshot while excluding private_state_keys (but retain the summarization fields that are intentionally needed via an explicit allowlist).

(Refers to lines 722-724)


Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.

Comment thread libs/deepagents/deepagents/middleware/subagents.py Outdated
Comment thread libs/deepagents/deepagents/middleware/subagents.py Outdated
@github-actions github-actions Bot added size: L 500-999 LOC and removed size: M 200-499 LOC labels Aug 29, 2026

@open-swe open-swe Bot 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.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment thread libs/deepagents/deepagents/graph.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepagents Related to the `deepagents` SDK / agent harness fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: L 500-999 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants