DeepSeek Harness

DeepSeek Harness Plugin Extension Patterns

· 7 min read · 中文版

DeepSeek Harness extensions are Cordis plugins that contribute through services, events and reversible registrations. Choose the extension point for the job—tool, policy hook, UI or protocol driver—and match its lifecycle and contract.

DeepSeek Harness: What do the patterns have in common?

The extension cookbook maps product features to documented extension points. Its snippets omit imports or helper implementations and are not all copy-paste complete. The Cordis primer explains the shared structure: a context holds services, a plugin declares required services through inject, and registrations should have disposers so teardown and reload can unwind them.

A service method is a direct capability call; an event is appropriate for a documented interception or communication point. An event's dispatch mode is part of its contract. emit observes without a return value, waterfall is synchronous around-middleware, parallel awaits listeners in parallel, serial awaits them in order, and bail stops at a bail value. Read the actual event contract before choosing an interception point.

Choose a tool, hook, UI or protocol extension, then declare dependencies and manage its lifetime

DeepSeek Harness: Which extension shape fits the task?

NeedDocumented patternBoundary
Give the model an operationRegister a tool on ctx.toolsIts schema, execution and policy are separate concerns.
Intercept a tool callListen at the appropriate tool pipeline eventA hook is an ordinary plugin, not necessarily a permission gate.
Show live interactionCombine agent/assistant-stream with durable session/eventTransient frames and persisted events have different purposes.
Adapt an external peerA protocol driver maps requests to ctx.agentsAn enqueue receipt is not a completed response.
Supply a model adapterRegister an LlmAdapterFollow the adapter's specific contract rather than a tool example.

A plugin can combine mechanisms, but each registration still belongs to a scope and lifecycle. Start with the capability the consumer needs. For example, adding a tool for the model differs from observing the outcome of existing tools; a new tool definition is not a substitute for an outcome listener. For the tool authoring path, see develop an agent tool.

DeepSeek Harness: How do tool and hook patterns differ?

The cookbook says a tool registers on ctx.tools. defineTool is a typed helper for first-party definitions; ctx.tools.register() also accepts raw JSON Schema definitions, as for MCP-sourced tools. Read the dedicated tool guide for argument types, result construction and the background execution pattern. Registering a schema does not by itself decide the task's permission policy.

A hook intercepts an existing extension point. The cookbook's permission-gate example listens to tools/pre-execute and returns a typed denial when its policy rejects the call; otherwise it delegates with next(). In a Cordis waterfall, returning without next() short-circuits downstream listeners. Cooperative listeners that only annotate or observe should delegate. Hooks can target other events and need no external protocol merely to be native hooks.

The tool pipeline has distinct choices. The cookbook recommends ctx.tools.guard() for an invariant requiring a monotonic final denial; tools/execute wraps the dispatch lifetime for timeout, retry or metrics, and only exec.signal is replaceable there. Use tools/post-execute for explicit result transformation and tools/result for contained observation of the immutable final outcome. These are not interchangeable: a result observer should not be described as a policy gate, and a reorderable pre-execution listener is not the same contract as a final guard.

DeepSeek Harness: How do UI and protocol drivers handle events?

The UI pattern combines durable session/event records, such as assistant settlements and turn or step boundaries, with transient agent/assistant-stream frames for live text. Input goes back through agent.followup() or agent.steer(). For a business row in the built-in browser Chat, the cookbook points to a ConversationNodeDefinition and keyed renderer instead of treating an arbitrary UI as the same integration.

An external protocol driver adapts a wire peer to ctx.agents. A stdio driver owns stdout, creates or resumes agents through the factory and maps requests to operations such as followup() or cancel(). A low-level prompt request returns a durable enqueue receipt; the cookbook explicitly says not to correlate MessageId with turn/end as if that alone were the request's result. Publish whole-agent status separately. An automation method can deliberately wait from its receipt through the next idle and summarize that owned interval; a UI normally continues observing the open-ended event stream.

The ACP package is the cookbook's automation-only worked example. Its README specifies its actual methods, event ordering and lifecycle. Use AgentHandle.dispose() for teardown so disposal reaches quiescence. Do not infer that every driver has identical protocol methods or that an enqueue receipt proves the model completed its work.

DeepSeek Harness: How should you implement and verify a pattern?

  1. Identify the consumer and desired behavior: model-callable operation, interception, display, protocol transport or adapter. Find the exact service or event contract for that behavior.
  2. Declare the services the plugin requires through inject. Required dependencies allow the plugin to wait for services rather than relying on guessed boot order.
  3. Register the capability or listener with a lifecycle-aware disposer. Keep related work in one effect if teardown ordering matters.
  4. Exercise the intended behavior and its negative path. For a hook, verify delegation and the intended decision; for a UI, distinguish live frames from durable events; for a driver, distinguish receipt from completion.
  5. Dispose or reload the plugin and verify that its registrations and owned resources are unwound. Test the actual profile composition, because a source file alone does not prove its plugin is mounted.

The primer explains that ctx.effect() and helpers such as ctx.on() make registrations reversible. That supports orderly reload, but correctness still depends on what the plugin owns and on the precise event contract. Documenting expected cleanup makes it easier to test a repeated mount and avoid duplicated listeners or stale external resources.

DeepSeek Harness: What are the limits and safety boundaries?

The cookbook presents patterns, not complete implementations for every deployment. Its abbreviated examples do not establish a universal configuration, permission preset or transport security policy. Inspect the specific package documentation and the installed version before copying code.

Policy hooks and tool restrictions can affect access, but their mere presence does not make a system safe. Assess the intended authority, use the appropriate final guard when the invariant calls for it, and test failure and disposal paths. UI or protocol code must also treat incoming requests and output as data from its actual trust boundary; a registered plugin is executable code, not an endorsement.

DeepSeek Harness: What do the terms mean?

  • Context: the Cordis service repository available to a plugin.
  • Injection: a declaration of services a plugin needs before activation.
  • Waterfall: around-middleware in which next() delegates to the next listener.
  • Disposer: a function or effect cleanup that removes a registration or resource.
  • Enqueue receipt: confirmation of a durable queued prompt, not its completed result.

Frequently asked questions

Is every hook a permission gate?

No. Hook plugins can intercept other documented extension points.

Does a prompt receipt mean work is complete?

No. The documented low-level protocol request returns a durable enqueue receipt.

How are registrations cleaned up?

Use lifecycle-aware effects or helpers with disposers and verify the plugin releases its resources.

Sources

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

  1. Extension plugin shapes
  2. Cordis primer

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 Plugin Extension Patterns