LLM adapters and the streaming vocabulary
Unify content blocks, messages, stream chunks, and recovery so providers stay behind the seam
ModelSelection → adapter → StreamChunk*Why can DeepSeek, replay, and other providers stream into the same agent loop?
An international airport maps each airline's internal process into a common gate protocol. Air traffic control deals only with standardized callsigns, states, and error classes.
Mechanism
ctx.llm holds a provider-routed adapter registry. LlmCallConfig, ContentBlock, Message, ToolCall, and StreamChunk are provider-neutral vocabulary.
Every raw chunk is logged as assistant/chunk. Success adds assistant/message and usage. After a failed step closes, agent/request-error decides whether recovery may retry.
Resolve route
ModelSelection resolves provider and exact adapter.
What extensions must preserve
- Adapters do not mutate sessions directly
- One successful provider call maps to one assistant/message
- Recovery is bounded and preserves the original error
The tempting wrong turns
- ×Branching on provider names inside agent-loop
- ×Logging only final text and losing tool/thinking stream fidelity
- ×Retrying context overflow unconditionally
Do not trust the conclusion—verify it
These anchors are pinned to official deepseek-harness@47f9438; account for later breaking changes when reading current upstream.
Pause for ten seconds before revealing
Why does a failed provider call have no assistant/message?
The model may emit tool calls. Next we enter the harness's most important security pipeline.