defineModelTools
SUPPORT · function · Runtime value
Build a sealed capability catalog from typed declarations.
Import
ts
import { defineModelTools } from '@jangts/agent-core/support';js
import { defineModelTools } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.
Definition
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Definitions | readonly ModelToolRegistration[] | — |
Call
ts
defineModelTools<const Definitions extends readonly ModelToolRegistration[]>(definitions: Definitions): ModelToolCatalog<CapabilityOutput<Definitions[number]>>Build a sealed capability catalog from typed declarations.
| Type parameter | Constraint | Default type |
|---|---|---|
Definitions | readonly ModelToolRegistration[] | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
definitions | Definitions | Required | — |
Returns: ModelToolCatalog<CapabilityOutput<Definitions[number]>>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
definitions | readonly Readonly<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>>[] | Required | Read-only. Definitions in registration order; each entry is frozen by the implementation. |
ids | () => readonly string[] | Required | Ids in the same order as definitions. |
values | (() => IterableIterator<Readonly<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>>) | Required | See the type definition and usage context. |
entries | () => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>>]> | Required | See the type definition and usage context. |
has | (id: string) => boolean | Required | See the type definition and usage context. |
get | (id: string) => Readonly<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>> | undefined | Required | Returns the definition or undefined; the caller decides whether absence is an error. |
require | (id: string) => Readonly<Readonly<ModelTool<unknown, CapabilityOutput<Definitions[number]>, any>>> | Required | Returns the definition or throws; use when the id is a required reference. |
resolve | (selection: ModelSelection, context: Readonly<{ stageId: string; }>) => CapabilityOutput<Definitions[number]> | Required | Resolves one selection; throws when the capability is absent from this source. |
select | (ids: readonly string[], context?: unknown) => ModelToolCatalog<CapabilityOutput<Definitions[number]>> | Required | Explicit selection, optionally filtered against a host context. |
withIntent | (context: unknown) => ModelToolCatalog<CapabilityOutput<Definitions[number]>> | Required | Demand-facing active tools; no workflow node or invocation is implied. |
Examples
- 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.
Create a named text transport
Beginner · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);js
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);Generate transports for two stages from same-source tools
Configuration · Node.js
ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);Keep the tools and replace only the explicit interaction adapter
Extension · Node.js
Model calls still use invoke({input,transport}) and return ModelResult; switching interaction does not redesign business results.
ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'status', description: '查询服务状态', inputSchema, resolve: () => 'status' },
]);
const native = Support.createModelTransport({ id: 'native', tools });
const adapterId: keyof typeof Support.modelInteractionCatalog = 'json-object';
const json = Support.createModelTransport({ id: 'json', tools, adapter: Support.modelInteractionCatalog[adapterId] });
console.log(native.id, json.id);js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'status', description: '查询服务状态', inputSchema, resolve: () => 'status' },
]);
const native = Support.createModelTransport({ id: 'native', tools });
const adapterId = 'json-object';
const json = Support.createModelTransport({ id: 'json', tools, adapter: Support.modelInteractionCatalog[adapterId] });
console.log(native.id, json.id);Related policy source
- Stage list validation and dynamic source snapshots
- Explicit model interaction adapter catalog
- Session transport for prose and multiple tool calls