Here’s the answer to Brett’s question, focused on V1 and the secrets path from web UI → app-server → agent-server.
How core OpenHands uses agent-sdk (V1)
• The V1 “core” runs the agent remotely via the agent-sdk’s agent-server. The OpenHands app-server builds a StartConversationRequest (which includes per-conversation secrets) and POSTs it to agent-server. OpenHands does not “pull” code from agent-sdk; it calls its REST API.
• Secrets are injected per conversation. Custom user secrets come from the user context (StaticSecret). Git provider tokens are added as either:
◦ LookupSecret: a per-conversation, short-lived JWT-backed callback to the app-server (preferred), or
◦ StaticSecret: the latest token value if the sandbox can’t reach the app-server webhook.
End-to-end execution path with the files/classes actually used in V1
1. User stores secrets in the UI (storage path still uses legacy /api)
• FE calls legacy /api/secrets:
◦ frontend/src/api/secrets-service.ts (GET/POST/PUT/DELETE /api/secrets)
https://github.com/OpenHands/OpenHands/blob/main/frontend/src/api/secrets-service.ts#L10-L39
• Legacy server mounts /api/secrets; this is still on the live server process that also mounts the V1 router:
◦ openhands/server/app.py (includes both legacy and v1)
https://github.com/OpenHands/OpenHands/blob/main/openhands/server/app.py#L83-L95
◦ openhands/server/routes/secrets.py (CRUD)
GET /api/secrets:
https://github.com/OpenHands/OpenHands/blob/main/openhands/server/routes/secrets.py#L186-L220
POST /api/secrets:
https://github.com/OpenHands/OpenHands/blob/main/openhands/server/routes/secrets.py#L222-L244
PUT /api/secrets/{id}:
https://github.com/OpenHands/OpenHands/blob/main/openhands/server/routes/secrets.py#L246-L296
DELETE /api/secrets/{id}:
https://github.com/OpenHands/OpenHands/blob/main/openhands/server/routes/secrets.py#L298-L338
◦ FileSecretsStore → secrets.json
https://github.com/OpenHands/OpenHands/blob/main/openhands/storage/secrets/file_secrets_store.py#L15-L53
2. User starts a V1 conversation (FE → app-server /api/v1 → agent-server)
• FE starts V1 app-conversation:
◦ frontend/src/api/conversation-service/v1-conversation-service.api.ts (POST /api/v1/app-conversations)
https://github.com/OpenHands/OpenHands/blob/main/frontend/src/api/conversation-service/v1-conversation-service.api.ts#L85-L91
• V1 routing:
◦ openhands/app_server/v1_router.py (mounts V1 routers under /api/v1)
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/v1_router.py#L12-L19
◦ openhands/app_server/app_conversation/app_conversation_router.py (POST /api/v1/app-conversations)
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/app_conversation_router.py#L169-L187
3. App-server assembles secrets and calls agent-server
• Orchestration service that builds StartConversationRequest, injects secrets, and POSTs to agent-server:
◦ openhands/app_server/app_conversation/live_status_app_conversation_service.py:
POST to agent-server /api/conversations:
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/live_status_app_conversation_service.py#L217-L226
Build StartConversationRequest (includes secrets):
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/live_status_app_conversation_service.py#L454-L513
GIT_TOKEN key constant:
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/live_status_app_conversation_service.py#L76
• Custom secrets are converted to StaticSecret per conversation:
◦ openhands/app_server/user/auth_user_context.py#get_secrets:
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/user/auth_user_context.py#L70-L79
• Git provider token is set as:
◦ LookupSecret when web_url is reachable (per-conversation JWT):
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/live_status_app_conversation_service.py#L465-L480
◦ StaticSecret fallback when not reachable:
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/app_conversation/live_status_app_conversation_service.py#L480-L487
• The LookupSecret URL points to app-server’s webhook; Docker runtime helps make it reachable from the sandbox:
◦ Docker sets OH_WEBHOOKS_0_BASE_URL and X-Session-API-Key for sandbox:
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/sandbox/docker_sandbox_service.py#L271-L287
◦ Webhook endpoint used by LookupSecret to fetch the token:
openhands/app_server/event_callback/webhook_router.py (GET /api/v1/webhooks/secrets)
https://github.com/OpenHands/OpenHands/blob/main/openhands/app_server/event_callback/webhook_router.py#L155-L173
4. Agent-server (agent-sdk) runs with per-conversation secrets
• StartConversationRequest (secrets: dict[str, SecretSource]):
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-agent-server/openhands/agent_server/models.py#L44-L83
• On start, EventService creates LocalConversation(secrets=...):
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-agent-server/openhands/agent_server/event_service.py#L105-L140
• Secret types:
◦ StaticSecret and LookupSecret:
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-sdk/openhands/sdk/conversation/secret_source.py#L21-L39
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-sdk/openhands/sdk/conversation/secret_source.py#L41-L83
• How secrets are used:
◦ SecretRegistry finds secret names in a command, exports env vars, and masks outputs:
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-sdk/openhands/sdk/conversation/secret_registry.py#L62-L80
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-sdk/openhands/sdk/conversation/secret_registry.py#L101-L125
◦ Terminal tool exports those env vars before executing and masks outputs:
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-tools/openhands/tools/terminal/impl.py#L56-L96
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-tools/openhands/tools/terminal/impl.py#L152-L181
5. Runtime secret updates (agent-server capability)
• Agent-server endpoint to update secrets mid-run:
Route:
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-agent-server/openhands/agent_server/conversation_router.py#L196-L226
Service:
https://github.com/OpenHands/software-agent-sdk/blob/main/openhands-agent-server/openhands/agent_server/event_service.py#L286-L304
What is implemented vs. what isn’t (V1)
• Implemented:
◦ FE saves custom secrets via /api/secrets (legacy server) which are injected as StaticSecret per conversation.
◦ Git provider token is available per conversation as GIT_TOKEN (prefer LookupSecret with a short-lived JWT; fallback StaticSecret).
◦ Agent-server injects env vars for commands referencing secret names and masks outputs.
◦ Agent-server supports updating secrets via POST /conversations/{id}/secrets.
• Not yet implemented in V1 UI:
◦ A V1 endpoint/FE action to update a running conversation’s secrets (the contract exists on agent-server, but app-server/FE aren’t calling it yet).
Where to start if you want to add per-conversation secret updates in the V1 UI
• Add an app-server V1 endpoint (e.g., POST /api/v1/app-conversations/{id}/secrets) that resolves requested secret names into SecretSource (StaticSecret from custom store, LookupSecret for provider tokens) and proxies to agent-server’s POST /api/conversations/{id}/secrets with X-Session-API-Key.
• Add a FE mutation for “Update secrets for this conversation” (or “Apply to conversation” in Settings).
• Keep existing /api/secrets CRUD for persistence; use the new endpoint to push changes to running conversations.
Prereqs
• Clone both repos: OpenHands/OpenHands and OpenHands/software-agent-sdk.
<sub>
View full conversation</sub>