@framers/agentos 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels/adapters/GoogleChatChannelAdapter.d.ts.map +1 -1
- package/dist/channels/adapters/GoogleChatChannelAdapter.js +1 -3
- package/dist/channels/adapters/GoogleChatChannelAdapter.js.map +1 -1
- package/dist/channels/adapters/TeamsChannelAdapter.d.ts.map +1 -1
- package/dist/channels/adapters/TeamsChannelAdapter.js +1 -3
- package/dist/channels/adapters/TeamsChannelAdapter.js.map +1 -1
- package/dist/core/tools/IToolOrchestrator.d.ts +17 -0
- package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolOrchestrator.d.ts +13 -0
- package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -1
- package/dist/core/tools/ToolOrchestrator.js +28 -0
- package/dist/core/tools/ToolOrchestrator.js.map +1 -1
- package/dist/discovery/CapabilityContextAssembler.d.ts +54 -0
- package/dist/discovery/CapabilityContextAssembler.d.ts.map +1 -0
- package/dist/discovery/CapabilityContextAssembler.js +192 -0
- package/dist/discovery/CapabilityContextAssembler.js.map +1 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts +76 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts.map +1 -0
- package/dist/discovery/CapabilityDiscoveryEngine.js +197 -0
- package/dist/discovery/CapabilityDiscoveryEngine.js.map +1 -0
- package/dist/discovery/CapabilityEmbeddingStrategy.d.ts +45 -0
- package/dist/discovery/CapabilityEmbeddingStrategy.d.ts.map +1 -0
- package/dist/discovery/CapabilityEmbeddingStrategy.js +167 -0
- package/dist/discovery/CapabilityEmbeddingStrategy.js.map +1 -0
- package/dist/discovery/CapabilityGraph.d.ts +78 -0
- package/dist/discovery/CapabilityGraph.d.ts.map +1 -0
- package/dist/discovery/CapabilityGraph.js +263 -0
- package/dist/discovery/CapabilityGraph.js.map +1 -0
- package/dist/discovery/CapabilityIndex.d.ts +93 -0
- package/dist/discovery/CapabilityIndex.d.ts.map +1 -0
- package/dist/discovery/CapabilityIndex.js +324 -0
- package/dist/discovery/CapabilityIndex.js.map +1 -0
- package/dist/discovery/CapabilityManifestScanner.d.ts +66 -0
- package/dist/discovery/CapabilityManifestScanner.d.ts.map +1 -0
- package/dist/discovery/CapabilityManifestScanner.js +315 -0
- package/dist/discovery/CapabilityManifestScanner.js.map +1 -0
- package/dist/discovery/DiscoverCapabilitiesTool.d.ts +44 -0
- package/dist/discovery/DiscoverCapabilitiesTool.d.ts.map +1 -0
- package/dist/discovery/DiscoverCapabilitiesTool.js +118 -0
- package/dist/discovery/DiscoverCapabilitiesTool.js.map +1 -0
- package/dist/discovery/index.d.ts +39 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +41 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/types.d.ts +357 -0
- package/dist/discovery/types.d.ts.map +1 -0
- package/dist/discovery/types.js +46 -0
- package/dist/discovery/types.js.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Capability Context Assembler — tiered, token-budgeted context builder.
|
|
3
|
+
* @module @framers/agentos/discovery/CapabilityContextAssembler
|
|
4
|
+
*
|
|
5
|
+
* Assembles the capability discovery context for injection into agent prompts.
|
|
6
|
+
* Enforces hard token budgets per tier to prevent context rot.
|
|
7
|
+
*
|
|
8
|
+
* Three tiers (inspired by Anthropic's defer_loading + Redis Tool RAG):
|
|
9
|
+
*
|
|
10
|
+
* Tier 0 (~150 tokens): Category summaries — always in context
|
|
11
|
+
* "Available categories: Information (4), Developer (3), Communication (8)..."
|
|
12
|
+
*
|
|
13
|
+
* Tier 1 (~200 tokens): Retrieved summaries — per-turn semantic retrieval
|
|
14
|
+
* "1. web-search (tool, 0.87): Search web. Params: query, max_results"
|
|
15
|
+
*
|
|
16
|
+
* Tier 2 (~1500 tokens): Full details — top-2 most relevant capabilities
|
|
17
|
+
* Full JSON schema or SKILL.md content
|
|
18
|
+
*
|
|
19
|
+
* Token budgets are hard-enforced by the assembler, NOT the LLM.
|
|
20
|
+
* This is critical for preventing context rot (Chroma 2025).
|
|
21
|
+
*/
|
|
22
|
+
import { DEFAULT_DISCOVERY_CONFIG } from './types.js';
|
|
23
|
+
import { CapabilityEmbeddingStrategy } from './CapabilityEmbeddingStrategy.js';
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// CONTEXT ASSEMBLER
|
|
26
|
+
// ============================================================================
|
|
27
|
+
export class CapabilityContextAssembler {
|
|
28
|
+
constructor(strategy) {
|
|
29
|
+
this.cachedTier0 = null;
|
|
30
|
+
this.cachedTier0Version = 0;
|
|
31
|
+
this.strategy = strategy ?? new CapabilityEmbeddingStrategy();
|
|
32
|
+
}
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// TIER 0: CATEGORY SUMMARIES
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Build Tier 0 category summary text.
|
|
38
|
+
* Regenerated only when capabilities change (tracked by version).
|
|
39
|
+
*/
|
|
40
|
+
buildTier0(capabilities, version) {
|
|
41
|
+
if (this.cachedTier0 && this.cachedTier0Version === version) {
|
|
42
|
+
return this.cachedTier0;
|
|
43
|
+
}
|
|
44
|
+
// Group by category
|
|
45
|
+
const categories = new Map();
|
|
46
|
+
for (const cap of capabilities) {
|
|
47
|
+
const cat = cap.category || 'other';
|
|
48
|
+
const entry = categories.get(cat) ?? { names: [], count: 0 };
|
|
49
|
+
entry.names.push(cap.name);
|
|
50
|
+
entry.count++;
|
|
51
|
+
categories.set(cat, entry);
|
|
52
|
+
}
|
|
53
|
+
// Sort categories by count descending
|
|
54
|
+
const sorted = Array.from(categories.entries()).sort((a, b) => b[1].count - a[1].count);
|
|
55
|
+
const lines = ['Available capability categories:'];
|
|
56
|
+
for (const [category, { names, count }] of sorted) {
|
|
57
|
+
// Show first 4 names, then count
|
|
58
|
+
const displayNames = names.slice(0, 4).join(', ');
|
|
59
|
+
const suffix = count > 4 ? ` (+${count - 4} more)` : '';
|
|
60
|
+
lines.push(`- ${capitalize(category)}: ${displayNames}${suffix} (${count})`);
|
|
61
|
+
}
|
|
62
|
+
lines.push('Use discover_capabilities tool to get details on any capability.');
|
|
63
|
+
const text = lines.join('\n');
|
|
64
|
+
this.cachedTier0 = text;
|
|
65
|
+
this.cachedTier0Version = version;
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// ASSEMBLY
|
|
70
|
+
// ============================================================================
|
|
71
|
+
/**
|
|
72
|
+
* Assemble discovery context from search results.
|
|
73
|
+
*
|
|
74
|
+
* Takes raw search results (already filtered and graph-reranked),
|
|
75
|
+
* applies token budgets, and produces the final tiered result.
|
|
76
|
+
*/
|
|
77
|
+
assemble(tier0Text, searchResults, config = DEFAULT_DISCOVERY_CONFIG, timings) {
|
|
78
|
+
const startTime = performance.now();
|
|
79
|
+
// --- Tier 0 ---
|
|
80
|
+
const tier0Tokens = estimateTokens(tier0Text);
|
|
81
|
+
// --- Tier 1: Build compact summaries within budget ---
|
|
82
|
+
const tier1 = [];
|
|
83
|
+
let tier1Tokens = 0;
|
|
84
|
+
const tier1Header = 'Relevant capabilities:\n';
|
|
85
|
+
tier1Tokens += estimateTokens(tier1Header);
|
|
86
|
+
const tier1Candidates = searchResults
|
|
87
|
+
.filter((r) => r.score >= config.tier1MinRelevance)
|
|
88
|
+
.slice(0, config.tier1TopK);
|
|
89
|
+
for (const candidate of tier1Candidates) {
|
|
90
|
+
const summary = this.strategy.buildCompactSummary(candidate.descriptor);
|
|
91
|
+
const lineText = `${tier1.length + 1}. ${summary}`;
|
|
92
|
+
const lineTokens = estimateTokens(lineText);
|
|
93
|
+
if (tier1Tokens + lineTokens > config.tier1TokenBudget)
|
|
94
|
+
break;
|
|
95
|
+
tier1Tokens += lineTokens;
|
|
96
|
+
tier1.push({
|
|
97
|
+
capability: candidate.descriptor,
|
|
98
|
+
relevanceScore: candidate.score,
|
|
99
|
+
summaryText: lineText,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// --- Tier 2: Full details within budget ---
|
|
103
|
+
const tier2 = [];
|
|
104
|
+
let tier2Tokens = 0;
|
|
105
|
+
// Take top N from Tier 1 for full expansion
|
|
106
|
+
const tier2Candidates = tier1.slice(0, config.tier2TopK);
|
|
107
|
+
for (const candidate of tier2Candidates) {
|
|
108
|
+
const fullText = this.strategy.buildFullDetailText(candidate.capability);
|
|
109
|
+
const fullTokens = estimateTokens(fullText);
|
|
110
|
+
if (tier2Tokens + fullTokens > config.tier2TokenBudget)
|
|
111
|
+
break;
|
|
112
|
+
tier2Tokens += fullTokens;
|
|
113
|
+
tier2.push({
|
|
114
|
+
capability: candidate.capability,
|
|
115
|
+
fullText,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const totalTokens = tier0Tokens + tier1Tokens + tier2Tokens;
|
|
119
|
+
const queryTimeMs = performance.now() - startTime;
|
|
120
|
+
return {
|
|
121
|
+
tier0: tier0Text,
|
|
122
|
+
tier1,
|
|
123
|
+
tier2,
|
|
124
|
+
tokenEstimate: {
|
|
125
|
+
tier0Tokens,
|
|
126
|
+
tier1Tokens,
|
|
127
|
+
tier2Tokens,
|
|
128
|
+
totalTokens,
|
|
129
|
+
},
|
|
130
|
+
diagnostics: {
|
|
131
|
+
queryTimeMs,
|
|
132
|
+
embeddingTimeMs: timings?.embeddingTimeMs ?? 0,
|
|
133
|
+
graphTraversalTimeMs: timings?.graphTraversalTimeMs ?? 0,
|
|
134
|
+
candidatesScanned: searchResults.length,
|
|
135
|
+
capabilitiesRetrieved: tier1.length + tier2.length,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Render a CapabilityDiscoveryResult into a single string
|
|
141
|
+
* suitable for injection into PromptBuilder.
|
|
142
|
+
*/
|
|
143
|
+
renderForPrompt(result) {
|
|
144
|
+
const parts = [];
|
|
145
|
+
// Tier 0: Always present
|
|
146
|
+
parts.push(result.tier0);
|
|
147
|
+
// Tier 1: Retrieved summaries
|
|
148
|
+
if (result.tier1.length > 0) {
|
|
149
|
+
parts.push('');
|
|
150
|
+
parts.push('Relevant capabilities:');
|
|
151
|
+
for (const item of result.tier1) {
|
|
152
|
+
parts.push(item.summaryText);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Tier 2: Full details
|
|
156
|
+
if (result.tier2.length > 0) {
|
|
157
|
+
parts.push('');
|
|
158
|
+
parts.push('--- Detailed Capability Reference ---');
|
|
159
|
+
for (const item of result.tier2) {
|
|
160
|
+
parts.push('');
|
|
161
|
+
parts.push(item.fullText);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return parts.join('\n');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Invalidate the Tier 0 cache (e.g., after capabilities change).
|
|
168
|
+
*/
|
|
169
|
+
invalidateCache() {
|
|
170
|
+
this.cachedTier0 = null;
|
|
171
|
+
this.cachedTier0Version = 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// ============================================================================
|
|
175
|
+
// HELPERS
|
|
176
|
+
// ============================================================================
|
|
177
|
+
/**
|
|
178
|
+
* Rough token estimation (~4 chars per token for English text).
|
|
179
|
+
* Used for budget enforcement — not exact, but close enough for budgeting.
|
|
180
|
+
*/
|
|
181
|
+
function estimateTokens(text) {
|
|
182
|
+
return Math.ceil(text.length / 4);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Capitalize the first letter of a string.
|
|
186
|
+
*/
|
|
187
|
+
function capitalize(s) {
|
|
188
|
+
if (!s)
|
|
189
|
+
return s;
|
|
190
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=CapabilityContextAssembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityContextAss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CAAC;QAED,uBAAuB;QACvB,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;YACpD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,eAAe;QACb,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACjB,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Capability Discovery Engine — main orchestrator.
|
|
3
|
+
* @module @framers/agentos/discovery/CapabilityDiscoveryEngine
|
|
4
|
+
*
|
|
5
|
+
* Coordinates the capability index, relationship graph, and context assembler
|
|
6
|
+
* to provide tiered, semantic capability discovery for AgentOS agents.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* User Message → CapabilityIndex.search() → CapabilityGraph.rerank()
|
|
10
|
+
* → CapabilityContextAssembler.assemble() → CapabilityDiscoveryResult
|
|
11
|
+
*
|
|
12
|
+
* Performance targets:
|
|
13
|
+
* - Initialize: ~3s (one-time embedding generation for ~100 capabilities)
|
|
14
|
+
* - Per-turn discover(): ~50ms cold (embedding) / ~5ms warm (cache hit)
|
|
15
|
+
* - Context tokens: ~1,850 (down from ~20,000 with static dumps)
|
|
16
|
+
*/
|
|
17
|
+
import type { IEmbeddingManager } from '../rag/IEmbeddingManager.js';
|
|
18
|
+
import type { IVectorStore } from '../rag/IVectorStore.js';
|
|
19
|
+
import type { CapabilityDiscoveryConfig, CapabilityDiscoveryResult, CapabilityDescriptor, CapabilityIndexSources, DiscoveryQueryOptions, ICapabilityDiscoveryEngine, PresetCoOccurrence } from './types.js';
|
|
20
|
+
export declare class CapabilityDiscoveryEngine implements ICapabilityDiscoveryEngine {
|
|
21
|
+
private readonly index;
|
|
22
|
+
private readonly graph;
|
|
23
|
+
private readonly assembler;
|
|
24
|
+
private readonly config;
|
|
25
|
+
private indexVersion;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(embeddingManager: IEmbeddingManager, vectorStore: IVectorStore, config?: Partial<CapabilityDiscoveryConfig>);
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the engine: build index + graph from all capability sources.
|
|
30
|
+
*
|
|
31
|
+
* @param sources - Tools, skills, extensions, channels, and manifest entries
|
|
32
|
+
* @param presetCoOccurrences - Co-occurrence data from agent presets
|
|
33
|
+
*/
|
|
34
|
+
initialize(sources: CapabilityIndexSources, presetCoOccurrences?: PresetCoOccurrence[]): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Discover capabilities relevant to a user message.
|
|
37
|
+
*
|
|
38
|
+
* Flow:
|
|
39
|
+
* 1. Semantic search against capability embeddings
|
|
40
|
+
* 2. Graph-based re-ranking (boost related capabilities)
|
|
41
|
+
* 3. Token-budgeted tiered assembly
|
|
42
|
+
*
|
|
43
|
+
* Returns a CapabilityDiscoveryResult with Tier 0/1/2 context.
|
|
44
|
+
*/
|
|
45
|
+
discover(userMessage: string, options?: DiscoveryQueryOptions): Promise<CapabilityDiscoveryResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Get full detail for a specific capability by ID.
|
|
48
|
+
*/
|
|
49
|
+
getCapabilityDetail(id: string): CapabilityDescriptor | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Refresh the index incrementally.
|
|
52
|
+
* Called when manifest files change or new capabilities are added at runtime.
|
|
53
|
+
*/
|
|
54
|
+
refreshIndex(sources?: Partial<CapabilityIndexSources>): Promise<void>;
|
|
55
|
+
isInitialized(): boolean;
|
|
56
|
+
listCapabilityIds(): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Get the current configuration.
|
|
59
|
+
*/
|
|
60
|
+
getConfig(): Readonly<CapabilityDiscoveryConfig>;
|
|
61
|
+
/**
|
|
62
|
+
* Get index statistics.
|
|
63
|
+
*/
|
|
64
|
+
getStats(): {
|
|
65
|
+
capabilityCount: number;
|
|
66
|
+
graphNodes: number;
|
|
67
|
+
graphEdges: number;
|
|
68
|
+
indexVersion: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Render a discovery result into a string suitable for prompt injection.
|
|
72
|
+
*/
|
|
73
|
+
renderForPrompt(result: CapabilityDiscoveryResult): string;
|
|
74
|
+
private emptyResult;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=CapabilityDiscoveryEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityDiscoveryEngine.d.ts","sourceRoot":"","sources":["../../src/discovery/CapabilityDiscoveryEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;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AAC;KACtB;IASD;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,yBAAyB,GAAG,MAAM;IAQ1D,OAAO,CAAC,WAAW;CAoBpB"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Capability Discovery Engine — main orchestrator.
|
|
3
|
+
* @module @framers/agentos/discovery/CapabilityDiscoveryEngine
|
|
4
|
+
*
|
|
5
|
+
* Coordinates the capability index, relationship graph, and context assembler
|
|
6
|
+
* to provide tiered, semantic capability discovery for AgentOS agents.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* User Message → CapabilityIndex.search() → CapabilityGraph.rerank()
|
|
10
|
+
* → CapabilityContextAssembler.assemble() → CapabilityDiscoveryResult
|
|
11
|
+
*
|
|
12
|
+
* Performance targets:
|
|
13
|
+
* - Initialize: ~3s (one-time embedding generation for ~100 capabilities)
|
|
14
|
+
* - Per-turn discover(): ~50ms cold (embedding) / ~5ms warm (cache hit)
|
|
15
|
+
* - Context tokens: ~1,850 (down from ~20,000 with static dumps)
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_DISCOVERY_CONFIG } from './types.js';
|
|
18
|
+
import { CapabilityIndex } from './CapabilityIndex.js';
|
|
19
|
+
import { CapabilityGraph } from './CapabilityGraph.js';
|
|
20
|
+
import { CapabilityContextAssembler } from './CapabilityContextAssembler.js';
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// CAPABILITY DISCOVERY ENGINE
|
|
23
|
+
// ============================================================================
|
|
24
|
+
export class CapabilityDiscoveryEngine {
|
|
25
|
+
constructor(embeddingManager, vectorStore, config) {
|
|
26
|
+
this.indexVersion = 0;
|
|
27
|
+
this.initialized = false;
|
|
28
|
+
this.config = { ...DEFAULT_DISCOVERY_CONFIG, ...config };
|
|
29
|
+
this.index = new CapabilityIndex(embeddingManager, vectorStore, this.config.collectionName, this.config.embeddingModelId);
|
|
30
|
+
this.graph = new CapabilityGraph();
|
|
31
|
+
this.assembler = new CapabilityContextAssembler(this.index.getEmbeddingStrategy());
|
|
32
|
+
}
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// INITIALIZATION
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the engine: build index + graph from all capability sources.
|
|
38
|
+
*
|
|
39
|
+
* @param sources - Tools, skills, extensions, channels, and manifest entries
|
|
40
|
+
* @param presetCoOccurrences - Co-occurrence data from agent presets
|
|
41
|
+
*/
|
|
42
|
+
async initialize(sources, presetCoOccurrences) {
|
|
43
|
+
// 1. Build the vector index (normalizes sources + embeds + stores)
|
|
44
|
+
await this.index.buildIndex(sources);
|
|
45
|
+
// 2. Build the relationship graph
|
|
46
|
+
const allCapabilities = this.index.getAllCapabilities();
|
|
47
|
+
this.graph.buildGraph(allCapabilities, presetCoOccurrences);
|
|
48
|
+
this.indexVersion++;
|
|
49
|
+
this.initialized = true;
|
|
50
|
+
}
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// DISCOVERY
|
|
53
|
+
// ============================================================================
|
|
54
|
+
/**
|
|
55
|
+
* Discover capabilities relevant to a user message.
|
|
56
|
+
*
|
|
57
|
+
* Flow:
|
|
58
|
+
* 1. Semantic search against capability embeddings
|
|
59
|
+
* 2. Graph-based re-ranking (boost related capabilities)
|
|
60
|
+
* 3. Token-budgeted tiered assembly
|
|
61
|
+
*
|
|
62
|
+
* Returns a CapabilityDiscoveryResult with Tier 0/1/2 context.
|
|
63
|
+
*/
|
|
64
|
+
async discover(userMessage, options) {
|
|
65
|
+
if (!this.initialized) {
|
|
66
|
+
return this.emptyResult();
|
|
67
|
+
}
|
|
68
|
+
const queryConfig = { ...this.config, ...options?.config };
|
|
69
|
+
const embeddingStart = performance.now();
|
|
70
|
+
// 1. Semantic search
|
|
71
|
+
// Retrieve more candidates than needed for graph re-ranking to work effectively
|
|
72
|
+
const searchTopK = queryConfig.tier1TopK * 2;
|
|
73
|
+
const searchResults = await this.index.search(userMessage, searchTopK, {
|
|
74
|
+
kind: options?.kind,
|
|
75
|
+
category: options?.category,
|
|
76
|
+
onlyAvailable: options?.onlyAvailable,
|
|
77
|
+
});
|
|
78
|
+
const embeddingTimeMs = performance.now() - embeddingStart;
|
|
79
|
+
// 2. Graph-based re-ranking
|
|
80
|
+
let finalResults = searchResults;
|
|
81
|
+
let graphTraversalTimeMs = 0;
|
|
82
|
+
if (queryConfig.useGraphReranking && searchResults.length > 0) {
|
|
83
|
+
const graphStart = performance.now();
|
|
84
|
+
const reranked = this.graph.rerank(searchResults.map((r) => ({ id: r.descriptor.id, score: r.score })), queryConfig.graphBoostFactor);
|
|
85
|
+
// Map back to CapabilitySearchResult format
|
|
86
|
+
finalResults = reranked
|
|
87
|
+
.map((r) => {
|
|
88
|
+
const descriptor = this.index.getCapability(r.id);
|
|
89
|
+
if (!descriptor)
|
|
90
|
+
return null;
|
|
91
|
+
return { descriptor, score: r.score };
|
|
92
|
+
})
|
|
93
|
+
.filter((r) => r !== null);
|
|
94
|
+
graphTraversalTimeMs = performance.now() - graphStart;
|
|
95
|
+
}
|
|
96
|
+
// 3. Build Tier 0 category summary
|
|
97
|
+
const tier0 = this.assembler.buildTier0(this.index.getAllCapabilities(), this.indexVersion);
|
|
98
|
+
// 4. Assemble tiered result with token budgets
|
|
99
|
+
return this.assembler.assemble(tier0, finalResults, queryConfig, {
|
|
100
|
+
embeddingTimeMs,
|
|
101
|
+
graphTraversalTimeMs,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// ============================================================================
|
|
105
|
+
// DETAIL ACCESS
|
|
106
|
+
// ============================================================================
|
|
107
|
+
/**
|
|
108
|
+
* Get full detail for a specific capability by ID.
|
|
109
|
+
*/
|
|
110
|
+
getCapabilityDetail(id) {
|
|
111
|
+
return this.index.getCapability(id);
|
|
112
|
+
}
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// INDEX MANAGEMENT
|
|
115
|
+
// ============================================================================
|
|
116
|
+
/**
|
|
117
|
+
* Refresh the index incrementally.
|
|
118
|
+
* Called when manifest files change or new capabilities are added at runtime.
|
|
119
|
+
*/
|
|
120
|
+
async refreshIndex(sources) {
|
|
121
|
+
if (!sources)
|
|
122
|
+
return;
|
|
123
|
+
// Normalize and upsert new sources
|
|
124
|
+
const fullSources = {
|
|
125
|
+
tools: sources.tools,
|
|
126
|
+
skills: sources.skills,
|
|
127
|
+
extensions: sources.extensions,
|
|
128
|
+
channels: sources.channels,
|
|
129
|
+
manifests: sources.manifests,
|
|
130
|
+
};
|
|
131
|
+
const newDescriptors = this.index.normalizeSources(fullSources);
|
|
132
|
+
for (const desc of newDescriptors) {
|
|
133
|
+
await this.index.upsertCapability(desc);
|
|
134
|
+
}
|
|
135
|
+
// Rebuild graph with all capabilities
|
|
136
|
+
const allCapabilities = this.index.getAllCapabilities();
|
|
137
|
+
this.graph.buildGraph(allCapabilities);
|
|
138
|
+
this.indexVersion++;
|
|
139
|
+
this.assembler.invalidateCache();
|
|
140
|
+
}
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// ACCESSORS
|
|
143
|
+
// ============================================================================
|
|
144
|
+
isInitialized() {
|
|
145
|
+
return this.initialized;
|
|
146
|
+
}
|
|
147
|
+
listCapabilityIds() {
|
|
148
|
+
return this.index.listIds();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the current configuration.
|
|
152
|
+
*/
|
|
153
|
+
getConfig() {
|
|
154
|
+
return this.config;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get index statistics.
|
|
158
|
+
*/
|
|
159
|
+
getStats() {
|
|
160
|
+
return {
|
|
161
|
+
capabilityCount: this.index.size(),
|
|
162
|
+
graphNodes: this.graph.nodeCount(),
|
|
163
|
+
graphEdges: this.graph.edgeCount(),
|
|
164
|
+
indexVersion: this.indexVersion,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Render a discovery result into a string suitable for prompt injection.
|
|
169
|
+
*/
|
|
170
|
+
renderForPrompt(result) {
|
|
171
|
+
return this.assembler.renderForPrompt(result);
|
|
172
|
+
}
|
|
173
|
+
// ============================================================================
|
|
174
|
+
// INTERNAL
|
|
175
|
+
// ============================================================================
|
|
176
|
+
emptyResult() {
|
|
177
|
+
return {
|
|
178
|
+
tier0: 'No capabilities indexed. Discovery engine not initialized.',
|
|
179
|
+
tier1: [],
|
|
180
|
+
tier2: [],
|
|
181
|
+
tokenEstimate: {
|
|
182
|
+
tier0Tokens: 10,
|
|
183
|
+
tier1Tokens: 0,
|
|
184
|
+
tier2Tokens: 0,
|
|
185
|
+
totalTokens: 10,
|
|
186
|
+
},
|
|
187
|
+
diagnostics: {
|
|
188
|
+
queryTimeMs: 0,
|
|
189
|
+
embeddingTimeMs: 0,
|
|
190
|
+
graphTraversalTimeMs: 0,
|
|
191
|
+
candidatesScanned: 0,
|
|
192
|
+
capabilitiesRetrieved: 0,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=CapabilityDiscoveryEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityDiscoveryEngine.js","sourceRoot":"","sources":["../../src/discovery/CapabilityDiscoveryEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAcH,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,MAAM,OAAO,yBAAyB;IAQpC,YACE,gBAAmC,EACnC,WAAyB,EACzB,MAA2C;QANrC,iBAAY,GAAG,CAAC,CAAC;QACjB,gBAAW,GAAG,KAAK,CAAC;QAO1B,IAAI,CAAC,MAAM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**
|
|
2
|
+
* @fileoverview Capability Embedding Strategy
|
|
3
|
+
* @module @framers/agentos/discovery/CapabilityEmbeddingStrategy
|
|
4
|
+
*
|
|
5
|
+
* Constructs the embedding text for each capability descriptor.
|
|
6
|
+
* The strategy captures WHEN a capability is useful (intent-oriented),
|
|
7
|
+
* not just what it does (description-only).
|
|
8
|
+
*
|
|
9
|
+
* Design informed by:
|
|
10
|
+
* - ToolLLM Neural API Retriever: embedding API docs (name, description, params)
|
|
11
|
+
* achieves NDCG@5 of 84.9 on 16K+ APIs
|
|
12
|
+
* - MCP-RAG: decomposing tools into parameter-level embeddings improves matching
|
|
13
|
+
* - Context Rot (Chroma 2025): keeping embedded text concise maximizes retrieval precision
|
|
14
|
+
*/
|
|
15
|
+
import type { CapabilityDescriptor } from './types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Builds optimized embedding text for capability descriptors.
|
|
18
|
+
*
|
|
19
|
+
* The embedding text is structured to maximize semantic match with user intents:
|
|
20
|
+
* 1. Name/display name — captures exact-match queries
|
|
21
|
+
* 2. Description — core semantic content
|
|
22
|
+
* 3. Category + tags — captures categorical queries ("communication tool")
|
|
23
|
+
* 4. Parameter names — captures action queries ("I need to search for X")
|
|
24
|
+
* 5. Dependencies — captures composition queries ("tool that works with GitHub")
|
|
25
|
+
*/
|
|
26
|
+
export declare class CapabilityEmbeddingStrategy {
|
|
27
|
+
/**
|
|
28
|
+
* Build the text that will be embedded for a capability.
|
|
29
|
+
* Designed to be concise (typically 100-300 tokens) while capturing
|
|
30
|
+
* the key semantic signals for retrieval.
|
|
31
|
+
*/
|
|
32
|
+
buildEmbeddingText(cap: CapabilityDescriptor): string;
|
|
33
|
+
/**
|
|
34
|
+
* Build a compact summary text for Tier 1 display.
|
|
35
|
+
* This is shown to the LLM when a capability is retrieved as relevant.
|
|
36
|
+
* Kept to ~30-50 tokens per capability.
|
|
37
|
+
*/
|
|
38
|
+
buildCompactSummary(cap: CapabilityDescriptor): string;
|
|
39
|
+
/**
|
|
40
|
+
* Build the full detail text for Tier 2 injection.
|
|
41
|
+
* Includes full schema and/or SKILL.md content.
|
|
42
|
+
*/
|
|
43
|
+
buildFullDetailText(cap: CapabilityDescriptor): string;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=CapabilityEmbeddingStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityEmbeddingStrategy.d.ts","sourceRoot":"","sources":["../../src/discovery/CapabilityEmbeddingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMvD;;;;;;;;;GASG;AACH,qBAAa,2BAA2B;IACtC;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM;IA0CrD;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM;IAiCtD;;;OAGG;IACH,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM;CAkCvD"}
|