DeepSeek Harness

DeepSeek Harness: How Model Streams Reach Sessions

· 6 min read · 中文版

DeepSeek Harness turns an adapter's typed stream into live agent events and a durable session settlement. Chunks seen during generation are transient; replay uses the stream recorded when the attempt settles.

DeepSeek Harness: what starts a streamed request?

The agent lifecycle places model streaming inside a step of an agent turn. The driver prepares the model call, admits the relevant messages, records request information as needed, derives a request from the log and invokes the prepared call through the llm/stream waterfall. The provider's adapter supplies the stream; the agent driver and Session own the surrounding turn and its recorded outcome.

The LLM streaming reference defines shared request and message types, the raw StreamChunk protocol, adapter obligations and an assembler. A model's response may include text, reasoning and multiple tool calls, with chunks interleaved. It is not simply one string appended to the conversation.

A prepared request becomes chunks, a live stream and a durable settlement

DeepSeek Harness: how are chunks assembled?

Each block uses an index to associate deltas with the right content block. block-start starts a typed block; text-delta and reasoning-delta carry text; tool-call-delta carries an identity and argumentsDelta. block-end provides the fully assembled ContentBlock, so a consumer of that boundary need not reconstruct every delta. The union also includes usage and a terminal finish.

Stream factPurposeConsumer caution
Block indexCorrelates interleaved fragmentsDo not merge unrelated blocks
Tool argument deltaCarries part of the argumentsFragments are raw JSON strings, not complete parsed objects
block-endSupplies the assembled blockA block end is not necessarily the end of the whole response
usageCarries token usageAdapters emit it before terminal finish
finishMarks terminal outcomeNo further chunks should follow

The adapter contract requires usage before finish and nothing after finish. Tool-call arguments remain raw JSON strings end to end. An adapter may throw, or represent an in-band failure in a terminal finish; the runtime normalizes adapter failures to an error or aborted terminal finish before exposing them to consumers. That distinction matters when a visible prefix is followed by a failure: partial display is not the same thing as a successful assistant message.

DeepSeek Harness: what reaches live listeners and the log?

The driver emits agent/assistant-stream frames for live presentation. These frames are process-local and transient. On a successful provider call, it records assistant/message, including the compact timed stream; the lifecycle says this includes successful content-less and max-tokens finishes. Empty content stays out of derived history. If a failed, retried, cancelled or stream-error attempt reaches settlement without a surface message, the stream is recorded as assistant/attempt instead.

The AssistantStreamAccumulator stores chunks with their timestamps in compact records. Consecutive text, reasoning or tool-argument deltas for the same block can share a record, while retaining each original delta and timing gaps. Other chunks remain timestamped raw records. expandAssistantStream() validates the stored representation and recreates the timed chunk sequence. Compact storage is therefore not simply joining all text into a single string.

The lifecycle recommends session/event for SDK consumers needing replayable transcript data; agent/* is the live coordination interface. An observer that only listens to live frames should not assume those frames form the durable history. Conversely, a process lost before settlement has no durable attempt stream for that unsettled request, even if a listener saw partial output.

DeepSeek Harness: what happens when the model requests tools?

After a successful model request, the driver classifies pending calls by execution mode. The lifecycle describes ordered pre-processing, bounded concurrent execution where applicable, and ordered post-processing and results. It records tool/call when a call starts and tool/result as results become ready in model order, then records step/end. Subsequent input or tool results can lead to another request step within the turn.

Streaming a tool-call argument is not itself the same as running the tool. The runtime has to assemble the call and the driver must proceed to the execution phase. Similarly, a tool result is a separate event from the assistant's streamed output. See tool calls to results for the execution side.

If an attempt fails, the lifecycle describes a request-error waterfall that can choose a retry action or preserve the original error. A retry occurs within the open step with a newly prepared call and reconciliation, without repeating pre-step or user admission. Do not collapse multiple attempts into one apparently uninterrupted success when examining the event history.

DeepSeek Harness: how can you trace an apparent missing response?

  1. Identify the turn and step, and distinguish an in-progress request from a settled attempt. A live view may have seen a fragment even when no durable settlement exists yet.
  2. Inspect the recorded assistant/message or assistant/attempt, if present, and its terminal outcome. Check whether the content was empty, interrupted, failed or successfully completed.
  3. For interleaved blocks, correlate indexes and inspect block-end rather than joining every delta together. Keep tool arguments as strings until the appropriate boundary handles them.
  4. If a tool was requested, check the separate call and result events and whether a subsequent step ran. A tool-call delta alone does not establish execution.
  5. If the request was retried, compare attempts and the final outcome. For durable replay, use Session events and the documented validation path rather than relying on a screenshot of live output.

This is an evidence-gathering workflow, not a promise that every interrupted process will have a complete record. Preserve only the information needed to investigate and remove private prompts, outputs and credentials before sharing it.

DeepSeek Harness: what are the limits and safety boundaries?

A streamed prefix can be incomplete or wrong, and a terminal error can follow it. Treat tool calls as proposed actions governed by the execution and approval contracts, not as actions authorized merely by appearing in output. A successful message settlement establishes a provider call outcome, not the correctness of its contents or the safety of a later tool.

Durable logs may contain prompts, assistant content, tool arguments and failure information. Access and sharing require care. The references describe the event and replay contracts; they do not promise recovery of live chunks lost before settlement or guarantee that every provider supplies identical block types and usage information in every response.

DeepSeek Harness: what do the terms mean?

  • Turn and step: a turn can contain request steps and tool execution before it ends.
  • Adapter: the provider-facing implementation that emits the shared stream protocol.
  • Delta: an incremental fragment associated with a content block.
  • Settlement: the recorded message or attempt outcome after the request resolves.
  • Live frame: a transient agent/assistant-stream event used for presentation.
  • Replay: reconstruction from the durable Session settlement rather than a process-local live frame.

Frequently asked questions

Are live stream frames durable?

No. Live frames are transient; replay reads the recorded settlement.

Does a tool-call delta mean a tool ran?

No. The call must be assembled and the driver must proceed to tool execution.

Can a failed attempt be recorded?

Yes. An attempt that settles without a surface message can be recorded as assistant/attempt.

Sources

Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.

  1. LLM streaming
  2. Agent turn and step lifecycle

This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.

← Back to all articles

DeepSeek Harness: How Model Streams Reach Sessions