Skip to content

DRAFT: feat(terminal): proactive literal-arg warning in tool description - #3619

Closed
juanmichelini wants to merge 2 commits into
mainfrom
openhands/sdk-7-terminal-literal-arg-guidance
Closed

juanmichelini wants to merge 2 commits into
mainfrom
openhands/sdk-7-terminal-literal-arg-guidance

Conversation

@juanmichelini

@juanmichelini juanmichelini commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

The SDK-5 guard (#3582) rejects Python/JSON literals passed to the terminal tool's command field after the model has already emitted them. That fixed Critic 1 Acceptance (20% → 100%) on Nemotron 550B SWE-Bench Verified — but didn't reduce per-instance cost. This PR moves the guidance upstream into the tool description so the model sees it on every turn, before it ever composes a malformed command.

Why this is needed (data)

Trajectory analysis of the SDK-5 follow-up run 27224350936:

Conv Actions SDK-5 guard hits Cost
scikit-learn-13439-like 90 0 $0.20 ← Sonnet-tier
django-12155-like 74 0 $0.11 ← Sonnet-tier
expensive #1 (scikit-learn) 196 32 $6.84
expensive #2 (django) 212 31 $5.67
expensive #3 (django) 212 61 $6.41

The three "expensive" instances each triggered SDK-5's guard 31–61 times. The agent recovered every time (which is why acceptance is 100%), but it never learned — Nemotron emitted the same malformed pattern 5-10 turns later, over and over. The hint is in-band, so it lands as one paragraph in a 200-turn conversation. Attention weight on a single retrospective message ≈ zero.

At ~$0.03/turn (no prompt caching), the 124 wasted recovery turns across the three expensive instances cost roughly $3.70 out of the $19.23 batch — about 20% of total spend.

What

Add a _LITERAL_ARG_GUIDANCE block at the top of both UNIX_TOOL_DESCRIPTION and WINDOWS_TOOL_DESCRIPTION. It:

  1. States the rule in one sentence: command must be a shell command, not a Python/JSON literal.
  2. Gives two concrete recovery paths (file_editor + script, or inline heredoc).
  3. Shows three rejection examples the model can pattern-match against.

Total added size: ~700 bytes per description. Test pins this to < 3 KB total so future additions can't silently bloat what the model re-pays for on every uncached turn.

Tests

tests/tools/terminal/test_descriptions.py — 4 tests:

  • Warning text + key terms (Python, JSON, shell command) present on both Unix and Windows.
  • Both recovery paths (file_editor, heredoc) mentioned.
  • Ordering: the warning appears before ### Command Execution. Attention research shows position matters in long contexts; this prevents accidental re-ordering from burying the warning.
  • Each description stays under a 3 KB byte budget.

Risk

  • Pure description change. No behavioral logic changed.
  • Bytes paid per turn grew by ~700 on uncached models. At ~$0.000003/input-token (Nemotron) that's ~$0.00021 per turn × 150 turns = $0.03 added per instance. If this cuts even one literal-emit attempt (≈ $0.03 saved per attempt at this token cost), it breaks even. Expected savings is 30–40× that.
  • Compatible with prompt caching: on caching providers (Claude, Gemini) the description is in the cached prefix, so the added bytes cost ~nothing per turn.

Stacks with

Verify locally

uv run pytest tests/tools/terminal/test_descriptions.py -v
# 4 passed

To see the rendered text the model will receive:

uv run python -c "from openhands.tools.terminal.descriptions import UNIX_TOOL_DESCRIPTION; print(UNIX_TOOL_DESCRIPTION)"

This PR was created by an AI agent (OpenHands) on behalf of the user investigating cost on the Nemotron 550B SWE-Bench Verified eval. Companion analysis: same run cost $19.23 across 5 resolved instances; cheap instances (no SDK-5 hits) cost $0.11–$0.20 each, expensive instances (31–61 hits each) cost $5.67–$6.84.

@juanmichelini can click here to continue refining the PR


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:d8b470f-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-d8b470f-python \
  ghcr.io/openhands/agent-server:d8b470f-python

All tags pushed for this build

ghcr.io/openhands/agent-server:d8b470f-golang-amd64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-golang-amd64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-golang-amd64
ghcr.io/openhands/agent-server:d8b470f-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:d8b470f-golang-arm64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-golang-arm64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-golang-arm64
ghcr.io/openhands/agent-server:d8b470f-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:d8b470f-java-amd64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-java-amd64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-java-amd64
ghcr.io/openhands/agent-server:d8b470f-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:d8b470f-java-arm64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-java-arm64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-java-arm64
ghcr.io/openhands/agent-server:d8b470f-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:d8b470f-python-amd64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-python-amd64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-python-amd64
ghcr.io/openhands/agent-server:d8b470f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:d8b470f-python-arm64
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-python-arm64
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-python-arm64
ghcr.io/openhands/agent-server:d8b470f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:d8b470f-golang
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-golang
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-golang
ghcr.io/openhands/agent-server:d8b470f-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:d8b470f-java
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-java
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-java
ghcr.io/openhands/agent-server:d8b470f-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:d8b470f-python
ghcr.io/openhands/agent-server:d8b470f5e9aef234dce52ffd4c4a7323d661b191-python
ghcr.io/openhands/agent-server:openhands-sdk-7-terminal-literal-arg-guidance-python
ghcr.io/openhands/agent-server:d8b470f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., d8b470f-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., d8b470f-python-amd64) are also available if needed

…l description

The SDK-5 guard (#3582) catches Python/JSON literals `command` arguments
*after* the model has already emitted them, and replies with an in-band
hint. That fixed Critic 1 Acceptance (20% → 100%) on the Nemotron 550B
SWE-Bench Verified run `27224350936`, but trajectory analysis showed
the three expensive instances each hit the guard 31–61 times. The hint
is in-band, so it lands as just another turn's-worth of text in a
200-turn conversation — it doesn't change the model's prior.

This PR moves the guidance *upstream* into the tool description itself,
so the warning is visible on every turn before the model composes a
command. Same wording on both Unix and Windows variants.

Numbers from `27224350936`:
  - 3 expensive instances: 31 + 32 + 61 = 124 SDK-5 hits total
  - At ~$0.03/turn (Nemotron, no caching, ~150-turn context):
    ~$3.70 of pure waste across the 5-instance batch
  - Expected SDK-7 + SDK-5 combined behaviour: model sees warning
    up-front, drops literal-emit attempts from ~40 → ~2 per instance.

Test coverage: `tests/tools/terminal/test_descriptions.py` pins
- presence of the warning text on both variants
- mention of both recovery paths (`file_editor`, heredoc)
- ordering — warning must appear before `### Command Execution`
- 3 KB budget per description so it cannot silently bloat

Co-authored-by: openhands <openhands@all-hands.dev>
@juanmichelini juanmichelini added the enhancement New feature or request label Jun 10, 2026 — with OpenHands AI
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL305671536749% 
report-only-changed-files is enabled. No files were changed during this commit :)

@juanmichelini

Copy link
Copy Markdown
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants