DeepSeek Harness developing the first tool: defineTool
A tool is a function the Agent uses to do work; the model decides to call it after seeing the tool definition.
In this chapter we will use defineTool to write our first tool, greet, and make the model actually call it.
What is a tool
A tool is a clearly described function, including a name, description, parameters, and output format.
When generating a reply, the model can initiate a call based on this information.
In dsh, tools are registered to the tool registry via ctx.tools.register.
The complete structure of defineTool
defineTool is a DSL for defining tools; it takes an object describing all the tool's information.
| Field | Purpose | Description |
|---|---|---|
| name | Tool name | The model uses it to initiate calls |
| description | Tool description | Tells the model what this tool does |
| parameters | Input parameter schema | A typed definition from which defineTool infers and validates args |
| output.schema | Return value schema | Declares the canonical value type returned by execute |
| output.render | Result formatting | Converts the canonical value into model-facing content |
| execute | Tool implementation | The actual execution logic, returning a canonical value |
Creating the greet tool
Replace scratch-plugin/src/my-plugin.ts with the following content.
Example
// File path: scratch-plugin/src/my-plugin.ts
import
type
{
Context
}
from
'@deepseek-ai/cordis'
import
{
defineTool
}
from
'@deepseek-ai/dsh-tools'
export
const
name
=
'greet-tool'
// Requires the tools service: a prerequisite for registering tools
export
const
inject
=
[
'tools'
]
export
function
apply
(
ctx
:
Context
)
{
// Register a tool named greet
ctx.
tools
.
register
(
defineTool
(
{
// Tool name: the model will call it by this name
name
:
'greet'
,
// Tool description: tells the model when to use it
description
:
'Greet someone by name.'
,
// Input schema: defineTool will infer and validate args
parameters
:
{
name
:
{
type
:
'string'
,
required
:
true
,
description
:
'The name to greet'
}
,
}
,
// Output definition
output
:
{
// Canonical value type: the return value of execute
schema
:
{
type
:
'string'
}
,
// render: converts the canonical value into model-facing content
render
:
(
_args
,
value
)
=>
[
{
type
:
'text'
,
text
:
value
}
]
,
}
,
// Tool implementation: the actual execution logic
async execute
(
args
)
{
// Returns a canonical value, here a string
return
`Hello
,
$
{
args.
name
}
!
`
}
,
}
)
)
}
inject makes Cordis wait until the tool registry is ready.
defineTool infers and validates args from parameters.
execute returns the canonical value declared by output.schema.
output.render then converts the canonical value into model-facing content.

Running and calling
If the dev command is not running, restart it:
pnpm dsh web --patch ./scratch-plugin/cordis.yml
Open http://127.0.0.1:3080 and enter:
Use the greet tool to greet RUNOOB.

The model can call greet and receive "Hello, RUNOOB!" as the tool result.
Key point: the schema automatically flows into the prompt
The tool's name, description, parameters, and output are automatically assembled into the model prompt.
The model "knows" such a tool exists and will call it when appropriate.
You do not need to hand-write a function signature for the model; the schema is the interface the model sees.
Canonical value(canonical value) is the value returned by execute and declared by output.schema.
It is decoupled from "model-facing content": the same canonical value can become different formats through different renders.
Tip: to see more complex tool-writing patterns (nested schemas, background work, policy hooks), see the official tool-writing reference.
Summary and self-test
defineTool describes the tool with a schema, ctx.tools.register registers it, and the model calls it directly after seeing the schema.
1. What does defineTool's execute return?
2. What is the role of output.render?
3. How does the model know to call greet?