Execution Control
Control tool execution behavior — results, timeout & retry, result compaction, and cancellation.
Tool Execution Results
Tool execution results are automatically serialized as strings and returned to the model. The tool() function internally handles result wrapping:
- On success: Returns
{ success: true, data: <result> } - On failure: Returns
{ success: false, error: "<error message>" }
Your execute function can return any type — string, object, number — deepseek-kit handles serialization automatically:
Timeout and Retry
Timeout
Set a timeout for tools that may take a long time to avoid waiting indefinitely. The default timeout is 60 seconds:
Retry
Configure automatic retry count for unreliable tools. When execution fails, deepseek-kit automatically retries until success or the maximum retry count is reached:
Timeout and retry can be combined — each retry is subject to the timeout limit:
Result Compaction
When tools return large outputs (e.g. file contents, API responses), the raw result can consume a significant portion of the model's context window. The compact option uses an LLM to compress verbose tool results while preserving all information the agent needs to continue reasoning.
Basic Usage
Enable compaction with default settings (threshold: 1500 characters, model: deepseek-v4-flash):
Custom Configuration
You can customize the compaction behavior by passing an object instead of true:
threshold(number, default 1500) — Minimum character length of a tool result before compaction is triggered. Results shorter than this are returned as-is.model(Model, default'deepseek-v4-flash') — The LLM used to compress content.
Compaction results are cached in memory. When the same tool is called repeatedly with identical arguments, the compacted result is served from cache instead of making another LLM call. If compaction fails for any reason, the original uncompressed result is returned — tool execution is never affected.
AbortSignal
deepseek-kit supports AbortSignal throughout the tool execution pipeline, allowing you to cancel in-progress tool calls. This is useful when users cancel requests or when you need to enforce time limits at the application level.
Usage with Agents
Pass a signal to generateText or agent.generate to enable cancellation:
When the signal is aborted:
- In-progress tool executions are cancelled immediately
- Pending retries are skipped
- The agent loop stops and throws an
AbortError
Integration with Timeout
AbortSignal works alongside the timeout option. The timeout acts as a per-attempt time limit, while AbortSignal provides external cancellation:

