@kuralle-agents/core 0.12.0 → 0.14.0
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/README.md +89 -4
- package/dist/ai-sdk/uiMessageStream.d.ts +2 -2
- package/dist/ai-sdk/uiMessageStream.js +42 -29
- package/dist/capabilities/LivePromptAssembler.d.ts +1 -1
- package/dist/capabilities/LivePromptAssembler.js +2 -1
- package/dist/capabilities/index.d.ts +1 -1
- package/dist/eval/EvalRunner.js +4 -4
- package/dist/eval/simulation.js +4 -3
- package/dist/events/TurnHandle.d.ts +3 -3
- package/dist/flow/collectDigression.d.ts +5 -2
- package/dist/flow/collectDigression.js +48 -10
- package/dist/flow/collectUntilComplete.js +13 -5
- package/dist/flow/degrade.js +8 -4
- package/dist/flow/emitInteractive.d.ts +2 -2
- package/dist/flow/emitInteractive.js +6 -3
- package/dist/flow/extraction.d.ts +3 -2
- package/dist/flow/extraction.js +14 -4
- package/dist/flow/reduceTransition.d.ts +2 -2
- package/dist/flow/reduceTransition.js +7 -3
- package/dist/flow/runFlow.js +97 -17
- package/dist/foundation/AgentStateController.d.ts +1 -1
- package/dist/foundation/ToolExecutor.d.ts +2 -2
- package/dist/foundation/index.d.ts +0 -11
- package/dist/foundation/index.js +0 -5
- package/dist/index.d.ts +15 -15
- package/dist/index.js +9 -6
- package/dist/outcomes/streamPart.d.ts +2 -2
- package/dist/outcomes/streamPart.js +2 -3
- package/dist/prompts/PromptBuilder.d.ts +3 -3
- package/dist/prompts/PromptBuilder.js +13 -6
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/types.d.ts +9 -2
- package/dist/runtime/InMemoryRetrievalCache.d.ts +25 -0
- package/dist/runtime/InMemoryRetrievalCache.js +59 -0
- package/dist/runtime/KnowledgeProvider.d.ts +3 -2
- package/dist/runtime/KnowledgeProvider.js +60 -31
- package/dist/runtime/Runtime.d.ts +47 -1
- package/dist/runtime/Runtime.js +273 -36
- package/dist/runtime/TokenAccumulator.d.ts +7 -0
- package/dist/runtime/TokenAccumulator.js +7 -0
- package/dist/runtime/TraceRecorder.d.ts +51 -0
- package/dist/runtime/TraceRecorder.js +326 -0
- package/dist/runtime/buildAgentToolSurface.js +1 -1
- package/dist/runtime/channels/TextDriver.js +57 -31
- package/dist/runtime/channels/executeModelTool.d.ts +14 -1
- package/dist/runtime/channels/executeModelTool.js +132 -3
- package/dist/runtime/channels/extractionTurn.js +1 -1
- package/dist/runtime/channels/index.d.ts +0 -3
- package/dist/runtime/channels/index.js +0 -6
- package/dist/runtime/channels/inputBuffer.d.ts +1 -0
- package/dist/runtime/channels/inputBuffer.js +9 -0
- package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
- package/dist/runtime/channels/streaming/speakGated.js +24 -12
- package/dist/runtime/citations/index.d.ts +3 -3
- package/dist/runtime/closeRun.js +14 -10
- package/dist/runtime/compaction.d.ts +2 -0
- package/dist/runtime/compaction.js +3 -2
- package/dist/runtime/controlFlowSignal.d.ts +24 -0
- package/dist/runtime/controlFlowSignal.js +29 -0
- package/dist/runtime/ctx.d.ts +3 -4
- package/dist/runtime/ctx.js +147 -60
- package/dist/runtime/durable/RunStore.d.ts +16 -0
- package/dist/runtime/durable/RunStore.js +7 -1
- package/dist/runtime/durable/SessionRunStore.d.ts +7 -2
- package/dist/runtime/durable/SessionRunStore.js +136 -34
- package/dist/runtime/durable/idempotency.d.ts +1 -0
- package/dist/runtime/durable/idempotency.js +3 -0
- package/dist/runtime/durable/replay.js +7 -2
- package/dist/runtime/durable/types.d.ts +11 -0
- package/dist/runtime/goals.d.ts +18 -0
- package/dist/runtime/goals.js +158 -0
- package/dist/runtime/grounding/gather.d.ts +1 -1
- package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.js +1 -1
- package/dist/runtime/handoffContinuation.d.ts +20 -0
- package/dist/runtime/handoffContinuation.js +30 -0
- package/dist/runtime/handoffOscillation.d.ts +6 -0
- package/dist/runtime/handoffOscillation.js +17 -0
- package/dist/runtime/hostLoop.js +37 -6
- package/dist/runtime/index.d.ts +4 -3
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/openRun.d.ts +2 -0
- package/dist/runtime/openRun.js +46 -17
- package/dist/runtime/outcomeMarking.d.ts +2 -2
- package/dist/runtime/outcomeMarking.js +2 -1
- package/dist/runtime/policies/agentTurn.d.ts +1 -1
- package/dist/runtime/policies/limits.d.ts +1 -0
- package/dist/runtime/policies/limits.js +3 -0
- package/dist/runtime/runHookSafely.d.ts +3 -0
- package/dist/runtime/runHookSafely.js +19 -0
- package/dist/runtime/select.d.ts +5 -1
- package/dist/runtime/select.js +30 -1
- package/dist/runtime/turnTokenUsage.d.ts +28 -0
- package/dist/runtime/turnTokenUsage.js +70 -0
- package/dist/scheduler/index.d.ts +2 -2
- package/dist/scheduler/index.js +1 -1
- package/dist/services/TracingService.js +2 -3
- package/dist/session/SessionStore.d.ts +6 -0
- package/dist/session/SessionStore.js +12 -1
- package/dist/session/stores/MemoryStore.d.ts +1 -1
- package/dist/session/stores/MemoryStore.js +16 -2
- package/dist/session/testing.d.ts +6 -1
- package/dist/session/testing.js +34 -0
- package/dist/session/utils.d.ts +3 -0
- package/dist/session/utils.js +23 -0
- package/dist/skills/collectSkills.d.ts +11 -3
- package/dist/skills/collectSkills.js +51 -8
- package/dist/skills/compositeSkillStore.d.ts +26 -0
- package/dist/skills/compositeSkillStore.js +54 -0
- package/dist/skills/defineSkill.d.ts +21 -0
- package/dist/skills/defineSkill.js +26 -0
- package/dist/skills/fsSkillStore.d.ts +3 -0
- package/dist/skills/fsSkillStore.js +79 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
- package/dist/skills/parseSkillFrontmatter.js +183 -0
- package/dist/skills/wireAgentSkills.d.ts +2 -1
- package/dist/skills/wireAgentSkills.js +2 -2
- package/dist/testing/mocks.d.ts +3 -3
- package/dist/testing/mocks.js +7 -3
- package/dist/tools/controlResults.d.ts +14 -0
- package/dist/tools/controlResults.js +15 -0
- package/dist/tools/effect/ToolExecutor.d.ts +6 -0
- package/dist/tools/effect/ToolExecutor.js +75 -36
- package/dist/tools/effect/defineTool.d.ts +11 -0
- package/dist/tools/effect/defineTool.js +3 -0
- package/dist/tools/effect/errors.d.ts +2 -5
- package/dist/tools/effect/errors.js +2 -5
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tracing/MemoryTraceStore.d.ts +16 -0
- package/dist/tracing/MemoryTraceStore.js +56 -0
- package/dist/tracing/OtelTraceSink.d.ts +127 -0
- package/dist/tracing/OtelTraceSink.js +101 -0
- package/dist/tracing/TraceStore.d.ts +19 -0
- package/dist/tracing/TraceStore.js +32 -0
- package/dist/tracing/index.d.ts +3 -0
- package/dist/tracing/index.js +3 -0
- package/dist/tracing/testing.d.ts +3 -0
- package/dist/tracing/testing.js +45 -0
- package/dist/types/agentConfig.d.ts +2 -1
- package/dist/types/channel.d.ts +14 -1
- package/dist/types/effectTool.d.ts +6 -0
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/guardrails.d.ts +5 -0
- package/dist/types/hooks.d.ts +2 -2
- package/dist/types/index.d.ts +25 -15
- package/dist/types/index.js +8 -12
- package/dist/types/knowledge.d.ts +213 -0
- package/dist/types/processors.d.ts +0 -58
- package/dist/types/run-context.d.ts +16 -7
- package/dist/types/runtime.d.ts +3 -74
- package/dist/types/session.d.ts +11 -1
- package/dist/types/skills.d.ts +15 -1
- package/dist/types/stream.d.ts +138 -68
- package/dist/types/stream.js +34 -1
- package/dist/types/trace.d.ts +52 -0
- package/guides/AGENTS.md +3 -3
- package/guides/EXAMPLE_VERIFICATION.md +4 -4
- package/guides/FLOWS.md +1 -1
- package/guides/GETTING_STARTED.md +1 -1
- package/guides/RUNTIME.md +20 -15
- package/guides/TOOLS.md +1 -1
- package/package.json +13 -14
- package/dist/foundation/AgentDefinition.d.ts +0 -17
- package/dist/foundation/ConversationEventLog.d.ts +0 -71
- package/dist/foundation/ConversationState.d.ts +0 -33
- package/dist/foundation/ConversationState.js +0 -1
- package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
- package/dist/foundation/DefaultConversationEventLog.js +0 -205
- package/dist/foundation/DefaultConversationState.d.ts +0 -36
- package/dist/foundation/DefaultConversationState.js +0 -103
- package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
- package/dist/foundation/DefaultToolExecutor.js +0 -132
- package/dist/foundation/createFoundation.d.ts +0 -32
- package/dist/foundation/createFoundation.js +0 -33
- package/dist/hooks/HookRunner.d.ts +0 -37
- package/dist/hooks/HookRunner.js +0 -111
- package/dist/hooks/builtin/logging.d.ts +0 -5
- package/dist/hooks/builtin/logging.js +0 -98
- package/dist/hooks/builtin/metrics.d.ts +0 -7
- package/dist/hooks/builtin/metrics.js +0 -60
- package/dist/hooks/builtin/observability.d.ts +0 -20
- package/dist/hooks/builtin/observability.js +0 -572
- package/dist/hooks/helpers.d.ts +0 -22
- package/dist/hooks/helpers.js +0 -183
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -6
- package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
- package/dist/realtime/RealtimeAudioClient.js +0 -14
- package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
- package/dist/realtime/RealtimeSessionHandle.js +0 -1
- package/dist/realtime/index.d.ts +0 -2
- package/dist/realtime/index.js +0 -1
- package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
- package/dist/runtime/channels/VoiceDriver.js +0 -321
- package/dist/runtime/channels/voiceTools.d.ts +0 -9
- package/dist/runtime/channels/voiceTools.js +0 -51
- package/dist/tools/errorHandling.d.ts +0 -35
- package/dist/tools/errorHandling.js +0 -145
- package/dist/types/voice.d.ts +0 -517
- package/dist/types/voice.js +0 -14
- package/dist/utils/isRecord.d.ts +0 -1
- package/dist/utils/isRecord.js +0 -3
- package/dist/utils/messageNormalization.d.ts +0 -2
- package/dist/utils/messageNormalization.js +0 -137
- /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
- /package/dist/{foundation/ConversationEventLog.js → types/trace.js} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function cosineSimilarity(a, b) {
|
|
2
|
+
const n = Math.min(a.length, b.length);
|
|
3
|
+
if (n === 0)
|
|
4
|
+
return 0;
|
|
5
|
+
let dot = 0;
|
|
6
|
+
let na = 0;
|
|
7
|
+
let nb = 0;
|
|
8
|
+
for (let i = 0; i < n; i++) {
|
|
9
|
+
dot += a[i] * b[i];
|
|
10
|
+
na += a[i] * a[i];
|
|
11
|
+
nb += b[i] * b[i];
|
|
12
|
+
}
|
|
13
|
+
if (na === 0 || nb === 0)
|
|
14
|
+
return 0;
|
|
15
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
16
|
+
}
|
|
17
|
+
export class InMemoryRetrievalCache {
|
|
18
|
+
/** Ordered oldest → newest (LRU front, MRU back). */
|
|
19
|
+
entries = [];
|
|
20
|
+
maxEntries;
|
|
21
|
+
ttlMs;
|
|
22
|
+
threshold;
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.maxEntries = options.maxEntries ?? 256;
|
|
25
|
+
this.ttlMs = options.ttlMs ?? 300_000;
|
|
26
|
+
this.threshold = options.similarityThreshold ?? 0.85;
|
|
27
|
+
}
|
|
28
|
+
get size() {
|
|
29
|
+
return this.entries.length;
|
|
30
|
+
}
|
|
31
|
+
lookup(queryEmbedding, topK) {
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
let best;
|
|
34
|
+
let bestSim = this.threshold;
|
|
35
|
+
for (const entry of this.entries) {
|
|
36
|
+
if (now - entry.at > this.ttlMs)
|
|
37
|
+
continue;
|
|
38
|
+
const sim = cosineSimilarity(queryEmbedding, entry.embedding);
|
|
39
|
+
if (sim >= bestSim) {
|
|
40
|
+
bestSim = sim;
|
|
41
|
+
best = entry;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!best)
|
|
45
|
+
return [];
|
|
46
|
+
// Touch: move to MRU.
|
|
47
|
+
this.entries = this.entries.filter((e) => e !== best);
|
|
48
|
+
this.entries.push(best);
|
|
49
|
+
const results = best.results;
|
|
50
|
+
return topK === undefined ? results : results.slice(0, topK);
|
|
51
|
+
}
|
|
52
|
+
populate(results, queryEmbedding) {
|
|
53
|
+
if (!queryEmbedding || queryEmbedding.length === 0 || results.length === 0)
|
|
54
|
+
return;
|
|
55
|
+
this.entries.push({ embedding: queryEmbedding, results: [...results], at: Date.now() });
|
|
56
|
+
while (this.entries.length > this.maxEntries)
|
|
57
|
+
this.entries.shift();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* The provider holds no mutable state itself — per-session cache state is
|
|
13
13
|
* stored on RunContext.retrievalCache so it survives agent handoffs.
|
|
14
14
|
*/
|
|
15
|
-
import type { KnowledgeProviderConfig, AgentKnowledgeOverrides, KnowledgeRetrievalResult,
|
|
15
|
+
import type { KnowledgeProviderConfig, AgentKnowledgeOverrides, KnowledgeRetrievalResult, RetrievalCacheAdapter } from '../types/index.js';
|
|
16
|
+
import type { StreamPart } from '../types/stream.js';
|
|
16
17
|
export type { RetrievalCacheAdapter } from '../types/index.js';
|
|
17
18
|
interface ResolvedKnowledgeConfig {
|
|
18
19
|
compiledEnabled: boolean;
|
|
@@ -72,7 +73,7 @@ export declare class KnowledgeProvider {
|
|
|
72
73
|
*/
|
|
73
74
|
retrieve(query: string, cache: RetrievalCacheAdapter | undefined, agentOverrides?: AgentKnowledgeOverrides, isVoice?: boolean): Promise<{
|
|
74
75
|
results: KnowledgeRetrievalResult[];
|
|
75
|
-
events:
|
|
76
|
+
events: StreamPart[];
|
|
76
77
|
}>;
|
|
77
78
|
/**
|
|
78
79
|
* Run quality check on retrieval results and optionally reformulate.
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* The provider holds no mutable state itself — per-session cache state is
|
|
13
13
|
* stored on RunContext.retrievalCache so it survives agent handoffs.
|
|
14
14
|
*/
|
|
15
|
+
import { InMemoryRetrievalCache } from './InMemoryRetrievalCache.js';
|
|
15
16
|
export class KnowledgeProvider {
|
|
16
17
|
config;
|
|
17
18
|
retriever;
|
|
@@ -21,7 +22,11 @@ export class KnowledgeProvider {
|
|
|
21
22
|
this.config = options.config;
|
|
22
23
|
this.retriever = options.config.retriever;
|
|
23
24
|
this.embedder = options.config.embedder;
|
|
24
|
-
|
|
25
|
+
// Default to a zero-config in-process cache when an embedder is available
|
|
26
|
+
// (the cache is keyed by query embedding). Apps can inject their own adapter.
|
|
27
|
+
this.cacheFactory =
|
|
28
|
+
options.cacheFactory ??
|
|
29
|
+
(this.embedder ? () => new InMemoryRetrievalCache(options.config.cache) : undefined);
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
32
|
* Create a new session-level cache instance. Called once per session
|
|
@@ -87,24 +92,33 @@ export class KnowledgeProvider {
|
|
|
87
92
|
const cacheLatency = Date.now() - cacheStart;
|
|
88
93
|
if (cached.length > 0) {
|
|
89
94
|
events.push({
|
|
95
|
+
channel: 'internal',
|
|
90
96
|
type: 'knowledge-cache-hit',
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
payload: {
|
|
98
|
+
query,
|
|
99
|
+
resultCount: cached.length,
|
|
100
|
+
latencyMs: cacheLatency,
|
|
101
|
+
},
|
|
94
102
|
});
|
|
95
103
|
events.push({
|
|
104
|
+
channel: 'internal',
|
|
96
105
|
type: 'knowledge-search',
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
payload: {
|
|
107
|
+
query,
|
|
108
|
+
resultCount: cached.length,
|
|
109
|
+
latencyMs: cacheLatency,
|
|
110
|
+
layer: 'cache',
|
|
111
|
+
},
|
|
101
112
|
});
|
|
102
113
|
return { results: cached, events };
|
|
103
114
|
}
|
|
104
115
|
events.push({
|
|
116
|
+
channel: 'internal',
|
|
105
117
|
type: 'knowledge-cache-miss',
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
payload: {
|
|
119
|
+
query,
|
|
120
|
+
latencyMs: cacheLatency,
|
|
121
|
+
},
|
|
108
122
|
});
|
|
109
123
|
// Layer 3: Hybrid search (cache miss)
|
|
110
124
|
const searchStart = Date.now();
|
|
@@ -116,11 +130,14 @@ export class KnowledgeProvider {
|
|
|
116
130
|
});
|
|
117
131
|
const searchLatency = Date.now() - searchStart;
|
|
118
132
|
events.push({
|
|
133
|
+
channel: 'internal',
|
|
119
134
|
type: 'knowledge-search',
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
payload: {
|
|
136
|
+
query,
|
|
137
|
+
resultCount: results.length,
|
|
138
|
+
latencyMs: searchLatency,
|
|
139
|
+
layer: 'hybrid',
|
|
140
|
+
},
|
|
124
141
|
});
|
|
125
142
|
// Quality check + optional reformulation
|
|
126
143
|
results = await this.runQualityCheck(query, results, events, isVoice, resolved);
|
|
@@ -139,11 +156,14 @@ export class KnowledgeProvider {
|
|
|
139
156
|
});
|
|
140
157
|
const searchLatency = Date.now() - searchStart;
|
|
141
158
|
events.push({
|
|
159
|
+
channel: 'internal',
|
|
142
160
|
type: 'knowledge-search',
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
161
|
+
payload: {
|
|
162
|
+
query,
|
|
163
|
+
resultCount: results.length,
|
|
164
|
+
latencyMs: searchLatency,
|
|
165
|
+
layer: 'hybrid',
|
|
166
|
+
},
|
|
147
167
|
});
|
|
148
168
|
// Quality check + optional reformulation
|
|
149
169
|
results = await this.runQualityCheck(query, results, events, isVoice, resolved);
|
|
@@ -177,12 +197,15 @@ export class KnowledgeProvider {
|
|
|
177
197
|
quality = 'low';
|
|
178
198
|
}
|
|
179
199
|
events.push({
|
|
200
|
+
channel: 'internal',
|
|
180
201
|
type: 'knowledge-quality-check',
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
payload: {
|
|
203
|
+
query,
|
|
204
|
+
quality,
|
|
205
|
+
topScore,
|
|
206
|
+
avgScore,
|
|
207
|
+
coverageEstimate,
|
|
208
|
+
},
|
|
186
209
|
});
|
|
187
210
|
// Only reformulate on low quality with a reformulate callback
|
|
188
211
|
if (quality !== 'low' || !qc.reformulate)
|
|
@@ -190,11 +213,14 @@ export class KnowledgeProvider {
|
|
|
190
213
|
if (isVoice) {
|
|
191
214
|
// Voice: signal background reformulation, don't block
|
|
192
215
|
events.push({
|
|
216
|
+
channel: 'internal',
|
|
193
217
|
type: 'knowledge-reformulation',
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
payload: {
|
|
219
|
+
originalQuery: query,
|
|
220
|
+
reformulatedQuery: '',
|
|
221
|
+
trigger: 'background',
|
|
222
|
+
latencyMs: 0,
|
|
223
|
+
},
|
|
198
224
|
});
|
|
199
225
|
return results;
|
|
200
226
|
}
|
|
@@ -204,11 +230,14 @@ export class KnowledgeProvider {
|
|
|
204
230
|
const reformulatedQuery = await qc.reformulate(query, results);
|
|
205
231
|
const reformulateLatency = Date.now() - reformulateStart;
|
|
206
232
|
events.push({
|
|
233
|
+
channel: 'internal',
|
|
207
234
|
type: 'knowledge-reformulation',
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
235
|
+
payload: {
|
|
236
|
+
originalQuery: query,
|
|
237
|
+
reformulatedQuery,
|
|
238
|
+
trigger: 'inline',
|
|
239
|
+
latencyMs: reformulateLatency,
|
|
240
|
+
},
|
|
212
241
|
});
|
|
213
242
|
// Re-retrieve with reformulated query (one attempt, no recursion)
|
|
214
243
|
if (this.retriever) {
|
|
@@ -12,12 +12,25 @@ import type { SignalDelivery } from './durable/types.js';
|
|
|
12
12
|
import type { ResolvedSelection } from '../types/selection.js';
|
|
13
13
|
import type { ConversationOutcome, ConversationOutcomeMarkedBy } from '../outcomes/types.js';
|
|
14
14
|
import type { classifyHostTarget, selectHostTarget } from './select.js';
|
|
15
|
-
import type { KnowledgeProviderConfig } from '../types/
|
|
15
|
+
import type { KnowledgeProviderConfig } from '../types/knowledge.js';
|
|
16
16
|
import type { MemoryService as V1MemoryService } from '../memory/MemoryService.js';
|
|
17
17
|
import type { PersistentMemoryStore } from '../memory/blocks/types.js';
|
|
18
18
|
import { type CompactionConfig } from './compaction.js';
|
|
19
19
|
import type { EscalationConfig } from '../escalation/types.js';
|
|
20
20
|
import type { WakeOptions } from '../scheduler/index.js';
|
|
21
|
+
import type { HandoffInputFilter } from './handoffFilters.js';
|
|
22
|
+
import type { AgentSpan, AgentTrace } from '../types/trace.js';
|
|
23
|
+
import { type TraceSink, type TraceStore } from '../tracing/TraceStore.js';
|
|
24
|
+
export interface TracingConfig {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
store?: TraceStore;
|
|
27
|
+
sinks?: TraceSink[];
|
|
28
|
+
redact?: (span: AgentSpan) => AgentSpan | null;
|
|
29
|
+
sampling?: number | ((context: {
|
|
30
|
+
sessionId: string;
|
|
31
|
+
input?: unknown;
|
|
32
|
+
}) => boolean);
|
|
33
|
+
}
|
|
21
34
|
export interface HarnessConfig {
|
|
22
35
|
agents: AgentConfig[];
|
|
23
36
|
defaultAgentId: string;
|
|
@@ -56,6 +69,24 @@ export interface HarnessConfig {
|
|
|
56
69
|
* invokes the handler. Resume with `runtime.resumeFromEscalation()`.
|
|
57
70
|
*/
|
|
58
71
|
escalation?: EscalationConfig;
|
|
72
|
+
/** Default handoff input filter when a route does not define `filter`. */
|
|
73
|
+
handoffInputFilter?: HandoffInputFilter;
|
|
74
|
+
/**
|
|
75
|
+
* Silent handoff (default `true`). A transfer between agents reads as one
|
|
76
|
+
* continuous assistant: the transfer is a silent control tool call, and the
|
|
77
|
+
* target is given a continuation directive so it does not greet or
|
|
78
|
+
* re-introduce itself. Set `false` for an explicit visible transfer (the
|
|
79
|
+
* target follows its own instructions, e.g. "Bill here").
|
|
80
|
+
*/
|
|
81
|
+
silentHandoff?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Structured goal/thread tracking (G5). When enabled, a cheap control-model
|
|
84
|
+
* pass at turn end patches `session.workingMemory.__goals` and open threads
|
|
85
|
+
* are projected into the next turn's prompt. Default off — opt-in cost/latency.
|
|
86
|
+
*/
|
|
87
|
+
trackGoals?: boolean;
|
|
88
|
+
/** Read-only observability, configured independently from durable session state. */
|
|
89
|
+
tracing?: TracingConfig;
|
|
59
90
|
}
|
|
60
91
|
export interface RunOptions {
|
|
61
92
|
sessionId?: string;
|
|
@@ -75,6 +106,8 @@ export interface RunOptions {
|
|
|
75
106
|
historyDelta?: ModelMessage[];
|
|
76
107
|
driver?: ChannelDriver;
|
|
77
108
|
signalDelivery?: SignalDelivery;
|
|
109
|
+
/** Stable key for this inbound user message; duplicate webhook retries are ignored (H2). */
|
|
110
|
+
idempotencyKey?: string;
|
|
78
111
|
abortSignal?: AbortSignal;
|
|
79
112
|
}
|
|
80
113
|
export declare class Runtime {
|
|
@@ -87,10 +120,19 @@ export declare class Runtime {
|
|
|
87
120
|
private readonly hooks?;
|
|
88
121
|
private readonly activeTurnAborts;
|
|
89
122
|
private readonly sessionMutex;
|
|
123
|
+
private readonly traceStore?;
|
|
124
|
+
private readonly traceSinks;
|
|
125
|
+
private readonly pendingTraceWrites;
|
|
90
126
|
constructor(config: HarnessConfig);
|
|
91
127
|
run(opts: RunOptions): TurnHandle;
|
|
128
|
+
runOnce(opts: RunOptions): Promise<AgentTrace>;
|
|
92
129
|
stream(opts: RunOptions): TurnHandle;
|
|
93
130
|
getSession(sessionId: string): Promise<Session | null>;
|
|
131
|
+
getTrace(traceId: string): Promise<AgentTrace | null>;
|
|
132
|
+
listTraces(sessionId: string): Promise<AgentTrace[]>;
|
|
133
|
+
getTraceStore(): TraceStore | undefined;
|
|
134
|
+
/** The agent used when neither the caller nor persisted state names one. */
|
|
135
|
+
getDefaultAgentId(): string;
|
|
94
136
|
getSessionStore(): SessionStore;
|
|
95
137
|
deleteSession(sessionId: string): Promise<void>;
|
|
96
138
|
abortSession(sessionId: string, reason?: string): void;
|
|
@@ -99,6 +141,10 @@ export declare class Runtime {
|
|
|
99
141
|
reason?: string;
|
|
100
142
|
markedBy?: ConversationOutcomeMarkedBy;
|
|
101
143
|
}): Promise<void>;
|
|
144
|
+
private shouldTrace;
|
|
145
|
+
private writeSpan;
|
|
146
|
+
private settleTraceWrites;
|
|
147
|
+
private flushTraceSinks;
|
|
102
148
|
/**
|
|
103
149
|
* Compact `runState.messages` when over the configured trigger (or always,
|
|
104
150
|
* when `force`). Persists both the run state and the session message mirror.
|