DeepSeek Harness

DeepSeek Harness Agent Lifecycle: Creation to Stop

· 7 min read · 中文版

A DeepSeek Harness agent has an owned lifetime, but its work proceeds through separate turns and steps recorded in a session. Becoming idle, cancelling a turn, and disposing the agent are different events.

DeepSeek Harness: what is created, and who owns it?

The core reference describes an agent as the live participant that drives a session. Programmatic creation through ctx.agents can create a fresh session and agent under a caller-supplied session identity, or resume a persisted session. Config-created agents are another supported route. An owned AgentHandle gives the creating consumer an agent and a disposer; merely obtaining an agent from the registry does not grant that disposer.

Creation also has a publication boundary. The documented setup callback receives the agent and its scoped context before their identities are published. Its registrations are ready before agent/created and the first prompt assembly. If setup or its commit fails, the transaction rolls back without publishing either identity. This matters when a plugin needs to install per-agent behavior before the first request: there is a documented setup phase, not a race to add a listener afterward.

The session itself is an append-only event log, according to the session reference. The agent is live execution; the session is the recorded source from which model history is derived. A resumed agent uses persisted session state, but that does not mean that every transient stream frame can be replayed.

Agent creation, queued work, turn and step execution, idle and disposal

DeepSeek Harness: how does a turn become steps?

The lifecycle sequence follows a prompt from the inbox through a driver and into the session log. A followup queues ordinary work and wakes the driver. The live agent/status changes to running; the driver opens turn/start, claims input, assembles the system prompt, and runs the agent/pre-step waterfall. Its decision is authoritative: a rejected proposal, empty first batch, or pre-step failure can leave the turn without an entered step.

When a step is admitted, step/start precedes request preparation and admission of the relevant system and user messages. The driver derives a request from the log, calls the model, and streams output. A successful model call records assistant/message; requested tools may then produce tool/call and tool/result events. The step ends with step/end. If more next-step input is pending, the loop can claim it and enter another step. A natural stop with an empty next-step inbox can run the agent/turn-stopping checkpoint before turn/end.

BoundaryMeaningWhat it does not imply
Agent lifetimeOwned live execution and scoped resourcesOne uninterrupted model request
SessionAppend-only typed interaction historyEvery event becomes a model message
TurnOne enclosed loop executionA step must have been entered
StepA model call and its requested tool executionsA tool must have been requested
IdleNo current driver work in the status sequenceThe agent has been disposed

In particular, running describes a driver-wide drain interval and can span queued turns; it does not prove that a particular turn is still open. The session reference also permits plugin-owned log events between turns, so a gap between turn boundaries is not necessarily missing data.

DeepSeek Harness: how can a caller observe the sequence?

  1. Identify whether your integration creates a fresh agent or resumes a stored session. Retain the owner handle if your code is responsible for teardown.
  2. Submit the identified input through the relevant delivery method. followup() queues an ordinary prompt; steering can target the nearest step boundary. Their delivery semantics are distinct.
  3. Observe agent/* for live status, inbox coordination and streaming. Use session/event for replayable facts, including turn and step boundaries, assistant settlements and tool events.
  4. If you need whole-agent quiescence, await whenIdle(). The core reference says it follows replacement work started before the observed driver retires; it does not identify the result of one particular message.
  5. If inspecting durable storage immediately after idle, follow the session reference's explicit flush guidance. It says the loop does not await a flush at turn boundaries; the checkpoint policy handles per-request durability.

These are observation steps, not a guarantee that a provider call or tool succeeds. A turn may finish without a step, and a model request can fail after a step has opened. Inspect the recorded reason and events rather than inferring success from the presence of a boundary.

DeepSeek Harness: what happens on failure, retry or cancellation?

The lifecycle sequence distinguishes live stream chunks from settled records. Successful provider calls record an assistant/message, even for content-less or max-tokens finishes; empty content stays out of derived history. Failed, retried, cancelled, or stream-error attempts that settle without a surface message can record assistant/attempt. A hard process loss before settlement leaves no durable attempt stream. Consequently, an observer that saw partial live output must not assume the same frames were persisted.

The agent/request-error waterfall can return a retry action. The documented retry stays in the open step, prepares and reconciles the retained assembly again, and does not repeat pre-step or user admission. This is not the same as opening a new turn. The reference describes context-overflow recovery as one possible user of that hook; whether recovery advances enough to retry depends on the actual pruning or summarization result.

cancel(cause, options?) requests cancellation of active activity; the documented cause identifies the caller's intent. When there is no active activity, cancellation is a no-op and does not arm later work. Pending inbox handling depends on the options. An aborted turn records its reason on turn/end, but the exact event trail depends on how far execution progressed. For instance, cancellation while request preparation is asynchronous commits neither the pending system nor user messages for that admission.

DeepSeek Harness: when does the agent actually stop?

Returning to idle ends an activity interval, not the agent's owned lifetime. Follow-up work can wake the driver again. By contrast, the owner handle's dispose() stops the loop, awaits its exit, unregisters the agent, removes its session from the in-memory store, and unwinds the scoped world. The registered factory provider is also a structural owner: unloading it stops and drains the live handles it created. The core reference says disposal emits agent/disposed; disposal is not a terminal status value.

Do not equate removal from the live store with a documented deletion of persisted logs. Persistence is a separate concern. Similarly, followup() returns no result handle: the message identity tracks inbox facts rather than identifying a later answer. If the application needs a particular answer, it must correlate the relevant documented events and own its observation interval instead of interpreting whole-agent idle as a per-message receipt.

A practical diagnosis starts with the narrowest missing boundary. Was input inserted and claimed? Did the pre-step decision admit it? Was a step opened? Did the request settle as a message or attempt? Were tool results recorded? Finally, did the turn end and did the driver become idle? Each answer rules out a different class of assumption without requiring a guessed internal state.

DeepSeek Harness: what are the limits and safety boundaries?

Event names and ordering here describe the documented implementation and should be checked against the installed version and composition. Hooks can reject or modify proposed work; tool availability and approval behavior depend on the composed services. A visible stream or a completed turn does not establish that tool effects were appropriate or that the task succeeded.

Session events and diagnostics can contain user prompts, tool arguments and outputs. Review them for secrets or private information before sharing. Cancellation and disposal are lifecycle controls, not a promise that an external side effect has been undone; verify the affected system when the task may have changed it.

DeepSeek Harness: what do the terms mean?

  • Agent: the live actor that accepts input and drives work for a session.
  • Session: the typed, append-only event history from which model-facing history is derived.
  • Turn: one enclosed model-loop execution with an ending reason.
  • Step: one model call and any tool executions it requests.
  • Owner handle: the agent plus a disposer held by its creating consumer.
  • Quiescence: the whole-agent condition observed by whenIdle(), not a receipt for an individual prompt.

Frequently asked questions

Does idle mean disposed?

No. Idle ends an activity interval; the owner can later submit more work.

Can a turn have no step?

Yes. Rejection, an empty first batch or pre-step failure can leave a turn with no entered step.

Does whenIdle identify one message result?

No. It observes whole-agent quiescence.

Sources

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

  1. Agent lifecycle
  2. Sessions
  3. Core

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 Agent Lifecycle: Creation to Stop