Skip to content
English

Domain Tools:Tool 声明与范围关系 ​

同一清单提供可用 Tool、允许 delegate、范围别名、来源和工具关系。

IntentRegistry.create(definitions,policy?) 与 createIntentRegistry 创建并封存完整目录;new IntentRegistry(policy) 则允许 register/registerAll 后 seal。定义至少包含 id、description,可选 delegates 必须非空且无重复;asIntent 只描述该 Tool 参与需求识别的用途,不产生独立 Intent 实体。

ScopeRegistry 的定义还需 category;goalIds、queryScopeIds、knowledgeTopicIds、toolIds、aliases 缺省为空数组。它不替 App 推断关系。normalize 使用已登记别名,acceptsTool/acceptsQuery 检查关系,topics/evidence 返回声明。create 同样封存,构造器允许后续集中登记。相同数据在登记时形成只读快照,回调保留原接收者;App 服务仍由原实现访问。

描述和关系不是权限本身。模型看见某个 Tool 或资料范围,不意味着服务端已经授权工具。

由简到繁的同业务示例 ​

先登记一个接口说明 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'));

策略与实现 ​

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