@framers/agentos 0.1.29 → 0.1.30
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/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,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,eA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,EAAE,CAAC;gBACd,WAAW,EAAE,CAAC;gBACd,WAAW,EAAE,EAAE;aAChB;YACD,WAAW,EAAE;gBACX,WAAW,EAAE,CAAC;gBACd,eAAe,EAAE,CAAC;gBAClB,oBAAoB,EAAE,CAAC;gBACvB,iBAAiB,EAAE,CAAC;gBACpB,qBAAqB,EAAE,CAAC;aACzB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
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"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
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
|
+
// ============================================================================
|
|
16
|
+
// EMBEDDING STRATEGY
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Builds optimized embedding text for capability descriptors.
|
|
20
|
+
*
|
|
21
|
+
* The embedding text is structured to maximize semantic match with user intents:
|
|
22
|
+
* 1. Name/display name — captures exact-match queries
|
|
23
|
+
* 2. Description — core semantic content
|
|
24
|
+
* 3. Category + tags — captures categorical queries ("communication tool")
|
|
25
|
+
* 4. Parameter names — captures action queries ("I need to search for X")
|
|
26
|
+
* 5. Dependencies — captures composition queries ("tool that works with GitHub")
|
|
27
|
+
*/
|
|
28
|
+
export class CapabilityEmbeddingStrategy {
|
|
29
|
+
/**
|
|
30
|
+
* Build the text that will be embedded for a capability.
|
|
31
|
+
* Designed to be concise (typically 100-300 tokens) while capturing
|
|
32
|
+
* the key semantic signals for retrieval.
|
|
33
|
+
*/
|
|
34
|
+
buildEmbeddingText(cap) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
// 1. Name and display name (captures exact-match queries)
|
|
37
|
+
if (cap.displayName !== cap.name) {
|
|
38
|
+
parts.push(`${cap.displayName} (${cap.name})`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
parts.push(cap.name);
|
|
42
|
+
}
|
|
43
|
+
// 2. Description (core semantics — the most important part)
|
|
44
|
+
if (cap.description) {
|
|
45
|
+
parts.push(cap.description);
|
|
46
|
+
}
|
|
47
|
+
// 3. Category (captures categorical queries like "I need a developer tool")
|
|
48
|
+
if (cap.category) {
|
|
49
|
+
parts.push(`Category: ${cap.category}`);
|
|
50
|
+
}
|
|
51
|
+
// 4. Tags (captures use-case queries like "search", "automation", "messaging")
|
|
52
|
+
if (cap.tags.length > 0) {
|
|
53
|
+
parts.push(`Use cases: ${cap.tags.join(', ')}`);
|
|
54
|
+
}
|
|
55
|
+
// 5. For tools: extract parameter names from schema
|
|
56
|
+
// This captures queries like "I need to specify a URL" → matches url param
|
|
57
|
+
if (cap.kind === 'tool' && cap.fullSchema) {
|
|
58
|
+
const paramNames = extractParameterNames(cap.fullSchema);
|
|
59
|
+
if (paramNames.length > 0) {
|
|
60
|
+
parts.push(`Parameters: ${paramNames.join(', ')}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// 6. Dependencies (captures composition queries)
|
|
64
|
+
if (cap.requiredTools.length > 0) {
|
|
65
|
+
parts.push(`Requires: ${cap.requiredTools.join(', ')}`);
|
|
66
|
+
}
|
|
67
|
+
return parts.join('\n');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build a compact summary text for Tier 1 display.
|
|
71
|
+
* This is shown to the LLM when a capability is retrieved as relevant.
|
|
72
|
+
* Kept to ~30-50 tokens per capability.
|
|
73
|
+
*/
|
|
74
|
+
buildCompactSummary(cap) {
|
|
75
|
+
const parts = [];
|
|
76
|
+
// Name and kind
|
|
77
|
+
parts.push(`${cap.name} (${cap.kind})`);
|
|
78
|
+
// Truncated description
|
|
79
|
+
const desc = cap.description.length > 120
|
|
80
|
+
? cap.description.slice(0, 117) + '...'
|
|
81
|
+
: cap.description;
|
|
82
|
+
parts.push(desc);
|
|
83
|
+
// Key params for tools (top 3)
|
|
84
|
+
if (cap.kind === 'tool' && cap.fullSchema) {
|
|
85
|
+
const params = extractParameterNames(cap.fullSchema, 3);
|
|
86
|
+
if (params.length > 0) {
|
|
87
|
+
parts.push(`Params: ${params.join(', ')}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Dependencies
|
|
91
|
+
if (cap.requiredTools.length > 0) {
|
|
92
|
+
parts.push(`Requires: ${cap.requiredTools.join(', ')}`);
|
|
93
|
+
}
|
|
94
|
+
// Availability warning
|
|
95
|
+
if (!cap.available) {
|
|
96
|
+
parts.push('[not available — missing secrets or dependencies]');
|
|
97
|
+
}
|
|
98
|
+
return parts.join('. ');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Build the full detail text for Tier 2 injection.
|
|
102
|
+
* Includes full schema and/or SKILL.md content.
|
|
103
|
+
*/
|
|
104
|
+
buildFullDetailText(cap) {
|
|
105
|
+
const parts = [];
|
|
106
|
+
parts.push(`# ${cap.displayName}`);
|
|
107
|
+
parts.push(`Kind: ${cap.kind} | Category: ${cap.category}`);
|
|
108
|
+
if (cap.description) {
|
|
109
|
+
parts.push(`\n${cap.description}`);
|
|
110
|
+
}
|
|
111
|
+
// Full schema for tools
|
|
112
|
+
if (cap.kind === 'tool' && cap.fullSchema) {
|
|
113
|
+
parts.push('\n## Input Schema');
|
|
114
|
+
parts.push(formatSchemaForContext(cap.fullSchema));
|
|
115
|
+
}
|
|
116
|
+
// Full SKILL.md content for skills
|
|
117
|
+
if (cap.fullContent) {
|
|
118
|
+
parts.push('\n## Skill Instructions');
|
|
119
|
+
parts.push(cap.fullContent);
|
|
120
|
+
}
|
|
121
|
+
// Required secrets
|
|
122
|
+
if (cap.requiredSecrets.length > 0) {
|
|
123
|
+
parts.push(`\nRequired secrets: ${cap.requiredSecrets.join(', ')}`);
|
|
124
|
+
}
|
|
125
|
+
// Tags
|
|
126
|
+
if (cap.tags.length > 0) {
|
|
127
|
+
parts.push(`Tags: ${cap.tags.join(', ')}`);
|
|
128
|
+
}
|
|
129
|
+
return parts.join('\n');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// ============================================================================
|
|
133
|
+
// HELPERS
|
|
134
|
+
// ============================================================================
|
|
135
|
+
/**
|
|
136
|
+
* Extract property names from a JSON Schema object.
|
|
137
|
+
* Returns the top-level property names, optionally limited.
|
|
138
|
+
*/
|
|
139
|
+
function extractParameterNames(schema, limit) {
|
|
140
|
+
const properties = schema.properties;
|
|
141
|
+
if (!properties)
|
|
142
|
+
return [];
|
|
143
|
+
const names = Object.keys(properties);
|
|
144
|
+
return limit ? names.slice(0, limit) : names;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Format a JSON Schema for context injection.
|
|
148
|
+
* Produces a compact, human-readable representation.
|
|
149
|
+
*/
|
|
150
|
+
function formatSchemaForContext(schema) {
|
|
151
|
+
const properties = schema.properties;
|
|
152
|
+
if (!properties)
|
|
153
|
+
return '(no parameters)';
|
|
154
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
155
|
+
const lines = [];
|
|
156
|
+
for (const [name, prop] of Object.entries(properties)) {
|
|
157
|
+
const type = prop.type ?? 'any';
|
|
158
|
+
const isRequired = required.has(name);
|
|
159
|
+
const desc = prop.description ? `: ${prop.description}` : '';
|
|
160
|
+
const enumValues = Array.isArray(prop.enum) ? ` [${prop.enum.join('|')}]` : '';
|
|
161
|
+
const defaultVal = prop.default !== undefined ? ` (default: ${JSON.stringify(prop.default)})` : '';
|
|
162
|
+
const reqLabel = isRequired ? ', required' : '';
|
|
163
|
+
lines.push(` ${name} (${type}${reqLabel})${desc}${enumValues}${defaultVal}`);
|
|
164
|
+
}
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=CapabilityEmbeddingStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityEmbeddingStrategy.js","sourceRoot":"","sources":["../../src/discovery/CapabilityEmbeddingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,OAAO,2BAA2B;IACtC;;;;OAIG;IACH,kBAAkB,CAAC,GAAyB;QAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,0DAA0D;QAC1D,IAAI,GAAG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C,CAAC,KAAM,IAAI,CAAC,IAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACnG,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;QAEhD,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,IAAI,GAAG,QAAQ,IAAI,IAAI,GAAG,UAAU,GAAG,UAAU,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Capability Relationship Graph
|
|
3
|
+
* @module @framers/agentos/discovery/CapabilityGraph
|
|
4
|
+
*
|
|
5
|
+
* Lightweight, deterministic relationship graph over capabilities.
|
|
6
|
+
* Built from metadata (SKILL.md frontmatter, preset co-occurrence),
|
|
7
|
+
* NOT from LLM extraction.
|
|
8
|
+
*
|
|
9
|
+
* Uses graphology (already in codebase via GraphRAGEngine) for:
|
|
10
|
+
* - O(1) neighbor lookups
|
|
11
|
+
* - Edge attributes (type, weight)
|
|
12
|
+
* - Sub-millisecond traversal for ~100 nodes
|
|
13
|
+
*
|
|
14
|
+
* Implements ICapabilityGraph so Neo4j can be swapped in later
|
|
15
|
+
* if capabilities scale to 1000+.
|
|
16
|
+
*
|
|
17
|
+
* Edge types:
|
|
18
|
+
* - DEPENDS_ON: Skill → Tool (from requiredTools)
|
|
19
|
+
* - COMPOSED_WITH: Co-occur in agent presets (suggestedSkills + suggestedExtensions)
|
|
20
|
+
* - SAME_CATEGORY: Shared category (weak signal, low weight)
|
|
21
|
+
* - TAGGED_WITH: Shared tags (weighted by overlap count, ≥2 tags)
|
|
22
|
+
*/
|
|
23
|
+
import type { CapabilityDescriptor, CapabilityEdge, ICapabilityGraph, PresetCoOccurrence, RelatedCapability } from './types.js';
|
|
24
|
+
export declare class CapabilityGraph implements ICapabilityGraph {
|
|
25
|
+
private graph;
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Build the graph from capability descriptors and preset co-occurrence data.
|
|
29
|
+
*
|
|
30
|
+
* Construction order:
|
|
31
|
+
* 1. Add all capabilities as nodes
|
|
32
|
+
* 2. Add DEPENDS_ON edges (skill → tool dependencies)
|
|
33
|
+
* 3. Add COMPOSED_WITH edges (preset co-occurrence)
|
|
34
|
+
* 4. Add TAGGED_WITH edges (shared tags, ≥2 overlap)
|
|
35
|
+
* 5. Add SAME_CATEGORY edges (weak signal)
|
|
36
|
+
*/
|
|
37
|
+
buildGraph(capabilities: CapabilityDescriptor[], presetCoOccurrences?: PresetCoOccurrence[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get capabilities related to a given capability (1-hop neighbors).
|
|
40
|
+
* Returns neighbors with edge weights, sorted by weight descending.
|
|
41
|
+
*/
|
|
42
|
+
getRelated(capabilityId: string): RelatedCapability[];
|
|
43
|
+
/**
|
|
44
|
+
* Get the subgraph for a set of capability IDs.
|
|
45
|
+
* Returns all nodes and edges within the induced subgraph.
|
|
46
|
+
*/
|
|
47
|
+
getSubgraph(capabilityIds: string[]): {
|
|
48
|
+
nodes: string[];
|
|
49
|
+
edges: CapabilityEdge[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Apply graph-based re-ranking boost to search results.
|
|
53
|
+
*
|
|
54
|
+
* For each result in the search results:
|
|
55
|
+
* 1. Look up its graph neighbors
|
|
56
|
+
* 2. If a neighbor is also in the results, boost both by graphBoostFactor * edge weight
|
|
57
|
+
* 3. If a neighbor is NOT in results but has a DEPENDS_ON edge, add it as a candidate
|
|
58
|
+
*
|
|
59
|
+
* Returns re-ranked results with potentially new candidates added.
|
|
60
|
+
*/
|
|
61
|
+
rerank(searchResults: Array<{
|
|
62
|
+
id: string;
|
|
63
|
+
score: number;
|
|
64
|
+
}>, graphBoostFactor: number): Array<{
|
|
65
|
+
id: string;
|
|
66
|
+
score: number;
|
|
67
|
+
boosted: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
nodeCount(): number;
|
|
70
|
+
edgeCount(): number;
|
|
71
|
+
clear(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Safely add an edge, handling the case where it already exists.
|
|
74
|
+
* If the edge already exists, update to the higher weight.
|
|
75
|
+
*/
|
|
76
|
+
private safeAddEdge;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=CapabilityGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityGraph.d.ts","sourceRoot":"","sources":["../../src/discovery/CapabilityGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EAEd,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAMpB,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,CAAC,KAAK,CAAQ;;IAUrB;;;;;;;;;OASG;IACH,UAAU,CACR,YAAY,EAAE,oBAAoB,EAAE,EACpC,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,GACzC,IAAI;IA2FP;;;OAGG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAoBrD;;;OAGG;IACH,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG;QACpC,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,KAAK,EAAE,cAAc,EAAE,CAAC;KACzB;IA4BD;;;;;;;;;OASG;IACH,MAAM,CACJ,aAAa,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EACnD,gBAAgB,EAAE,MAAM,GACvB,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAsCzD,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,MAAM;IAInB,KAAK,IAAI,IAAI;IAQb;;;OAGG;IACH,OAAO,CAAC,WAAW;CAiCpB"}
|