2026-07-16 18:13:34 +08:00
<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
# ctx.tools
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
`ToolRegistry` — provided by `@deepseek-ai/dsh-tools` .
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
Tool registry and execution pipeline. Scoped registrations shadow globals; one visibility resolver feeds presentation, lookup, and dispatch.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L378 )
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.tools.register(definition)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
```ts website-api
register(definition: ToolDefinition): () => void
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
Register globally or in the calling agent scope. Scoped tools shadow globals; duplicates within one layer and the reserved ` run_code` name fail.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
- ` definition` — the tool schema, execution, and optional presentation functions.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
**Returns** the exact disposer that unregisters the tool.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L468)
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
### ctx.tools.restrict(filter)
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-16 21:36:43 +08:00
restrict(filter: ToolRestriction): () => void
2026-07-09 16:07:58 +08:00
` ``
2026-07-16 21:36:43 +08:00
Restrict global tools for the calling agent scope. Empty filters, unknown names, scope-local names, and reserved transport names fail. Restrictions intersect; scoped registrations remain visible.
- ` filter` — global-surface mask: ` allow` (keep only) and/or ` deny` (remove).
**Returns** the exact disposer that lifts this restriction.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L508)
2026-07-16 21:36:43 +08:00
### ctx.tools.guard(guard)
` ``ts website-api
guard(guard: ToolGuard): () => void
` ``
Register a monotonic guard after the extensible ` tools/pre-execute` waterfall. A plain-context guard applies globally; one registered through ` agent.ctx` applies only to that agent. Any matching guard may deny by returning a reason, while no guard can force-allow a call another guard denied. The exact effect disposer is returned for ordered ownership and HMR cleanup.
- ` guard` — synchronous check; a returned string denies the execution.
**Returns** the exact disposer that unregisters the guard.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L559)
2026-07-16 21:36:43 +08:00
### ctx.tools.get(name, scope?)
` ``ts website-api
get(name: string, scope?: ScopeKey): ToolDefinition | undefined
` ``
Look up a tool as one scope sees it (scoped shadows global; a restricted-away global reads as absent). Presenters pass the calling agent so the rendered card matches the definition that actually executed.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` name` — the tool name as registered.
2026-07-16 21:36:43 +08:00
- ` scope` — the viewing scope (the agent); omitted = the global view.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
**Returns** the definition the scope resolves, or undefined when none is visible.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L661)
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
### ctx.tools.schemas(scope?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-16 21:36:43 +08:00
schemas(scope?: ScopeKey): ToolSchema[]
2026-07-09 16:07:58 +08:00
` ``
2026-07-16 21:36:43 +08:00
Project visible definitions onto the allowlisted model-facing schema fields, excluding execution and presentation callbacks.
- ` scope` — the viewing scope (the agent); omitted = the global view.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
**Returns** one deep-cloned schema per visible tool.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L671)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.tools.execute(exec)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-16 21:36:43 +08:00
async execute(exec: ToolExecutionInput): Promise<ToolExecutionResult>
2026-07-09 16:07:58 +08:00
` ``
2026-07-16 21:36:43 +08:00
Execute through pre-policy, guards, around-dispatch, post-policy, and final notification. Tool and listener failures resolve as materialized error results; an invisible tool reports ` UNKNOWN_TOOL`. The returned outcome is the same lossless, frozen snapshot final observers receive.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
- ` exec` — the typed same-process call input. The registry assigns its correlation token before policy begins.
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
**Returns ** the materialized final result.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/tools/src/index.ts#L694 )