Repository navigation
Description
Summary
A conversation started from an AgentProfile (agent_profile_id) instead of an inline agent_settings payload never gets LLM token streaming wired up — and a later switch_llm call that assumes streaming is already enabled (a legitimate, pre-existing behavior on the agent_settings path) crashes the run with:
ValueError: Streaming requires an on_token callback
This is the same profile-launch path exercised by agent-canvas#1571, and the same category of gap as #3967 (exec tools / public skills silently dropped on agent_profile_id launches) — this time for streaming.
Root cause (traced)
LocalConversation.__init__decides once, at conversation construction, whether to wire theon_tokenstreaming callback, viastreaming_enabled = isinstance(agent, ACPAgent) or any(llm.stream for llm in agent.get_all_llms())(openhands-agent-server/openhands/agent_server/event_service.py). This is never re-evaluated afterward — confirmed by readingLocalConversation.switch_llm(openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py): it swapsself.agent's LLM viamodel_copy(update={"llm": new_llm, ...})but never touchesself._on_token.- On the legacy
agent_settingspath, a consuming client can forcestream=Trueon the inline LLM config it sends at conversation-start (agent-canvas does this — see below), sostreaming_enabledis correctlyTruefrom construction. - On the
agent_profile_idpath,_build_openhands_settings(openhands-sdk/openhands/sdk/profiles/resolver.py) does"llm": llm— the loaded LLM profile object as-is, with no forcedstream=Trueoverride. Sostreaming_enableddepends entirely on whateverstreamvalue happens to be persisted on the referenced LLM profile (SDK default:False). - Consequence: any profile-launched conversation whose LLM profile was never explicitly saved with
stream: truegetson_token=Nonefor its entire lifetime. The first turn's completion is fine (no streaming requested), but a client that later callsswitch_llmwithstream: true(assuming parity with how conversation-start behaves) crashes the very next completion, sinceon_tokencan never be (re-)wired post-construction.
Confirmed via real agent-server tracebacks in agent-canvas#1571's CI (both mock-llm-e2e and mock-llm-docker-e2e), reproducing on both a /model slash-command switch and, intermittently under Docker, on a preset-automation dispatch.
Why this is an SDK-level gap, not just a client bug
The asymmetry is structural: _build_openhands_settings never gives OpenHands profile resolution a way to guarantee stream=True the way an agent_settings-launching client can. Every consumer of agent_profile_id (agent-canvas, the cloud app-server, eval) inherits this gap identically, since all three build the agent purely from the stored profile fields.
Proposed fix
_build_openhands_settings(orresolve_agent_profile) should forcellm.stream = Trueon the resolved LLM for OpenHands profiles, mirroring whatagent_settings-launching clients already do at their end — closing the asymmetry at the source rather than leaving every consumer to work around it independently.- Longer-term/more robust: consider making
streaming_enabled/on_tokenwiring re-evaluated per-call (or at least perswitch_llm) rather than frozen atLocalConversation.__init__, and/or haveacompletion/aresponsesgracefully downgrade to non-streaming instead of hard-raising whenstream=Trueis requested but noon_tokenis wired — a silent capability mismatch shouldn't crash the whole run.
Current workaround (agent-canvas)
agent-canvas#1571 works around this client-side only, since streaming (PR agent-canvas#1474) is a pre-existing, independently-shipped feature that must not regress — ruling out simply dropping the switch_llm stream:true call (would silently disable streaming-after-switch for the legacy path, which works today), and since existing users' LLM profiles predate any fix, a "default at next profile-save" approach alone would still crash on their first profile-launched conversation post-deploy.
The workaround (ensureLlmProfileStreams in src/hooks/mutation/use-create-conversation.ts, commit 65a429f8) self-heals the referenced LLM profile's persisted stream field to true the first time it's used to launch a profile conversation — the one call site guaranteed to run for every agent_profile_id launch (already fetching the LLM-profiles list to validate llm_profile_ref exists). It's explicitly a migration shim, safe to delete once this issue's root fix ships upstream (regardless of individual user migration state at that point).
Context / tracking
- Epic: [AgentProfile] Epic: first-class Agent Profiles (named launch setups) across SDK, agent-server, canvas, cloud #3713 (Agent Profiles)
- Related: Profile-resolved OpenHands agents have no exec tools (and no public skills) #3967 (same category — profile resolution dropping agent_settings-only enrichments — but for tools/skills, not streaming)
- Consumer that surfaced this + workaround: feat(agent-profiles): Agent Profiles — Settings → Agent as the profile library (local + cloud) agent-canvas#1571 (commit 65a429f8)
Activity
simonrosenberg commentedon Jul 7, 2026
Consolidated into #4017 — this is one of four faces of the same root cause (the profile resolver builds a minimal agent from scratch and drops the defaults the
agent_settingspath sets). #4017 proposes fixing the class (defaults-then-override, mirroring how #3968 already fixed the tools face) rather than patching streaming in isolation. Keeping this open for the streaming-specific detail (theon_tokenwiring frozen atLocalConversationconstruction); the resolverstream=Truedefault lives in #4017.fix(llm): gracefully degrade streaming without on_token callback
simonrosenberg commentedon Jul 10, 2026
Fixed by #4018 (merged as 1877912, released in SDK v1.33.0). Profile launches now force streaming at the agent-server layer, and LLM completion gracefully degrades when no on_token callback is present. Agent Canvas currently pins agent-server 1.33.0 and no longer contains ensureLlmProfileStreams.
fix(sdk): three defects found reviewing StreamContext