RegisteredModelTool
CORE · type · Type contract
Frozen snapshot stored by a registry after schema validation.
Import
ts
import type { RegisteredModelTool } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').RegisteredModelTool} RegisteredModelTool */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
Type: RegisteredModelTool<Output>
Type expression
ts
type RegisteredModelTool<Output = unknown> = Readonly<ModelTool<unknown, Output>>;Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Output | — | unknown |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique id within its registry; never blank. |
description | string | Required | Read-only. Model-visible description explaining when the capability applies. |
inputSchema | SchemaAdapter<unknown> | Required | Read-only. Schema describing the arguments; must be an object schema. |
active | ToolCondition<any> | undefined | Optional | Read-only. Omitted means active. Authorization remains a separate execution boundary. |
asIntent | AsIntent<any> | undefined | Optional | Read-only. Omitted means this tool is not advertised by withIntent(). |
resolve | (input: unknown, context: Readonly<{ stageId: string; }>) => Output | Required | Converts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection. |
Member index
| Member | Purpose |
|---|---|
resolve | Converts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection. |
Member details
resolve
Converts validated arguments into the value handed back to the caller.
Runs inside the model call, so it must return synchronously; throwing rejects the selection.
ts
RegisteredModelTool.resolve(input: unknown, context: Readonly<{ stageId: string; }>): OutputConverts validated arguments into the value handed back to the caller.
Runs inside the model call, so it must return synchronously; throwing rejects the selection.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | unknown | Required | — |
context | Readonly<{ stageId: string; }> | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | Required | See the type definition and usage context. |
Returns: Output.
Awaited value: Awaited<Output>.
Examples
- Model tools and transports: typed selection only after full validation: A tool definition provides a Schema and resolver; a transport translates wire output into the unified model selection contract.
- Tool best practice: one definition generates the model tool and execution runtime: Register Schema, authorization, execution, and output validation once, and bind the App per request instead of maintaining two tool lists.
- Model transport and stage projection: Generate a sealed catalog and stage projections from tool definitions; native functions and JSON adapters share the same tool contract.
Declare two selectable tools
Beginner · Node.js
ts
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new Error('需要空对象');
return {};
} };
const tools = new ModelToolRegistry([
{ id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));js
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new Error('需要空对象');
return {};
} };
const tools = new ModelToolRegistry([
{ id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));Project an allowed subset to only one stage
Configuration · Node.js
ts
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
parse(value: unknown) { if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
{ id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
{ id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());js
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
parse(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
{ id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
{ id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());Related policy source
- Authorization and model tool projection come from the same definition
- Stage list validation and dynamic source snapshots
- Explicit model interaction adapter catalog
- Session transport for prose and multiple tool calls