LAYER 03 · Trace the agent spine

LLM adapters and the streaming vocabulary

Unify content blocks, messages, stream chunks, and recovery so providers stay behind the seam

18 min3 source anchorsupstream@47f9438
ModelSelection → adapter → StreamChunk*
The question this chapter resolves

Why can DeepSeek, replay, and other providers stream into the same agent loop?

Build intuition

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

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.

Step 1 of 5

Resolve route

ModelSelection resolves provider and exact adapter.

INVARIANTS

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
FAILURE MODES

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
VERIFY IN SOURCE

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.

KNOWLEDGE CHECK

Pause for ten seconds before revealing

Why does a failed provider call have no assistant/message?

Why the next chapter follows

The model may emit tool calls. Next we enter the harness's most important security pipeline.

Learn DeepSeek Harness

An independent learning project. Explanations derive from source; upstream remains authoritative.