Repository navigation
fix: Include secrets in system prompt when added via update_secrets() - #2171
Conversation
Previously, secrets passed to LocalConversation via the constructor's secrets parameter or update_secrets() method were only added to the secret_registry for environment variable injection during command execution. They were NOT added to agent.agent_context.secrets, which meant they did not appear in the system prompt. This fix ensures that when secrets are added: 1. They are still registered in secret_registry for command execution 2. They are also added to agent.agent_context.secrets so they appear in the system prompt's <CUSTOM_SECRETS> section This brings the SDK behavior in line with OpenHands web, where secrets and their descriptions are always shown in the system prompt to inform the agent about available credentials. Changes: - Updated update_secrets() in LocalConversation to also update agent.agent_context.secrets - Added _update_agent_context_secrets() helper method - Added tests to verify secrets appear in the system prompt Co-authored-by: openhands <openhands@all-hands.dev>
API breakage checks (Griffe)Result: Passed |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable - Solves a real problem where agents had no visibility into available secrets. Tests are solid and verify actual behavior. One minor state consistency note inline.
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Thank you for looking into this! I'd love if we can pause a tiny moment to figure out if this is something we should do in the SDK (seems so) and if so, how, as in the code design and consequences.
I think we are assuming in general that we provide the "infrastructure" and it's up to client applications to use it. That's why we may have things like an API to load skills from the agent-box, but not actually loading them by default anywhere in the SDK, the applications do.
In this case, I think maybe "updates" to the agent context feels a tad suspicious. The agent is supposed to get created with attributes etc, and then the attributes do not really change except in well defined ways. I'd love to know @xingyaoww 's thoughts about this. 🤔
…on.py Co-authored-by: OpenHands Bot <contact@all-hands.dev>
|
Hmm I kind of agree the control flow here is bad. Probably better for the agent to do something like But I do think it's a basic assumption that if you define secrets, the agent knows it has access to those secrets |
|
@OpenHands change the control flow in the implementation here. have the agent request the secrets and add them to its prompt rather than modifying the agent from outside |
|
I'm on it! rbren can track my progress at all-hands.dev |
Changes the control flow for secrets in system prompts: - Previously: LocalConversation.update_secrets() modified agent.agent_context from outside - Now: Agent requests secrets from conversation state and adds them to its prompt Implementation: - Add get_secret_infos() method to SecretRegistry - Add get_dynamic_context(state) method to Agent that pulls secrets from state.secret_registry - Modify Agent.init_state() to use get_dynamic_context(state) instead of dynamic_context property - Add additional_secret_infos parameter to AgentContext.get_system_message_suffix() to allow merging registry secrets with agent_context secrets - Remove _update_agent_context_secrets() from LocalConversation - Simplify update_secrets() to only update the registry This design is cleaner because: - The agent controls what goes into its own prompt (pull model) - Secrets are stored in one place (secret_registry) - No external modification of frozen agent state Co-authored-by: openhands <openhands@all-hands.dev>
SummaryI've addressed @rbren's feedback by refactoring the control flow for secrets in the system prompt. Changes MadeControl Flow Change:
Files Changed:
Checklist
|
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable - Solves a real problem where agents had no visibility into available secrets. The approach is pragmatic: pull from the single source of truth (secret_registry) when building the prompt rather than duplicating state. Tests verify actual behavior. One efficiency note inline about the merge logic.
|
@OpenHands Do a /codereview-roasted on this PR. Investigate examples/ files too on this, to see how we work with agent context and secrets. Once you are done, take a step back and reconsider your review and the PR diff with fresh eyes: are things as major or minor as they seemed at fight sight? |
|
I'm on it! enyst can track my progress at all-hands.dev |
|
Final summary:
|
|
(OpenHands-GPT-5.2) Taste Rating: Acceptable (solves a real problem, but the shape is kind of ugly)You fixed the actual bug: secrets added to a But the implementation introduces some “two sources of truth” and layering weirdness that will age poorly. [CRITICAL ISSUES][openhands-sdk/openhands/sdk/agent/agent.py:187-243] You now have two different “dynamic context” concepts
So: the real system prompt event contains secrets, but the public-ish agent properties do not. That’s inconsistent and will confuse anyone debugging prompts or doing anything custom with This is the core architectural smell: the agent is “stateless” by design, but you need state to compute prompt context. Either embrace that and make a single blessed codepath, or keep the agent stateless and stop pushing stateful data through [agent.py:225-237] Creating a throwaway
|
enyst
left a comment
There was a problem hiding this comment.
This looks clean to me, thank you! As you can see, OpenHands is not entirely happy, but I feel it's manageable in follow-ups.
Up to you if you wish a second opinion or could address some of the rest.
|
@OpenHands Look at the https://github.com/OpenHands/software-agent-sdk/blob/65cf6c227f5e56c4d328bfe77a012abba9c7a79b/.github/workflows/api-breakage.yml and its CI log from this PR. Compare with the PR's diff. Shouldn't we have had some checks on the method signature change in this PR diff? Why did it succeed without reporting signature changes? |
|
I'm on it! enyst can track my progress at all-hands.dev |
|
I investigated the PR’s What I did / checked
Restated answer (why this wasn’t reported as breaking)
No code changes were made as part of answering this question. |
Co-authored-by: OpenHands Bot <contact@all-hands.dev>
|
[Automatic Post]: It has been a while since there was any activity on this PR. @rbren, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
…OpenHands#2171) Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: OpenHands Bot <contact@all-hands.dev>
Summary
Fixes an issue where secrets passed to
LocalConversationwere not appearing in the system prompt, even though the infrastructure for including them exists.Problem
Previously, secrets passed to
LocalConversationvia:secretsparameterupdate_secrets()methodWere only added to the
secret_registryfor environment variable injection during command execution. They were NOT added toagent.agent_context.secrets, which meant they did not appear in the system prompt's<CUSTOM_SECRETS>section.This meant the agent had no awareness of what secrets were available to it, unlike OpenHands web where secrets and their descriptions are always shown in the system prompt.
Solution
Updated
update_secrets()inLocalConversationto also updateagent.agent_context.secrets, ensuring that:secret_registryfor command execution (env var injection)agent.agent_context.secretsso they appear in the system promptChanges
local_conversation.py:update_secrets()to call new_update_agent_context_secrets()helper_update_agent_context_secrets()helper method that merges secrets into agent_contextAgentContexttest_agent_secrets_integration.py: Added 5 new tests:test_update_secrets_adds_to_agent_contexttest_update_secrets_appears_in_system_prompttest_update_secrets_merges_with_existing_contexttest_update_secrets_overrides_existing_secrettest_secrets_via_constructor_appear_in_promptTesting
All 14 tests in
test_agent_secrets_integration.pypass, including the 5 new ones.Before/After
Before: Agent has no knowledge of available secrets in system prompt
After: Agent sees available secrets in system prompt
@rbren can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:181e94e-pythonRun
All tags pushed for this build
About Multi-Architecture Support
181e94e-python) is a multi-arch manifest supporting both amd64 and arm64181e94e-python-amd64) are also available if needed