ScopeDefinition
KIT · interface · 类型合同
One declarable scope. Ids and aliases share one namespace and must be unique.
导入
ts
import type { ScopeDefinition } from '@jangts/agent-core/kits/domains';js
/** @typedef {import('@jangts/agent-core/kits/domains').ScopeDefinition} ScopeDefinition */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/domains、@jangts/agent-core/kits。
定义
ts
interface ScopeDefinition字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | Unique scope id, matched against the policy's idPattern when configured. |
description | string | 必需 | Non-blank description. |
category | string | 必需 | Scope category; validated against policy.categories when that is set. |
goalIds | readonly string[] | undefined | 可省略 | Goals this scope serves; required when the policy sets requireGoals. |
queryScopeIds | readonly string[] | undefined | 可省略 | Referenced query scopes, resolved by the App. |
knowledgeTopicIds | readonly string[] | undefined | 可省略 | Referenced knowledge topics, resolved by the App. |
toolIds | readonly string[] | undefined | 可省略 | Referenced tool ids; required when the policy sets requireTools. |
aliases | readonly string[] | undefined | 可省略 | Alternate names accepted by lookup; must not collide with ids or other aliases. |
contextTier | string | undefined | 可省略 | App-declared context tier, passed through for the App's own policy. |
evidence | readonly EvidenceRequirement[] | undefined | 可省略 | Evidence requirements that must be satisfied before this scope may answer. |
使用示例
- Domain Tools:Tool 声明与范围关系:同一清单提供可用 Tool、允许 delegate、范围别名、来源和工具关系。
先登记一个接口说明 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'));