Repository navigation
fix(subagent): decrypt named LLM profiles with the conversation cipher - #6461
Merged
Merged
Conversation
Sub-agents that set `model: <profile>` loaded the profile without the cipher that encrypted it at rest, so the stored Fernet token reached the provider as the API key and authentication failed. Top-level profile resolution already passed the cipher; the sub-agent factory did not. - Accept a keyword-only `cipher` in `agent_definition_to_factory`, `register_file_agents` and `register_plugin_agents`, and pass it to `LLMProfileStore.load` so the sub-agent LLM and its default condenser receive the decrypted key. - Forward the conversation cipher from `LocalConversation` when it registers file-based and plugin agents, and the server cipher from the agent-server when it registers forwarded or persisted definitions. - Add regression tests for the named-profile, Markdown and plugin paths, for `LocalConversation`, and for the agent-server create and resume paths. `model: inherit` and plaintext profiles are unchanged; the new parameter defaults to `None` for every existing caller.
Contributor
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Contributor
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Sub-agents that select a saved LLM profile by name were loading it without the cipher, so the encrypted API key was sent to the provider as-is. This threads the owning conversation's cipher through sub-agent registration, mirroring what top-level profile resolution already does. I reviewed the diff and the tests; the new tests fail on
mainwithout the source change and pass with it.AGENT:
Why
When
OH_SECRET_KEYis set,LLMProfileStore.saveencrypts a profile's secrets at rest. The sub-agent factory inopenhands/sdk/subagent/registry.pyloaded amodel: <profile>profile withstore.load(profile_name)and no cipher, sovalidate_secretleft the Fernet token in place and the sub-agent's LLM (and its default condenser) sent the ciphertext as the API key. Providers reject it, for exampleLiteLLM Virtual Key expected. Received=gAAA****. Top-level profile resolution (profiles/resolver.py,LocalConversation.get_or_create_profile_llm) already passes the cipher, which is why the same profile works for the main agent but not for Markdown or plugin sub-agents.Summary
agent_definition_to_factory,register_file_agentsandregister_plugin_agentsaccept a keyword-onlycipher(defaultNone) and pass it toLLMProfileStore.load.LocalConversationforwards its cipher when registering file-based and plugin agents; the agent-server forwards the server cipher in_register_agent_definitionsfor both new and resumed conversations.LocalConversationcall sites, and the agent-server create and resume paths.Issue Number
Fixes #4270, fixes #5564, fixes OpenHands/OpenHands#17384. Covers the sub-agent call site of #4558; the
FallbackStrategycall site tracked there is unchanged.How to Test
uv run pytest -q tests/sdk/subagent/test_subagent_registry.py tests/sdk/conversation/test_local_conversation_agent_plugins.py tests/sdk/conversation/test_local_conversation_file_agents.py tests/agent_server/test_conversation_service.py tests/tools/task tests/tools/delegate tests/tools/test_builtin_agents.py— 343 passed.uv run pre-commit run --files <changed files>— Ruff, pycodestyle, Pyright and the import-rule checks pass.mainwith only the three source files reverted (the sub-agent'sapi_keyis still thegAAAAA…token) and pass with this change.OH_SECRET_KEYset, save a profile throughPOST /api/profiles/{name}with an API key, add.agents/agents/worker.mdwithmodel: <that profile>, and delegate a task toworker. Before this change the sub-agent's first LLM call fails authentication; with it the call uses the plaintext key, and the stored profile JSON keeps the encrypted value.Video/Screenshots
Not a visual change; see the test and reproduction notes above.
Design Doc
Not needed for a change of this size.
Type
Notes
None, so existing callers (includingregister_builtins_agents, whose agents all usemodel: inherit) are unaffected, and plaintext profiles load exactly as before.FallbackStrategy._iter_fallbacksload (Encrypted LLM profiles are decrypted only on the conversation path — FallbackStrategy (and sub-agents) load them without the cipher #4558), and child conversations spawned by the task and delegate tools, which still do not receive the parent cipher. That only matters for nested delegation that discovers new agents inside the child, since the shared registry keeps the parent's cipher-aware factory for names already registered.