DeepSeek Harness: Develop an Agent Tool
A DeepSeek Harness agent tool is a registered plugin contribution with a validated input schema, a canonical JSON output and a cancellable execution body. Design those contracts together before adding presentation.
DeepSeek Harness: what does a new tool consist of?
The tool authoring reference shows a plugin that injects tools, calls ctx.tools.register(defineTool(...)) in apply, and supplies name, description, parameters, output and execute. Registration belongs to the plugin effect; disposing its fiber unregisters the tool. Schemas flow into system-prompt assembly. A tool must also be composed and visible in the deployment in which the agent runs; a source file alone is not proof that a model can call it.
The reference's minimal example reads a file, but direct filesystem access is not a complete production design for every environment. Start with a small, well-defined operation and identify its actual side effects. The execution pipeline applies policy and processing around the body; the tool author still owns the body and its domain constraints.
| Part | Responsibility | Design question |
|---|---|---|
parameters | Describe and validate model arguments | Which inputs and constraints are required? |
execute | Perform the operation and return its value | What side effects and cancellation are possible? |
output.schema | Describe the canonical JSON result | Can a program consume the result directly? |
output.render | Produce model-facing content | How should the value be explained? |
| Presentation metadata and views | Supply replayable UI facts | Which result facts must survive replay? |
DeepSeek Harness: how do you define inputs and outputs?
With defineTool, the registry validates model-generated arguments against ParameterSchemaSpec before execute: types, required keys, literal constraints, exact-one unions and nested values are covered. Explicit object nodes declare additionalProperties; the implicit parameter root stays open. The author must still check rules the DSL cannot express, such as a non-empty string, a positive number or a relationship between fields. A tool registered directly with raw JSON Schema owns its input validation.
The body returns the value described by output.schema, not a collection of content blocks. The schema can describe an object, array, scalar or null root. The registry snapshots the returned value as lossless JSON, validates and freezes it, then passes it to output.render(args, value). Return useful identifiers and fields as structured values instead of asking programmatic callers to parse prose. Rendering is where the human-readable explanation belongs.
Throws and invalid return values become isError; the registry also contains schema, renderer and metadata-projector failures. A successful domain result can still describe a non-ideal outcome: the reference gives a non-zero process exit as an example. Distinguish a successfully reported domain outcome from an infrastructure failure, and document what the caller should inspect.
DeepSeek Harness: what should the implementation respect?
Treat arguments as readonly. The registry materializes and freezes lossless JSON arguments before policy, and protects execution identity including callId, name, agent, token and caller-owned signal. Honor exec.signal to cancel in-flight foreground work. Do not mutate the registered definition's schema or replace callbacks after registration; to replace a tool, dispose the owning effect and register its replacement. Mutable state inside a callback closure remains ordinary plugin state.
If the operation needs background execution, the cookbook describes a different lifetime: a producer can use ctx.jobs.start, returning a typed handle after the job is published. Later outer-call cancellation stops waiting rather than killing that published job; job control and owner cleanup manage its lifetime. A pre-aborted call cannot honestly return a successful handle for a job that never started. Do not add a background option just because the foreground body might take time; first implement and test the owning runtime contract.
DeepSeek Harness: how do you build and verify the tool?
- Define the operation and its side effects. Write a model-facing description that tells the agent when the tool is useful and make required inputs explicit.
- Register a
defineToolcontribution in a plugin that injects the tools service. Confirm that the plugin is actually composed in the intended deployment and that the tool is visible to the caller. - Define
parameters, check constraints outside the schema DSL, and implementexecutewith cancellation. Make the return value matchoutput.schemafor both ordinary and meaningful domain outcomes. - Implement
output.renderfrom that value. If a result card needs durable facts, derive bounded JSON withoutput.presentationMeta; keep presentation functions pure so replay can reproduce them. - Exercise a valid call, invalid arguments, cancellation and an execution failure. Inspect the actual result through the shared pipeline, then follow the repository's testing policy and owning package requirements for a model- or UI-visible change.
The same visible registered tool is available in PTC mode as await tools.<name>(args), according to the authoring reference. Calls re-enter the ordinary pipeline and return the final canonical JSON value on success; failures reject with ToolCallError. That makes the output schema a programmatic contract as well as a basis for a model-facing rendering. A result that is easy for a person to read but cannot be consumed without parsing prose is a poor interface for that caller.
DeepSeek Harness: what are the limits and safety boundaries?
Policy should generally live in the appropriate pipeline extension rather than being assumed from a tool description. Registration and schema validation do not make a tool safe. They also cannot validate constraints that have not been expressed or checked. Consider what the body can read or change and review the effective permissions and execution environment.
The built-in Web Client does not consume Host presentCall or presentResult methods: specialized Web cards require the client-side slot described in the authoring reference. Host presenters alone do not create one. Presentation metadata is durable, so do not put unnecessary sensitive data in it. See pipeline integration for the placement of guards and result hooks.
DeepSeek Harness: which terms matter?
defineTool: typed tool-definition helper with schema validation and rendering contracts.- Canonical value: lossless JSON returned by the body and validated against the output schema.
output.render: projection of the value into model-facing content.exec.signal: cancellation signal for in-flight foreground execution.- Presentation metadata: durable JSON facts used to reconstruct a result view.
Frequently asked questions
What does execute return?
A canonical JSON value matching output.schema, which the registry validates and renders.
Does defineTool validate every domain rule?
No. Constraints outside the schema DSL still need explicit checks.
Does a Host presenter add a Web card?
No. The built-in Web Client requires its own client-side slot for a specialized card.
Sources
Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.
This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.