Skip to content

fix(code): record shell output as user context#4353

Merged
Mason Daugherty (mdrxy) merged 1 commit into
mainfrom
mdrxy/code/user-shell-context
Jun 28, 2026
Merged

fix(code): record shell output as user context#4353
Mason Daugherty (mdrxy) merged 1 commit into
mainfrom
mdrxy/code/user-shell-context

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jun 28, 2026

Copy link
Copy Markdown
Member

Local ! commands are user-initiated environment context, not assistant-authored output. Before this change, dcode represented a non-incognito shell command as a synthetic HumanMessage/AIMessage pair:

Human: !git pull
AI: ```text
Already up to date.
```

That made shell output look like something the model said, which is misleading in traces and can confuse downstream history consumers. This switches the model-visible record to a single structured user-context message, matching the pattern used by tools like Codex for user-entered shell commands:

Human: <user_shell_command>
    <command>
        git pull
    </command>
    <result>
        Exit code: 0
        Output:
        Already up to date.
    </result>
</user_shell_command>

Agent-invoked shell tools can still use normal tool-call/tool-result semantics. This change is only for user-entered ! commands that run outside the agent graph and are later flushed into the thread state before the next user turn.

Changes

  • Change DeepAgentsApp._buffer_shell_for_model_context to append one structured HumanMessage per ! command instead of a HumanMessage command plus synthetic AIMessage output.
  • Include the command, exit status, and combined stdout/stderr in explicit XML-like sections so the model can distinguish user intent from environment output.
  • Record Exit code: unknown for interrupted/timeout paths where the subprocess has no return code.
  • Preserve the existing privacy and timing behavior: !! incognito commands and --startup-cmd output stay local-only, and non-incognito ! output is still deferred until the next user send.
  • Update shell-context tests for successful output, nonzero exits, empty output, interrupted commands, timeout/OSError paths, flush ordering, and retained buffers.

@github-actions github-actions Bot added dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: S 50-199 LOC labels Jun 28, 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: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

@mdrxy
Mason Daugherty (mdrxy) merged commit 0d504a5 into main Jun 28, 2026
89 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/code/user-shell-context branch June 28, 2026 21:00
Mason Daugherty (mdrxy) added a commit that referenced this pull request Jun 29, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Everything below this line will be the GitHub release body._

---


##
[0.1.28](deepagents-code==0.1.27...deepagents-code==0.1.28)
(2026-06-29)

### Features

* Add Fireworks session settings
([#4360](#4360))
([90ebb1d](90ebb1d))
* `RubricMiddleware` implementation (`/goal`/`--goal` and
`/rubric`/`--rubric`)
* Add rubric-backed goal workflow
([#4365](#4365))
([8fca61d](8fca61d))
* Non-interactive rubric grading flags
([#4305](#4305))
([1bcb112](1bcb112))
* Adopt coding-agent-v1 trace metadata
([#4367](#4367))
([cb39747](cb39747))
* Quit shortcut on completed update modal
([#4312](#4312))
([5e6eae9](5e6eae9))

### Bug Fixes

* Redact LangSmith trace secrets by default
([#4356](#4356))
([5e01fec](5e01fec))
* Honor Baseten base URL env precedence
([#4328](#4328))
([8f20d74](8f20d74))
* Highlight just-installed provider on `/auth` reopen
([#4311](#4311))
([85e47b5](85e47b5))
* Clear transient update launch status
([#4355](#4355))
([b870b18](b870b18))
* Clearer MCP config JSON parse errors
([#4327](#4327))
([9cee602](9cee602))
* Record shell output as user context
([#4353](#4353))
([0d504a5](0d504a5))
* Suppress expected MCP reauth logs
([#4359](#4359))
([15ee384](15ee384))

### Performance Improvements

* Background refresh for `@` file completion cache
([#3911](#3911))
([aa22d6b](aa22d6b))
* Speed up shutdown after `Ctrl+C`/`Ctrl+D`
([#4351](#4351))
([db441ed](db441ed))

---

_Everything above this line will be the GitHub release body._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant