Skip to content
English

createIntentRegistry ​

KIT · function · 运行时值

Create and seal a complete catalog; use the constructor for incremental installation.

导入 ​

ts
import { createIntentRegistry } from '@jangts/agent-core/kits/domains';
js
import { createIntentRegistry } from '@jangts/agent-core/kits/domains';

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

定义 ​

泛型参数 ​

类型参数约束默认类型
DefinitionIntentToolRegistration—

调用 ​

ts
createIntentRegistry<Definition extends IntentToolRegistration>(definitions: Iterable<Definition>, policy?: IntentPolicy<Definition>): IntentRegistry<Definition>

Create and seal a complete catalog; use the constructor for incremental installation.

类型参数约束默认类型
DefinitionIntentToolRegistration—
参数类型传递说明
definitionsIterable<Definition>必需—
policyIntentPolicy<Definition>可省略—
policy 的字段
字段类型必需说明
idPatternRegExp | undefined可省略只读。Pattern every Tool id must match.
scopeModesreadonly string[] | undefined可省略只读。Allowed scopePolicy values; undefined accepts any value.
targetModesreadonly string[] | undefined可省略只读。Allowed targetPolicy values; undefined accepts any value.
contextTiersreadonly string[] | undefined可省略只读。Allowed contextTier values; undefined accepts any value.
actionsreadonly string[] | undefined可省略只读。Allowed planIntent values; undefined accepts any value.
delegatesreadonly string[] | undefined可省略只读。Allowed delegate ids; undefined accepts any non-empty delegate.
handoffValuesreadonly unknown[] | undefined可省略只读。Allowed preparedHandoff values; undefined accepts any value.
assertDefinition((definition: Definition) => void) | undefined可省略只读。Extra App assertion, called after the built-in checks; must return void synchronously.
tagsreadonly string[] | undefined可省略只读。Diagnostic tags attached to registration rejections.
errors{ readonly sealed?: BreakReason; readonly invalid?: BreakReason; readonly duplicate?: (goal: string) => Error | string; } | undefined可省略只读。见类型定义及调用场景。

返回: IntentRegistry<Definition>。

使用示例 ​

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

相关策略源码 ​

相关定义 ​

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