Skip to content

fix(app-server): honor an agent profile's tools and custom prompt - #368

Closed
simonrosenberg wants to merge 3 commits into
mainfrom
enterprise-profile-tools-and-prompt
Closed

simonrosenberg wants to merge 3 commits into
mainfrom
enterprise-profile-tools-and-prompt

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

  • A human has tested these changes.

AGENT:


No SDK dependency. tools, system_message_suffix and mcp_server_refs all exist on the pinned openhands-sdk==1.46.0; this is purely a cloud-side fix and can merge on its own.

Why

An Agent Profile can specify a custom prompt, a tool allow-list and an MCP allow-list. On cloud, two of the three were silently discarded.

_build_start_conversation_request resolves the profile into agent_settings correctly — and then rebuilds the agent on top of it:

configured_agent_settings = user.agent_settings.model_copy(
    update={
        'tools': tools,                              # get_default_tools(...) — profile's list gone
        'agent_context': AgentContext(
            system_message_suffix=effective_suffix,  # fresh context — profile's prompt gone
            ...
        ),
    }
)

Demonstrated against the real resolver:

resolved agent_settings.tools : ['glob', 'grep']
resolved suffix               : Read-only explorer.

cloud overwrote tools with    : ['terminal', 'file_editor', 'task_tracker', 'browser_tool_set']
cloud rebuilt agent_context from the request-derived suffix only

So a profile scoped to glob+grep with a read-only prompt launched on cloud with terminal, file_editor and browser_tool_set, and none of its instructions. The editor showed a restriction that did not exist — the same class of problem as a control that persists but does not apply.

This was a known loose end: the software-agent-sdk#3978 checklist already listed "cloud drops the get_default_tools override".

Summary

  • Tools — the injection now supplies a default rather than overriding a deliberate choice: it runs only when user.agent_settings.tools is None. The gate is is None, not truthiness, because the field is tri-state and [] means a deliberately bare agent that truthiness would silently refill.
  • Agent context — extended via model_copy instead of replaced, so the profile's system_message_suffix, disabled_skills and load_project_skills all survive. _compose_system_message_suffix joins the profile's prompt (which states what the agent is for, so it leads) with the runtime additions (shallow-clone notice, web host, integration context).
  • MCP needed no change — _merge_custom_mcp_config already reads user.agent_settings.mcp_config, which is the ref-filtered map after resolution; its docstring says so deliberately. Verified rather than assumed.
  • The ACP path needed no change — it already extends its context via model_copy, and neither field applies to an ACP profile.

Issue Number

Part of OpenHands/OpenHands#17234 (the cloud half). Related: OpenHands/OpenHands#17235 (the editor), #364 (secrets, which needs its own SDK release).

How to Test

uv sync --frozen --group dev --group test
uv run pytest tests/unit -q                                    # 5813 passed
uv run pre-commit run --config ./dev_config/python/.pre-commit-config.yaml \
  --files openhands/app_server/app_conversation/live_status_app_conversation_service.py

Manually: create an Agent Profile with a custom prompt, a narrowed tool list and an MCP subset, launch a conversation with it, and confirm the agent has exactly those tools, that prompt, and only those MCP servers.

Video/Screenshots

The same three-field profile, verified end-to-end on a locally-built agent-server (OH_AGENT_SERVER_LOCAL_PATH) — this is the path this PR brings cloud into line with:

$ POST /api/agent-profiles/code-exploration
    tools: [glob, grep] · suffix: "read-only code explorer" · mcp_server_refs: [github]
    (two MCP servers configured globally: github, postgres)

$ POST /api/agent-profiles/code-exploration/materialize
    valid: True   tools: ['glob', 'grep']
    system_message_sfx: You are a read-only code explorer. Never modify files.
    resolved MCP keys : ['github']      dangling: []

$ POST /api/conversations  {agent_profile_id: ...}
    LAUNCHED AGENT
      tools        : ['glob', 'grep']          # no terminal, no file_editor
      mcp_config   : ['github']                # postgres filtered out
      system suffix: You are a read-only code explorer. Never modify files.

Authored through the Agent Canvas UI rather than by hand, then read back:

tools             : ['glob', 'grep']
system_message_sfx: You are a read-only code explorer. Never modify files.
mcp_server_refs   : ['github']

Cloud itself is not covered by that run — it needs a full SaaS stack (postgres, auth). The cloud-side change is covered by unit tests over the two pure pieces (_compose_system_message_suffix, the tri-state tool gate) plus the full suite; a real cloud launch is the remaining verification.

Unit suite: 5813 passed, 1 unrelated pre-existing macOS failure (test_process_sandbox_service.py::test_default_values, /tmp vs /var/folders TMPDIR — identical on main). pre-commit clean, mypy included.

Type

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

Notes

  • Replicated is covered by the same fix. saas_server.py sets OPENHANDS_CONFIG_CLS=server.config.SaaSServerConfig, so replicated runs SaasSettingsStore and this same builder — not the FileSettingsStore, which has no Agent Profile concept at all (load() discards the resolve flags).
  • disabled_skills is fixed as a side effect of extending the context instead of replacing it. It was being dropped for the same reason as the suffix.
  • Suffix ordering is a judgement call: profile prompt first, runtime context after. For AgentType.PLAN the planning instruction is already prepended to the runtime half, so a planning profile reads <profile>\n\n<planning>\n\n<runtime>. Worth a look if that ordering matters to you.

🤖 Generated with Claude Code


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-66ce0b8

Cloud resolves an Agent Profile into agent_settings, then rebuilt the agent on
top of it — overwriting `tools` with get_default_tools() and constructing a
fresh AgentContext from the request-derived suffix. Both of the profile's own
values were discarded, so a profile scoped to glob+grep with a read-only prompt
launched with terminal, file_editor and browser and none of its instructions.

The tool injection now supplies a default rather than overriding a deliberate
choice: it runs only when `tools` is None. The gate is `is None`, not
truthiness, because the field is tri-state and [] means a deliberately bare
agent.

The agent context is extended rather than replaced, so the profile's
system_message_suffix, disabled_skills and load_project_skills all survive. The
profile's prompt leads and the runtime additions (shallow clone, web host,
integration context) follow.

mcp_server_refs already worked — _merge_custom_mcp_config reads the resolved,
ref-filtered mcp_config — and the ACP path already extends its context rather
than replacing it, so neither needed changing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the type: fix A bug fix label Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  live_status_app_conversation_service.py 2300, 2315, 2340
Project Total  

This report was generated by python-coverage-comment-action

…ols-and-prompt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonrosenberg

Copy link
Copy Markdown
Member Author

Refreshed onto main without rewriting history. The focused live-status conversation-builder suite passed all 229 tests on the current PostgreSQL test harness; pre-commit (including mypy) passed. This preserves the useful, bounded context/tools fix separately from #453's larger SDK/tool migration.

Keeping draft until the remaining runtime validation is complete. #453's rollout/migration blockers are now tracked in #758, and the broader fail-open profile-resolution problem is #759. Passing the builder suite does not establish a complete Cloud deployment or solve those separate issues.

@simonrosenberg

Copy link
Copy Markdown
Member Author

Superseded by #763, which consolidates profile tool and context preservation with the other Enterprise Agent Profile fixes. The replacement uses released SDK 1.54.0, adds strict launch resolution and revision 187 after the current migration head, and includes an upgrade/audit guide.

#763 has passing CI, 7,577 passing local backend tests, real HTTP/model QA, and an independent automated QA PASS. Closing this duplicate PR so review and follow-up happen in one place; the linked issues remain tracked until #763 merges.

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.

1 participant