Skip to content

Fix ACPAgent dropping image content from user messages - #3027

Merged
xingyaoww merged 13 commits into
OpenHands:mainfrom
sjathin:sdk-2982
May 3, 2026
Merged

xingyaoww merged 13 commits into
OpenHands:mainfrom
sjathin:sdk-2982

Conversation

@sjathin

@sjathin sjathin commented May 1, 2026 •

Copy link
Copy Markdown
Contributor
  • A human has tested these changes.

Why

ACPAgent._build_acp_prompt() only extracts TextContent from user messages and silently drops ImageContent blocks. The ACP prompt() method supports ImageContentBlock but it was never wired up.

Summary

  • Changed _build_acp_prompt() to return list[TextContentBlock | ImageContentBlock] instead of str, preserving image content as ACP ImageContentBlock
  • Added _image_url_to_acp_block() helper to convert data URIs and plain URLs to ACP image blocks
  • Updated step() to pass content blocks directly to conn.prompt() instead of wrapping in a single text_block()

Issue Number

Closes #2982

How to Test

uv run python -m pytest tests/sdk/agent/test_acp_agent.py -v -k "not test_static_secret"

168 tests pass. New tests cover:

  • test_build_acp_prompt_includes_image_content — mixed text + image message
  • TestImageUrlToAcpBlock — data URI parsing, plain URL passthrough, invalid URI handling

Manually verified with a real PNG image that base64 data round-trips correctly through the conversion.

Video/Screenshots

N/A — backend logic change.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

The _image_url_to_acp_block helper handles two URL formats:

  • Data URIs (data:image/png;base64,...): parsed into data + mime_type fields
  • Plain URLs (https://...): passed via the uri field with a generic MIME type for the ACP server to resolve

Jathin Sreenivas added 2 commits May 1, 2026 02:34
_build_acp_prompt now returns a list of ACP content blocks (text + image)
instead of a single joined string. ImageContent URLs (data URIs and plain
URLs) are converted to ACP ImageContentBlock via the new
_image_url_to_acp_block helper. step() passes the blocks directly to
conn.prompt().

Closes OpenHands#2982

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taste Rating: 🟢 Good taste - Clean implementation that eliminates the special case of dropped image content.

[EVAL CONSIDERATION]
This PR fixes a bug where image content was silently dropped, but it could affect agent behavior in multimodal scenarios. While the fix is correct, I recommend running lightweight evals before merging to ensure no unexpected performance impacts in benchmarks that use image inputs.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW

This is a correctness fix for existing ACP functionality. The change is well-isolated to ACPAgent, has good test coverage, and includes proper error handling for malformed data URIs. The risk is low because it's fixing missing functionality rather than changing existing behavior.

VERDICT:
✅ Worth merging after eval check: Implementation is solid, tests are comprehensive, and this fixes a real bug where images were being silently dropped.

KEY INSIGHT:
The change from str to list[ContentBlock] eliminates a special case by preserving all content types, which is a cleaner architecture than text-only extraction.

@xingyaoww
xingyaoww requested a review from simonrosenberg May 3, 2026 02:23
@xingyaoww

Copy link
Copy Markdown
Contributor

@OpenHands do we have existing example tests for ACP agent? If so, can we modify that example test to add an image as input so we can thoroughly test the ACP system to make sure that it can actually handle image inputs?

@openhands-ai

openhands-ai Bot commented May 3, 2026

Copy link
Copy Markdown

I'm on it! xingyaoww can track my progress at all-hands.dev

Adds a second conversation turn that sends a Message with TextContent +
ImageContent (using the OpenHands logo URL) so the example test exercises
the new multimodal image support end-to-end through the ACP pipeline.

Co-authored-by: openhands <openhands@all-hands.dev>

Copy link
Copy Markdown
Contributor

Yes, there is an existing example test at examples/01_standalone_sdk/40_acp_agent_example.py. I've added an image input turn to it in commit a8f28ea — it now sends a Message with TextContent + ImageContent (using the OpenHands logo URL) as a second conversation turn, which exercises the new multimodal image support end-to-end through the ACP pipeline.

The example now covers:

  1. Text-only turn — the original file listing task
  2. Image + text turn — sends an image URL with a description prompt via ImageContent
  3. ask_agent — the existing fork_session side-question

This will be validated when the example test suite runs (--run-examples).

This comment was generated by an AI agent (OpenHands).

@openhands-ai

openhands-ai Bot commented May 3, 2026

Copy link
Copy Markdown

Summary

The reviewer asked whether there are existing example tests for the ACP agent and requested adding an image input to that example to end-to-end test the new image support.

What was done

I modified the existing ACP agent example (examples/01_standalone_sdk/40_acp_agent_example.py) to add an image input turn, pushed the commit to the PR branch, and replied to the reviewer's comment on the PR.

Checklist

  • Identified existing ACP example test — examples/01_standalone_sdk/40_acp_agent_example.py exists and is discoverable by the example test runner
  • Added image input turn — New conversation turn sends a Message with TextContent + ImageContent using the OpenHands logo URL (same image used in 17_image_input.py)
  • Exercises the PR's changes end-to-end — The image URL goes through _build_acp_prompt() → _image_url_to_acp_block() → conn.prompt(), validating the full ACP image pipeline
  • All 169 existing unit tests pass — Verified with pytest tests/sdk/agent/test_acp_agent.py
  • Pre-commit checks pass — Linting, formatting, type checking all clean
  • Pushed to PR branch — Commit a8f28eab pushed to sjathin/software-agent-sdk:sdk-2982
  • Replied to reviewer — Left a comment on PR Fix ACPAgent dropping image content from user messages #3027 explaining the changes

Conciseness

The changes are minimal and focused — only one file was modified (40_acp_agent_example.py) with:

  • 3 new imports (ImageContent, Message, TextContent)
  • 1 constant (IMAGE_URL)
  • ~12 lines for the new image input turn
  • Minor docstring update

No extraneous changes were made.

@xingyaoww xingyaoww added the test-examples Run all applicable "examples/" files. Expensive operation. label May 3, 2026
@xingyaoww

Copy link
Copy Markdown
Contributor

@OpenHands help me check https://github.com/OpenHands/software-agent-sdk/actions/runs/25280845180/job/74119105118 and fix this issue and get it running

@openhands-ai

openhands-ai Bot commented May 3, 2026

Copy link
Copy Markdown

I'm on it! xingyaoww can track my progress at all-hands.dev

The wait-on-check-action and checkout steps used
github.event.pull_request.head.ref (branch name) which doesn't resolve
in the upstream repo for fork PRs. Changed to head.sha which always
resolves correctly since GitHub makes fork PR commit SHAs accessible.

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww removed the test-examples Run all applicable "examples/" files. Expensive operation. label May 3, 2026
@xingyaoww xingyaoww added the test-examples Run all applicable "examples/" files. Expensive operation. label May 3, 2026 — with OpenHands AI

Copy link
Copy Markdown
Contributor

Checked the failing CI run. The failure was in the wait-on-check-action step:

GET .../commits/sdk-2982/check-runs: 422 - No commit found for SHA: sdk-2982

Root cause: The run-examples.yml workflow used github.event.pull_request.head.ref (branch name sdk-2982) as the ref for both the wait-on-check-action and actions/checkout. For fork PRs, the branch name doesn't exist in the upstream repo, so the GitHub API returns 422.

Fix: Changed both refs from head.ref to head.sha, which always resolves correctly since GitHub makes fork PR commit SHAs accessible in the upstream repo context.

Re-triggered the workflow — new run: https://github.com/OpenHands/software-agent-sdk/actions/runs/25281495046

This comment was created by an AI agent (OpenHands).

@openhands-ai

openhands-ai Bot commented May 3, 2026

Copy link
Copy Markdown

Summary of Work

What was done

The user asked me to check the failing CI run on PR #3027 and fix the issue.

Root Cause

The run-examples.yml workflow used github.event.pull_request.head.ref (branch name sdk-2982) as the ref for both lewagon/wait-on-check-action and actions/checkout. Since this PR comes from a fork (sjathin/software-agent-sdk), the branch name doesn't exist in the upstream repo, causing the GitHub API to return 422 - No commit found for SHA: sdk-2982.

Fix Applied

Changed two ref values in .github/workflows/run-examples.yml from head.ref to head.sha. The commit SHA always resolves correctly for fork PRs.

Checklist

  • Checked the failing CI run — identified the error in the wait-on-check-action step
  • Fixed the issue — committed cbfdecf8 changing head.ref → head.sha in both the wait-on-check and checkout steps
  • Pushed to the PR branch — pushed to sdk-2982 on the fork
  • Re-triggered the workflow — removed and re-added the test-examples label to start a new run
  • Posted a PR comment explaining the fix

Conciseness

The change is minimal — only 2 lines changed in 1 file (.github/workflows/run-examples.yml), directly addressing the root cause. No extraneous changes were made.

Note

The new workflow run has been triggered but may still take time to complete. The fix addresses the CI infrastructure issue (ref resolution for fork PRs); the actual example tests themselves still need to run and pass.

The Build & Push job in server.yml is explicitly skipped for fork PRs
(forks cannot push to GHCR). The wait-on-check step was waiting for a
check that would never exist, causing the workflow to always fail on
fork PRs.

Added the same fork check condition to the wait step, mirroring
server.yml's build-and-push-image condition.

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww removed the test-examples Run all applicable "examples/" files. Expensive operation. label May 3, 2026
@xingyaoww xingyaoww added the test-examples Run all applicable "examples/" files. Expensive operation. label May 3, 2026 — with OpenHands AI

Copy link
Copy Markdown
Contributor

The second fix addresses the actual root cause: the Build & Push (python-amd64) job in server.yml is explicitly skipped for fork PRs (forks can't push to GHCR). The wait-on-check step was waiting for a check that would never exist.

Added the same !github.event.pull_request.head.repo.fork condition to the wait step. The new run is now past the blocker and progressing: https://github.com/OpenHands/software-agent-sdk/actions/runs/25281605787

This comment was created by an AI agent (OpenHands).

Revert the fork-specific run-examples workflow changes and include the local stdout proving the ACP image example can see the image.

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww

Copy link
Copy Markdown
Contributor

Updated in 7e71d62.

What changed:

  • Reverted the previous fork-CI attempts in .github/workflows/run-examples.yml; the final PR diff no longer changes that workflow.
  • Added .pr/acp_agent_example_stdout.txt with the local stdout from the ACP example run.

Local verification:

  • make build
  • uv run pre-commit run --files .github/workflows/run-examples.yml .pr/acp_agent_example_stdout.txt
  • ANTHROPIC_API_KEY=... ANTHROPIC_BASE_URL=... npm_config_cache="/Users/XingyaoWang/Projects/OpenHands/software-agent-sdk/.agent_tmp/npm-cache" uv run pytest 'tests/examples/test_examples.py::test_example_scripts[examples/01_standalone_sdk/40_acp_agent_example.py]' --run-examples --examples-results-dir .agent_tmp/example-test-results -vv -> 1 passed in 32.55s

The stdout artifact includes the image turn marker [Image: 1 URLs] and the model response: Two yellow cartoon hands raised with palms forward and small motion lines above, depicting a celebratory "raising hands" emoji.

The local npm_config_cache override was only to avoid a machine-level npm cache permission issue while running npx; it is not a repo change.

@xingyaoww

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR contains a .pr/ directory with PR-specific documents. This directory will be automatically removed when the PR is approved.

For fork PRs: Manual removal is required before merging.

@xingyaoww xingyaoww 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.

Thank you!

xingyaoww and others added 2 commits May 3, 2026 11:13
Add a trusted workflow_run cleanup path for approved fork PRs, update the PR artifact notices, and remove the temporary .pr artifact from PR OpenHands#3027.

Co-authored-by: openhands <openhands@all-hands.dev>
Remove the trusted fork cleanup workflow and restore the manual cleanup guidance for fork PRs to avoid using the OpenHands PAT against fork branches.

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww
xingyaoww enabled auto-merge (squash) May 3, 2026 17:59
@xingyaoww
xingyaoww merged commit 060ded3 into OpenHands:main May 3, 2026
26 checks passed
@sjathin
sjathin deleted the sdk-2982 branch May 3, 2026 18:30
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Co-authored-by: Jathin Sreenivas <sjathin@amazon.com>
Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Xingyao Wang <xingyaoww@gmail.com>
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
Co-authored-by: Jathin Sreenivas <sjathin@amazon.com>
Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Xingyao Wang <xingyaoww@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test-examples Run all applicable "examples/" files. Expensive operation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACPAgent drops image content from user messages

4 participants