Skip to content

fix: support ACP agent_kind in preset automation scripts#224

Open
Hades32 wants to merge 5 commits into
OpenHands:mainfrom
Hades32:fix-acp-agent
Open

fix: support ACP agent_kind in preset automation scripts#224
Hades32 wants to merge 5 commits into
OpenHands:mainfrom
Hades32:fix-acp-agent

Conversation

@Hades32

@Hades32 Hades32 commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Preset-based automations (prompt and plugin) failed immediately when the agent server was configured with an ACP agent (agent_kind: "acp"), because the generated sdk_main.py unconditionally called get_default_agent(llm=llm, cli_mode=True). That constructs a standard Agent and routes LLM calls through LiteLLM using llm.model — but in ACP mode the persisted llm.model is the sentinel string "acp" (cost attribution only, not a real LiteLLM model), so the run crashed with:

LLMBadRequestError: litellm.BadRequestError: LLM Provider NOT provided.
Pass in the LLM provider you are trying to call. You passed model=acp

Fixes #164.

Changes

  • openhands/automation/presets/prompt/sdk_main.py
  • openhands/automation/presets/plugin/sdk_main.py

In both preset templates, replaced the hardcoded get_default_agent() call with agent-kind detection:

  1. Fetch agent settings via workspace._fetch_agent_settings() — the same SDK helper that get_llm() and get_mcp_config() already use internally.
  2. If the settings are ACPAgentSettings → call settings.create_agent(), which returns an ACPAgent that delegates to a subprocess ACP server (no LiteLLM routing of the sentinel model).
  3. Otherwise (openhands / legacy llm) → keep the existing get_default_agent(llm=llm, cli_mode=True) path, preserving current behavior.

The MCP config / agent_context overlay via model_copy is preserved. For ACP, get_mcp_config() returns {} (the mcp_config field only exists on OpenHandsAgentSettings), so the ACP agent's own mcp_config from create_agent() is not clobbered.

Testing

  • Added assertions to test_generate_tarball_main_py_content and test_generate_plugin_tarball_main_py_content verifying the ACP detection code (ACPAgentSettings, _fetch_agent_settings, create_agent()) is present in the generated main.py.
  • All 84 tests in tests/test_preset_router.py pass.
  • Verified both preset files parse as valid Python (compile() / ast.parse).

Hades32 and others added 4 commits June 29, 2026 11:41
Consolidate the inline agent-kind branching in prompt and plugin preset
scripts into a shared `_resolve_agent()` helper. This avoids duplicating
the ACP-vs-openhands logic and keeps the main flow readable.

- Move `ACPAgentSettings` import to the top-level SDK block for fail-fast
  behavior inside the sandbox.
- Move `get_llm()` into the helper so it is only fetched for the openhands
  path, eliminating dead work for ACP runs.
- Remove verbose inline comments that described the bug; the remaining
  one-liner is sufficient.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Extract `resolve_agent` into a shared `common.py` module that is bundled
into both prompt and plugin preset tarballs. Both `sdk_main.py` files now
import from it instead of duplicating the helper.

- Remove all print statements from the shared helper; callers retain their
  own section headers.
- Remove issue references from comments.
- Update tarball generators and tests to include and verify `common.py`.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Keep the fix small by inlining the helper in both preset scripts rather
than introducing a shared module. No issue references or tombstones in
comments. The helper is silent (no prints) and defers get_llm() to the
openhands path only.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the type: fix A bug fix label Jun 30, 2026
@Hades32

Hades32 commented Jul 5, 2026

Copy link
Copy Markdown
Author

cc @malhotra5

@Hades32

Hades32 commented Jul 12, 2026

Copy link
Copy Markdown
Author

or maybe @hieptl

@Hades32

Hades32 commented Jul 19, 2026

Copy link
Copy Markdown
Author

@hieptl this is blocking me using automations with a pure ACP-based setup

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

Labels

type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automation preset scripts fail when agent server is configured with ACP agent (agent_kind: "acp")

1 participant