Skip to content
English

ToolAssociation ​

SUPPORT · type · 类型合同

Explicit tool references or inline overrides of the owner's default model interface.

导入 ​

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

其他公开入口:@jangts/agent-core/support。

定义 ​

类型: ToolAssociation

类型表达式
ts
type ToolAssociation = string | Partial<ModelToolRegistration>;

联合分支结构 ​

ToolAssociation的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1

string

分支 2
字段类型必需说明
idstring | undefined可省略只读。Unique id within its registry; never blank.
descriptionstring | undefined可省略只读。Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<any> | undefined可省略只读。Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefined可省略只读。Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefined可省略只读。Omitted means this tool is not advertised by withIntent().
resolve((input: any, context: Readonly<{ stageId: string; }>) => unknown) | undefined可省略只读。见类型定义及调用场景。

使用示例 ​

直接复用现有模块声明 ​

入门 · Node.js

ts
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询能力', tools: [{ id: 'get_status' }] }];
const catalog = Support.defineCapabilityCatalog(modules);
console.log(catalog.ids(), catalog.findToolOwner('get_status')?.id);
js
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询能力', tools: [{ id: 'get_status' }] }];
const catalog = Support.defineCapabilityCatalog(modules);
console.log(catalog.ids(), catalog.findToolOwner('get_status')?.id);

增加工具引用和有序安装 ​

配置 · Node.js

ts
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询', tools: [{ id: 'get_status' }],
  references: [{ id: 'status-skill', requiredToolIds: ['get_status'], optionalToolIds: [] }] }];
const moduleCatalog = Support.defineCapabilityCatalog(modules, { toolReferences: module => module.references });
const registration = Support.defineRegistrationCatalog<{ installed: string[] }>([
  { id: 'service', register: app => { app.installed.push(moduleCatalog.require('service').id); } },
  { id: 'status-view', when: app => app.installed.includes('service'), register: app => { app.installed.push('status-view'); } },
]);
const app = { installed: [] as string[] };
registration.install(app);
console.log(app.installed);
js
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询', tools: [{ id: 'get_status' }],
        references: [{ id: 'status-skill', requiredToolIds: ['get_status'], optionalToolIds: [] }] }];
const moduleCatalog = Support.defineCapabilityCatalog(modules, { toolReferences: module => module.references });
const registration = Support.defineRegistrationCatalog([
    { id: 'service', register: app => { app.installed.push(moduleCatalog.require('service').id); } },
    { id: 'status-view', when: app => app.installed.includes('service'), register: app => { app.installed.push('status-view'); } },
]);
const app = { installed: [] };
registration.install(app);
console.log(app.installed);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。