Skip to content

feat(agent-profiles): let a profile replace the agent's persona - #5449

Merged
simonrosenberg merged 5 commits into
mainfrom
agent-profile-persona
Oct 2, 2026
Merged

simonrosenberg merged 5 commits into
mainfrom
agent-profile-persona

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Alternative to #5438: a profile replaces only the agent's persona, so a planning, read-only or non-coding agent keeps the security, risk-assessment, memory, browser and terminal guidance it still needs. I had the agent verify it against a live agent-server and the mock LLM. The persona profile's prompt keeps every capability section and drops only the persona and coding-workflow ones.


AGENT:

Alternative to #5438. Pick one. #5438 lets a profile replace the whole static system prompt. This one replaces only the persona, so a planning, read-only or non-coding agent keeps the guidance its capabilities need.

Why

#5438's system_prompt replaces the entire static block. That removes guidance a task-tuned agent still depends on:

  • the security policy and the risk-assessment definitions that "confirm risky actions" relies on;
  • browser and terminal rules;
  • the memory instructions, including the memory path, which depends on the deployment;
  • model-specific fixes.

A profile author rarely wants those gone. What they want to change is who the agent is and how it works. This adds a persona that replaces exactly that part.

Summary

  • persona: str | None on Agent, OpenHandsAgentSettings and OpenHandsAgentProfile (1–65,536 chars). The resolver, create_agent() and the seed carry it through.
  • What it replaces in the default preset: SOUL, ROLE, EFFICIENCY, FILE_SYSTEM_GUIDELINES, CODE_QUALITY, VERSION_CONTROL, PULL_REQUESTS, PROBLEM_SOLVING_WORKFLOW, SELF_DOCUMENTATION, ENVIRONMENT_SETUP, TROUBLESHOOTING. The persona text takes their place at the top.
  • What stays: MEMORY, SECURITY, SECURITY_RISK_ASSESSMENT, BROWSER_TOOLS (when the browser is loaded), EXTERNAL_SERVICES, PROCESS_MANAGEMENT, model-specific IMPORTANT, and the whole dynamic block (repository context, skills, system_message_suffix, secrets, datetime).
  • How: the preset marks persona-layer sections with a small wrapper that drops them when ctx.persona is set. A new PersonaSection renders the text. No section body changed, and with no persona the section list and order are identical, which test_prompt_snapshot.py pins byte for byte.
  • Interactions:
    • Planning preset: the persona is prepended and the planning section stays. Cloud PLAN mode therefore keeps working with a persona, with no "Cannot set both" conflict, since the planning template is still a preset.
    • Inline system_prompt: still wins and replaces everything, as today, including cloud's per-request field.
    • Custom Jinja template: receives {{ persona }}.
  • The agent-server advertises profile_persona_v1; ACP profiles reject the field (the ACP CLI owns its prompt). The ts-client type is updated.

REST API contract changes

Compared with base OpenAPI 41443fc14a8a for public /api/** paths.

--- base public OpenAPI
+++ head public OpenAPI
@@ -933,0 +934 @@
+schema Agent-Input property persona optional schema=anyOf=[type="string",type="null"]
@@ -948,0 +950 @@
+schema Agent-Output property persona optional schema=anyOf=[type="string",type="null"]
@@ -2360,0 +2363 @@
+schema OpenHandsAgentProfile property persona optional schema=anyOf=[type="string" minLength=1 maxLength=65536,type="null"]

Issue Number

Alternative implementation for #4956

How to Test

Live, against a real agent-server from this branch and Agent Canvas's recording mock LLM (output in .pr/e2e_results.md):

.venv/bin/python .pr/persona_e2e.py --mock <agent-canvas>/tests/e2e/mock-llm/scripts/mock-llm-server.py

[explorer] block 1 starts with persona: True
  kept ['<MEMORY>', '<SECURITY>', '<SECURITY_RISK_ASSESSMENT>', '<EXTERNAL_SERVICES>', '<PROCESS_MANAGEMENT>']: [True, True, True, True, True]
  replaced ['<SOUL>', '<ROLE>', '<CODE_QUALITY>', '<VERSION_CONTROL>', '<PULL_REQUESTS>'] present: [False, False, False, False, False]
  browser guidance present: True   suffix present: True
[plain]    built-in persona sections present: [True, True, True, True, True]

Unit suites:

uv run pytest tests/sdk/profiles tests/sdk/test_settings.py tests/sdk/test_apply_agent_settings_diff.py tests/sdk/context tests/sdk/agent/test_system_prompt.py   # 788 passed
uv run pytest tests/agent_server/test_agent_profile_conv_start.py tests/agent_server/test_server_details_router.py \
  tests/agent_server/test_agent_profiles_router.py tests/agent_server/test_conversation_service.py                          # 248 passed
uv run python .github/scripts/check_persisted_settings_compat.py   # 8 baseline payloads from 1.50.1 validate
PYTHONPATH=. make test-server-schema                               # passed

tests/sdk/context/prompts/test_persona.py pins:

  • which sections are replaced and which stay;
  • that the dynamic block is unchanged;
  • planning-preset composition;
  • that inline system_prompt wins;
  • that a custom template receives the kwarg.

Negative control: with the wrapper's persona check and the resolver line removed, the three tests that prove replacement (prompt, resolver, agent-server launch) fail.

Video/Screenshots

N/A (no UI in this repo). The live evidence is above. The Canvas editor change would switch #17843's "Custom prompt" mode to write persona.

Type

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

Notes

Compared with #5438:

#5438 system_prompt this PR persona
Replaces the whole static block persona and coding-workflow sections only
Security policy and risk definitions dropped kept
Browser and terminal rules, memory path dropped kept
Cloud PLAN mode with a profile needs OpenHands/enterprise#614 works as is (preset composition)
Non-coding agent ("cooking ramen") full control, no OpenHands framing own persona plus OpenHands operating rules

🤖 Generated with Claude Code


🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• 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-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime 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:358e0e1-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:358e0e1-golang-amd64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-golang-amd64
ghcr.io/openhands/agent-server:agent-profile-persona-golang-amd64
ghcr.io/openhands/agent-server:358e0e1-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:358e0e1-golang-arm64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-golang-arm64
ghcr.io/openhands/agent-server:agent-profile-persona-golang-arm64
ghcr.io/openhands/agent-server:358e0e1-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:358e0e1-java-amd64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-java-amd64
ghcr.io/openhands/agent-server:agent-profile-persona-java-amd64
ghcr.io/openhands/agent-server:358e0e1-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:358e0e1-java-arm64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-java-arm64
ghcr.io/openhands/agent-server:agent-profile-persona-java-arm64
ghcr.io/openhands/agent-server:358e0e1-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:358e0e1-python-amd64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-amd64
ghcr.io/openhands/agent-server:agent-profile-persona-python-amd64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-amd64
ghcr.io/openhands/agent-server:358e0e1-python-arm64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-arm64
ghcr.io/openhands/agent-server:agent-profile-persona-python-arm64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-arm64
ghcr.io/openhands/agent-server:358e0e1-python-minimal-amd64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-minimal-amd64
ghcr.io/openhands/agent-server:agent-profile-persona-python-minimal-amd64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:358e0e1-python-minimal-arm64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-minimal-arm64
ghcr.io/openhands/agent-server:agent-profile-persona-python-minimal-arm64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:358e0e1-python-slim-amd64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-slim-amd64
ghcr.io/openhands/agent-server:agent-profile-persona-python-slim-amd64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:358e0e1-python-slim-arm64
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-slim-arm64
ghcr.io/openhands/agent-server:agent-profile-persona-python-slim-arm64
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:358e0e1-golang
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-golang
ghcr.io/openhands/agent-server:agent-profile-persona-golang
ghcr.io/openhands/agent-server:358e0e1-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:358e0e1-java
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-java
ghcr.io/openhands/agent-server:agent-profile-persona-java
ghcr.io/openhands/agent-server:358e0e1-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:358e0e1-python-minimal
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-minimal
ghcr.io/openhands/agent-server:agent-profile-persona-python-minimal
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-minimal
ghcr.io/openhands/agent-server:358e0e1-python-slim
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python-slim
ghcr.io/openhands/agent-server:agent-profile-persona-python-slim
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime-slim
ghcr.io/openhands/agent-server:358e0e1-python
ghcr.io/openhands/agent-server:358e0e18633ff2d0566ec0474db7e92c87b85996-python
ghcr.io/openhands/agent-server:agent-profile-persona-python
ghcr.io/openhands/agent-server:358e0e1-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 358e0e1-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., 358e0e1-python-amd64) are also available if needed

simonrosenberg and others added 2 commits October 2, 2026 02:44
Add `persona` to `Agent`, `OpenHandsAgentSettings` and
`OpenHandsAgentProfile`. A persona replaces only the persona and
coding-workflow sections of the static prompt (soul, role, efficiency,
file system, code quality, version control, pull requests, problem
solving, self-documentation, environment setup, troubleshooting).
Capability and policy sections still render: memory, security policy,
risk assessment, browser, external services, process management and
model-specific guidance. So does the dynamic block. With no persona the
prompt is unchanged.

The planning preset keeps its section after the persona; an inline
`system_prompt` still replaces everything. The agent-server advertises
`profile_persona_v1`; ACP profiles reject the field.

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

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
  ✅ **PR Artifacts Cleaned Up**

  The `.pr/` directory is no longer present.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@simonrosenberg
simonrosenberg marked this pull request as ready for review October 2, 2026 06:50
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   server_details_router.py66297%27–28
openhands-sdk/openhands/sdk/agent
   agent.py4673692%111, 331, 487, 491, 798–799, 806–807, 930, 934–935, 940–942, 944, 963–964, 970, 975, 1010–1011, 1018–1019, 1064, 1071, 1085–1086, 1118–1119, 1371, 1456–1457, 1459, 1489, 1538, 1545
openhands-sdk/openhands/sdk/context/prompts
   presets.py39295%135–136
openhands-sdk/openhands/sdk/profiles
   agent_profile.py125794%342, 353, 356, 434, 440, 445, 473
   resolver.py139398%161, 215, 497
openhands-sdk/openhands/sdk/settings
   model.py8847092%328, 346, 554, 566, 576–579, 582, 599, 605, 615, 621, 626, 802, 805–806, 812–815, 820, 824, 839, 842–844, 892, 897–898, 903, 924, 936, 985, 994, 1041, 1235, 1260, 1262, 1264, 1266, 1268, 1270, 1272, 1274, 1276, 1278, 1552, 1613, 1615, 1921, 1941, 2073, 2129, 2205, 2244, 2399–2401, 2403, 2489, 2499, 2501, 2506, 2524, 2537, 2539, 2541, 2543, 2550
TOTAL46972828482% 

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

This review was posted by an AI agent (OpenHands).

Scope gate: maintainer product/architecture decision required.

This change belongs in this repository. It modifies the Python SDK and agent server this repo owns (prompt presets/sections, AgentBase, OpenHandsAgentSettings, OpenHandsAgentProfile, the resolver/seed, and the server capability list). It is not a wrong-repository change and nothing needs to move.

What it does not have is a settled product/architecture direction. This PR is explicitly the second of two mutually exclusive designs:

  • #5438 (system_prompt) lets a profile replace the whole static prompt. Linked issue #4956 records a decision for that surface — "Decision on the exposed surface: inline text, no deployment flag, no file path. Implemented in #5438" — and #5438 already carries an all-hands-bot approval.
  • #5449 (this PR, persona) replaces only the persona and coding-workflow sections, keeping the capability/policy sections.

The PR description itself says "Pick one," and the two cannot both land: they introduce different profile/settings fields, different semantics, and different advertised capabilities (profile_persona_v1 vs profile_system_prompt_v1). Accepting this head would reverse the direction recorded on #4956 in favor of the alternative surface. That is a maintainer choice, not a review finding.

Recommendation: route to a maintainer to select the surface (#5438 vs this PR), then re-point #4956's acceptance criteria and the capability contract accordingly. Do not merge both. If the persona design is chosen, this head is ready for a fresh technical review; if #5438 is chosen, close this PR.

Per the review workflow, I am stopping at the scope gate and am not reporting implementation findings.

🛑 MAINTAINER DECISION REQUIRED

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

This review was posted by an AI agent (OpenHands).

Review: feat(agent-profiles): let a profile replace the agent's persona

Verdict: approve. The change is in scope (the SDK / Agent Server own prompt composition and the profile/settings models), and persona is threaded through every public path I checked: Agent → OpenHandsAgentSettings → resolver → seed → OpenHandsAgentProfile → create_agent() → static_system_message, plus the REST Agent schema and the handwritten TS profile type. Focused suites pass on the head.

What I verified on 1ef4270:

  • Prompt composition. PersonaSection plus the _ReplacedByPersona wrapper drop exactly the persona/coding-workflow sections when ctx.persona is set, and keep MEMORY, SECURITY, SECURITY_RISK_ASSESSMENT, BROWSER_TOOLS, EXTERNAL_SERVICES, PROCESS_MANAGEMENT, the model-specific IMPORTANT block, and the whole dynamic tier. With no persona, the section list and order are unchanged, and test_prompt_snapshot.py still pins the static block byte-for-byte. The planning preset prepends the persona and keeps PlanningSection; inline system_prompt still short-circuits.
  • Compatibility. persona is additive with default=None; from_persisted / apply_agent_settings_diff load older payloads and can clear it with an explicit None; switching to ACP drops it. Persisted settings, REST API (OpenAPI), and make test-server-schema are green on the head.
  • Tests. tests/sdk/context/prompts/*, tests/sdk/profiles/*, tests/sdk/test_settings.py, and tests/sdk/test_apply_agent_settings_diff.py → 366 passed locally.

CI. Every head check is green except agent-server-stress-tests, which fails test_concurrent_conversations_isolated_and_fast with ConversationRunLimitExceeded. That is a pre-existing flake, not a regression: the same test fails identically on main runs 36763498079 and 36727395188, and this PR does not touch the concurrency path. No action needed here.

Merge decision. This is an explicit alternative to #5438 (system_prompt replaces the entire static block). Both PRs are open; which design to take is a maintainer call that this review does not resolve.

Eval risk. The change alters system-prompt composition for profile-driven agents, so it can plausibly change agent behavior. The linked issue #4956 does not require eval evidence, but a lightweight eval on a profile-driven coding task is worth running before merge.

Non-blocking observation. A persona consisting only of whitespace (" ") satisfies min_length=1, is treated as set by PromptContext.persona (truthiness), and therefore drops the whole persona layer, leaving a static prompt that begins with <MEMORY>. A truly empty "" is handled correctly. If whitespace-only should count as "unset", stripping at the field boundary would close it. Degenerate input, so not blocking.

✅ APPROVED

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall. I couldn't find any problems with section ordering when no persona is set, with system_prompt still taking precedence, with the resolver/seed round-trip, with verify() on resume, or with sub-agents (they don't inherit the persona). Two small things inline.

- `persona` moves from `AgentBase` to `Agent`, so `ACPAgent` no longer
  advertises a field it ignores; `Agent` adds it to the prompt kwargs.
- A whitespace-only persona counts as unset, instead of dropping the
  persona sections and rendering nothing in their place.
- `PersonaSection` extends `_StaticTextSection`, and `_ReplacedByPersona`
  is a frozen, slotted dataclass; `PromptSection` now declares `name`
  and `cache_tier` read-only so frozen sections satisfy it.
- The persona field constraints and description are inlined, as for
  the other fields.

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

Copy link
Copy Markdown
Member Author

@VascoSch92 thanks for the review. All five points are addressed in 7220c57:

  • ACP: persona moved from AgentBase to Agent, so ACPAgent no longer advertises it. A test pins this, and the ACPAgent OpenAPI schema drops it.
  • Whitespace: a whitespace-only persona now counts as unset (your suggestion), so the built-in persona stays. Regression test included; it fails without the fix.
  • PersonaSection extends _StaticTextSection.
  • _ReplacedByPersona is a frozen, slotted dataclass. PromptSection now declares name/cache_tier as read-only properties so frozen sections satisfy it.
  • Field definitions: the persona constraints and description are inlined on the fields.

Re-verified on the new head:

  • SDK suites: 1697 passed; agent-server: 248 passed.
  • Live run against the mock LLM is unchanged: persona first, memory/security/risk/tool sections kept, persona-layer sections dropped.
  • CI: 51/51 green.

# Conflicts:
#	openhands-sdk/openhands/sdk/profiles/resolver.py
#	tests/sdk/profiles/test_resolver.py
@simonrosenberg
simonrosenberg enabled auto-merge (squash) October 2, 2026 15:16
@simonrosenberg
simonrosenberg merged commit 048c9be into main Oct 2, 2026
61 of 62 checks passed
@simonrosenberg
simonrosenberg deleted the agent-profile-persona branch October 2, 2026 15:19
simonrosenberg added a commit that referenced this pull request Oct 2, 2026
…finalize

Brings in #5151 (tools is the only tool control) and #5449 (profile persona).

- finalize resolves the tool set with launch_tool_specs, so an unset list gets
  switch_llm and the browser when the runtime can run it, and an explicit list
  loses a browser the runtime cannot run.
- The Docker host now knows the container's browser from its config
  (enable_browser, conversation_image_has_browser), so materialize no longer
  reports `pending`, and the host passes the decision to the container as
  OH_ENABLE_BROWSER; the container still finalizes with its own probe.
- materialize keeps main's draft body and unusable_tools, and reports the
  launch's tools in resolved_settings, so resolved_tools is dropped.
- profile_launch.py folds into launch.py; its launch helpers are replaced by
  resolve/finalize.
- persona is classified as profile-owned in the field-ownership test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VascoSch92 pushed a commit that referenced this pull request Oct 3, 2026
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: allhands-bot <allhands-bot@users.noreply.github.com>
(cherry picked from commit 048c9be)
This was referenced Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants