Skip to content
中文

ModelToolCatalog ​

CORE · type · Type contract

A compiled entity catalog also supports the minimal stage source contract.

Import ​

ts
import type { ModelToolCatalog } from '@jangts/agent-core';
js
/** @typedef {import('@jangts/agent-core').ModelToolCatalog} ModelToolCatalog */

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

Type: ModelToolCatalog<Output>

Type expression
ts
type ModelToolCatalog<Output = unknown> = ReadonlyCatalog<RegisteredModelTool<Output>> &
  ModelToolSource<Output> & {
    /** Explicit selection, optionally filtered against a host context. */
    select(ids: readonly string[], context?: unknown): ModelToolCatalog<Output>;
    /** Demand-facing active tools; no workflow node or invocation is implied. */
    withIntent(context: unknown): ModelToolCatalog<Output>;
  };

Type parameters ​

Type parameterConstraintDefault type
Output—unknown

Field structure ​

FieldTypeRequiredDescription
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]RequiredRead-only. Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]RequiredIds in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>RequiredReturns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => OutputRequiredResolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>RequiredExplicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>RequiredDemand-facing active tools; no workflow node or invocation is implied.

Member index ​

MemberPurpose
idsIds in the same order as definitions.
valuesSee the overload below for full inputs and outputs.
entriesSee the overload below for full inputs and outputs.
hasSee the overload below for full inputs and outputs.
getReturns the definition or undefined; the caller decides whether absence is an error.
requireReturns the definition or throws; use when the id is a required reference.
resolveResolves one selection; throws when the capability is absent from this source.
selectExplicit selection, optionally filtered against a host context.
withIntentDemand-facing active tools; no workflow node or invocation is implied.

Member details ​

ids ​

Ids in the same order as definitions.

ts
ModelToolCatalog.ids(): readonly string[]

Ids in the same order as definitions.

No call parameters.

Returns: readonly string[].

values ​

ts
ModelToolCatalog.values(): IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>

No call parameters.

Returns: IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>.

entries ​

ts
ModelToolCatalog.entries(): IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>

No call parameters.

Returns: IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>.

has ​

ts
ModelToolCatalog.has(id: string): boolean
ParameterTypePassingDescription
idstringRequired—

Returns: boolean.

get ​

Returns the definition or undefined; the caller decides whether absence is an error.

ts
ModelToolCatalog.get(id: string): Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefined

Returns the definition or undefined; the caller decides whether absence is an error.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Readonly<ModelTool<unknown, Output, any>>> \| undefined.

Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
idstringRequiredRead-only. Unique id within its registry; never blank.
descriptionstringRequiredRead-only. Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>RequiredRead-only. Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => OutputRequiredConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.

require ​

Returns the definition or throws; use when the id is a required reference.

ts
ModelToolCatalog.require(id: string): Readonly<Readonly<ModelTool<unknown, Output, any>>>

Returns the definition or throws; use when the id is a required reference.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Readonly<ModelTool<unknown, Output, any>>>.

Return value structure
FieldTypeRequiredDescription
idstringRequiredRead-only. Unique id within its registry; never blank.
descriptionstringRequiredRead-only. Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>RequiredRead-only. Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => OutputRequiredConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.

resolve ​

Resolves one selection; throws when the capability is absent from this source.

ts
ModelToolCatalog.resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>): Output

Resolves one selection; throws when the capability is absent from this source.

ParameterTypePassingDescription
selectionModelSelectionRequired—
contextReadonly<{ stageId: string; }>Required—
Fields of selection
FieldTypeRequiredDescription
inputRecord<string, unknown>RequiredRead-only. Arguments exactly as produced by the model, before schema parsing.
call{ id: string; name: string; argumentChars: number; } | undefinedOptionalRead-only. Native function call that carried the selection, when the provider used one.
toolIdstringRequiredRead-only. Capability the selection resolved to.
Fields of context
FieldTypeRequiredDescription
stageIdstringRequiredSee the type definition and usage context.

Returns: Output.

Awaited value: Awaited<Output>.

select ​

Explicit selection, optionally filtered against a host context.

ts
ModelToolCatalog.select(ids: readonly string[], context?: unknown): ModelToolCatalog<Output>

Explicit selection, optionally filtered against a host context.

ParameterTypePassingDescription
idsreadonly string[]Required—
contextunknownOptional—

Returns: ModelToolCatalog<Output>.

Return value structure
FieldTypeRequiredDescription
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]RequiredRead-only. Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]RequiredIds in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>RequiredReturns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => OutputRequiredResolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>RequiredExplicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>RequiredDemand-facing active tools; no workflow node or invocation is implied.

withIntent ​

Demand-facing active tools; no workflow node or invocation is implied.

ts
ModelToolCatalog.withIntent(context: unknown): ModelToolCatalog<Output>

Demand-facing active tools; no workflow node or invocation is implied.

ParameterTypePassingDescription
contextunknownRequired—

Returns: ModelToolCatalog<Output>.

Return value structure
FieldTypeRequiredDescription
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]RequiredRead-only. Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]RequiredIds in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>RequiredReturns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => OutputRequiredResolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>RequiredExplicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>RequiredDemand-facing active tools; no workflow node or invocation is implied.

Examples ​

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);

API reference, usage examples and developer guides.