Skip to content
English

IntentTool ​

KIT · interface · 类型合同

One domain Tool.

导入 ​

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

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/domains、@jangts/agent-core/kits。

定义 ​

ts
interface IntentTool

继承或实现: ModelTool<any, any>。

字段结构 ​

字段类型必需说明
idstring必需Unique Tool id, matched against the policy's idPattern when configured.
descriptionstring必需Non-blank model-facing description.
delegatesreadonly string[] | undefined可省略Allowed delegate ids, retained in declaration order without imposing execution order; non-empty and unique.
scopePolicystring | undefined可省略App-declared scope-mode name; validated against policy.scopeModes when that is set.
targetPolicystring | undefined可省略App-declared target-mode name; validated against policy.targetModes when that is set.
contextTierstring | undefined可省略App-declared context tier; validated against policy.contextTiers when that is set.
planIntentstring | undefined可省略App-declared planning action; validated against policy.actions when that is set.
auxiliaryActionsreadonly string[] | undefined可省略Additional actions the intent may use; must be unique.
preparedHandoffunknown可省略App-declared handoff marker; validated against policy.handoffValues when that is set.
inputSchemaSchemaAdapter<any>必需只读。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; }>) => any必需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.

成员目录 ​

成员用途
resolveConverts 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 ​

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
IntentTool.resolve(input: any, context: Readonly<{ stageId: string; }>): any

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.

参数类型传递说明
inputany必需—
contextReadonly<{ stageId: string; }>必需—
context 的字段
字段类型必需说明
stageIdstring必需见类型定义及调用场景。

返回: any。

使用示例 ​

先登记一个接口说明 Tool ​

入门 · Node.js

ts
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = IntentRegistry.create([
  { id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: true },
]);
console.log(tools.ids(), tools.allows('explain', 'read'));
const scopes = ScopeRegistry.create([
  { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge' },
]);
console.log(scopes.require('sdk').knowledgeTopicIds);
js
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = IntentRegistry.create([
    { id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: true },
]);
console.log(tools.ids(), tools.allows('explain', 'read'));
const scopes = ScopeRegistry.create([
    { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge' },
]);
console.log(scopes.require('sdk').knowledgeTopicIds);

增加约束和范围关联,查询入口保持一致 ​

配置 · Node.js

ts
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = new IntentRegistry({ idPattern: /^[a-z-]+$/, delegates: ['read', 'reply'] })
  .registerAll([{ id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: '用户希望了解 SDK 接口或用法。' }]).seal();
const scopes = ScopeRegistry.create([
  { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge', aliases: ['agent-core'], goalIds: ['explain'], knowledgeTopicIds: ['manual'], toolIds: ['read-source'] },
], { categories: ['knowledge'], requireGoals: true, requireSources: true });
console.log(tools.describe(), scopes.normalize('agent-core'));
console.log(scopes.acceptsTool('agent-core', 'explain'), scopes.topics('sdk'));
js
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = new IntentRegistry({ idPattern: /^[a-z-]+$/, delegates: ['read', 'reply'] })
    .registerAll([{ id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: '用户希望了解 SDK 接口或用法。' }]).seal();
const scopes = ScopeRegistry.create([
    { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge', aliases: ['agent-core'], goalIds: ['explain'], knowledgeTopicIds: ['manual'], toolIds: ['read-source'] },
], { categories: ['knowledge'], requireGoals: true, requireSources: true });
console.log(tools.describe(), scopes.normalize('agent-core'));
console.log(scopes.acceptsTool('agent-core', 'explain'), scopes.topics('sdk'));

相关策略源码 ​

相关定义 ​

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