@kuralle-agents/core 0.12.0 → 0.13.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.
Files changed (89) hide show
  1. package/README.md +85 -0
  2. package/dist/capabilities/LivePromptAssembler.js +1 -0
  3. package/dist/flow/collectDigression.d.ts +5 -2
  4. package/dist/flow/collectDigression.js +48 -10
  5. package/dist/flow/collectUntilComplete.js +9 -1
  6. package/dist/flow/extraction.d.ts +1 -0
  7. package/dist/flow/extraction.js +4 -0
  8. package/dist/flow/runFlow.js +63 -5
  9. package/dist/index.d.ts +6 -1
  10. package/dist/index.js +4 -0
  11. package/dist/prompts/PromptBuilder.js +7 -0
  12. package/dist/prompts/types.d.ts +2 -0
  13. package/dist/runtime/InMemoryRetrievalCache.d.ts +25 -0
  14. package/dist/runtime/InMemoryRetrievalCache.js +59 -0
  15. package/dist/runtime/KnowledgeProvider.js +6 -1
  16. package/dist/runtime/Runtime.d.ts +44 -0
  17. package/dist/runtime/Runtime.js +196 -13
  18. package/dist/runtime/TokenAccumulator.d.ts +7 -0
  19. package/dist/runtime/TokenAccumulator.js +7 -0
  20. package/dist/runtime/TraceRecorder.d.ts +33 -0
  21. package/dist/runtime/TraceRecorder.js +290 -0
  22. package/dist/runtime/channels/TextDriver.js +45 -22
  23. package/dist/runtime/channels/executeModelTool.d.ts +8 -1
  24. package/dist/runtime/channels/executeModelTool.js +70 -1
  25. package/dist/runtime/channels/inputBuffer.d.ts +1 -0
  26. package/dist/runtime/channels/inputBuffer.js +9 -0
  27. package/dist/runtime/closeRun.js +11 -8
  28. package/dist/runtime/compaction.d.ts +2 -0
  29. package/dist/runtime/compaction.js +3 -2
  30. package/dist/runtime/ctx.js +110 -57
  31. package/dist/runtime/durable/RunStore.d.ts +16 -0
  32. package/dist/runtime/durable/RunStore.js +6 -0
  33. package/dist/runtime/durable/SessionRunStore.d.ts +7 -2
  34. package/dist/runtime/durable/SessionRunStore.js +136 -34
  35. package/dist/runtime/durable/idempotency.d.ts +1 -0
  36. package/dist/runtime/durable/idempotency.js +3 -0
  37. package/dist/runtime/durable/replay.js +7 -2
  38. package/dist/runtime/durable/types.d.ts +11 -0
  39. package/dist/runtime/goals.d.ts +18 -0
  40. package/dist/runtime/goals.js +158 -0
  41. package/dist/runtime/grounding/knowledge.js +1 -1
  42. package/dist/runtime/handoffContinuation.d.ts +20 -0
  43. package/dist/runtime/handoffContinuation.js +30 -0
  44. package/dist/runtime/handoffOscillation.d.ts +6 -0
  45. package/dist/runtime/handoffOscillation.js +17 -0
  46. package/dist/runtime/hostLoop.js +11 -0
  47. package/dist/runtime/index.d.ts +3 -1
  48. package/dist/runtime/index.js +1 -0
  49. package/dist/runtime/openRun.d.ts +2 -0
  50. package/dist/runtime/openRun.js +46 -17
  51. package/dist/runtime/policies/limits.d.ts +1 -0
  52. package/dist/runtime/policies/limits.js +3 -0
  53. package/dist/runtime/select.d.ts +5 -1
  54. package/dist/runtime/select.js +30 -1
  55. package/dist/runtime/turnTokenUsage.d.ts +28 -0
  56. package/dist/runtime/turnTokenUsage.js +70 -0
  57. package/dist/session/SessionStore.d.ts +6 -0
  58. package/dist/session/SessionStore.js +12 -1
  59. package/dist/session/stores/MemoryStore.d.ts +1 -1
  60. package/dist/session/stores/MemoryStore.js +16 -2
  61. package/dist/session/testing.d.ts +6 -1
  62. package/dist/session/testing.js +34 -0
  63. package/dist/session/utils.d.ts +3 -0
  64. package/dist/session/utils.js +23 -0
  65. package/dist/tools/effect/ToolExecutor.js +4 -1
  66. package/dist/tools/effect/defineTool.d.ts +2 -0
  67. package/dist/tools/effect/defineTool.js +2 -0
  68. package/dist/tracing/MemoryTraceStore.d.ts +16 -0
  69. package/dist/tracing/MemoryTraceStore.js +56 -0
  70. package/dist/tracing/OtelTraceSink.d.ts +127 -0
  71. package/dist/tracing/OtelTraceSink.js +101 -0
  72. package/dist/tracing/TraceStore.d.ts +19 -0
  73. package/dist/tracing/TraceStore.js +32 -0
  74. package/dist/tracing/index.d.ts +3 -0
  75. package/dist/tracing/index.js +3 -0
  76. package/dist/tracing/testing.d.ts +3 -0
  77. package/dist/tracing/testing.js +45 -0
  78. package/dist/types/agentConfig.d.ts +2 -1
  79. package/dist/types/channel.d.ts +14 -1
  80. package/dist/types/effectTool.d.ts +4 -0
  81. package/dist/types/index.d.ts +1 -0
  82. package/dist/types/index.js +1 -0
  83. package/dist/types/run-context.d.ts +14 -1
  84. package/dist/types/session.d.ts +10 -0
  85. package/dist/types/stream.d.ts +8 -0
  86. package/dist/types/trace.d.ts +50 -0
  87. package/dist/types/trace.js +1 -0
  88. package/guides/EXAMPLE_VERIFICATION.md +4 -4
  89. package/package.json +13 -4
@@ -10,7 +10,7 @@ import type { Limits } from './guardrails.js';
10
10
  import type { AnyTool } from './effectTool.js';
11
11
  import type { FileSystem } from './filesystem.js';
12
12
  import type { Instructions } from './agentConfig.js';
13
- import type { AgentKnowledgeOverrides, SourceRef } from './voice.js';
13
+ import type { AgentKnowledgeOverrides, SourceRef, RetrievalCacheAdapter } from './voice.js';
14
14
  export interface GatherScope {
15
15
  query?: string;
16
16
  knowledge?: AgentKnowledgeOverrides & {
@@ -80,6 +80,13 @@ export interface RunContext {
80
80
  turnInputConsumed?: boolean;
81
81
  /** Citations from the latest gather-phase retrieval on this turn. */
82
82
  lastRetrievalCitations?: SourceRef[];
83
+ /**
84
+ * Session retrieval cache (G6): created once per run by the KnowledgeProvider,
85
+ * persists across in-session agent handoffs (this RunContext survives the
86
+ * handoff branch). Keyed by query embedding; RAG-only, undefined without a
87
+ * configured knowledge provider + embedder.
88
+ */
89
+ retrievalCache?: RetrievalCacheAdapter;
83
90
  /** Agent base layer (ADR 0001), set when entering a flow. `baseInstructions`
84
91
  * is composed as a prefix into every node turn's system prompt (persona /
85
92
  * safety / grounding floor); `globalTools` are safe tools made model-visible
@@ -98,6 +105,10 @@ export interface RunContext {
98
105
  toolCallId?: string;
99
106
  def?: AnyTool;
100
107
  toolCtx?: ToolContext;
108
+ /** Pre-reserved callsite ordinal for parallel-safe tool batches (G9). */
109
+ callsite?: string;
110
+ /** Pre-reserved journal index for parallel-safe tool batches (G9). */
111
+ index?: number;
101
112
  }): Promise<unknown>;
102
113
  approve(req: {
103
114
  title: string;
@@ -116,6 +127,8 @@ export interface RunContext {
116
127
  * a flow's durable callsites are anchored to the flow — identical on fresh entry
117
128
  * (after an answering turn) and on resume (where that turn does not re-run). */
118
129
  resetCallsites(): void;
130
+ /** Reserve N contiguous effect callsite ordinals for parallel-safe tool batches (G9). */
131
+ reserveCallsites(count: number): string[];
119
132
  }
120
133
  export type ActionContext = Pick<RunContext, 'tool' | 'approve' | 'signal' | 'now' | 'uuid' | 'emit' | 'fs'>;
121
134
  export type ToolContext = Pick<RunContext, 'session' | 'runState' | 'tool' | 'now' | 'uuid' | 'emit' | 'fs' | 'abortSignal'>;
@@ -6,6 +6,14 @@ import type { ConversationOutcomeRecord, CsatRecord } from '../outcomes/types.js
6
6
  import type { PersonaExperimentMetadata } from '../persona/types.js';
7
7
  import type { ConversationAuditEntry } from '../audit/types.js';
8
8
  export type ChannelId = 'web' | 'email' | 'sms' | 'voice' | 'api' | 'slack' | 'discord' | (string & {});
9
+ /** Structured goal/thread entry on session.workingMemory.__goals (G5). */
10
+ export type GoalStatus = 'open' | 'resolved';
11
+ export interface TrackedGoal {
12
+ topic: string;
13
+ status: GoalStatus;
14
+ lastTurn: number;
15
+ note?: string;
16
+ }
9
17
  export interface WorkingMemory {
10
18
  get<T>(key: string): T | undefined;
11
19
  set<T>(key: string, value: T): void;
@@ -42,6 +50,8 @@ export interface Session {
42
50
  pendingRefinement?: RefinementStageResult;
43
51
  /** @internal Pending key-facts extraction promises. Awaited before session save. */
44
52
  __pendingExtractions?: Promise<void>[];
53
+ /** Optimistic-concurrency version; must match the stored row on save (C2 CAS). */
54
+ version?: number;
45
55
  }
46
56
  export interface SessionMetadata {
47
57
  createdAt: Date;
@@ -116,6 +116,14 @@ export type HarnessStreamPart = {
116
116
  } | {
117
117
  type: 'done';
118
118
  sessionId: string;
119
+ /** Per-turn token usage: `inputTokens`/`outputTokens` are THIS turn's
120
+ * consumption (deltas, for cost attribution); `contextTokens` is the current
121
+ * context-window occupancy (last prompt tokens, a snapshot). */
122
+ usage?: {
123
+ inputTokens?: number;
124
+ outputTokens?: number;
125
+ contextTokens?: number;
126
+ };
119
127
  };
120
128
  export interface TurnHandle extends Promise<import('./channel.js').TurnResult> {
121
129
  readonly events: AsyncIterable<HarnessStreamPart>;
@@ -0,0 +1,50 @@
1
+ export type SpanKind = 'turn' | 'flow' | 'node' | 'tool' | 'handoff' | 'llm';
2
+ export interface AgentSpan {
3
+ traceId: string;
4
+ spanId: string;
5
+ parentSpanId?: string;
6
+ name: string;
7
+ kind: SpanKind;
8
+ startTime: number;
9
+ endTime?: number;
10
+ status: 'ok' | 'error';
11
+ events?: Array<{
12
+ name: string;
13
+ time: number;
14
+ attributes?: Record<string, unknown>;
15
+ }>;
16
+ attributes: {
17
+ sessionId: string;
18
+ activeFlow?: string;
19
+ nodeId?: string;
20
+ toolName?: string;
21
+ handoffFrom?: string;
22
+ handoffTo?: string;
23
+ input?: unknown;
24
+ output?: unknown;
25
+ error?: string;
26
+ /** Input tokens consumed by this turn (delta — for cost attribution). */
27
+ tokensIn?: number;
28
+ /** Output tokens generated by this turn (delta — for cost attribution). */
29
+ tokensOut?: number;
30
+ /** Context-window occupancy at this turn (last prompt tokens — a snapshot, not a delta). */
31
+ contextTokens?: number;
32
+ };
33
+ }
34
+ export interface AgentTrace {
35
+ traceId: string;
36
+ sessionId: string;
37
+ spans: AgentSpan[];
38
+ answer: string;
39
+ usedTool: boolean;
40
+ toolCalls: Array<{
41
+ name: string;
42
+ args: unknown;
43
+ }>;
44
+ toolResults: Array<{
45
+ name: string;
46
+ result: unknown;
47
+ }>;
48
+ startedAt: number;
49
+ endedAt?: number;
50
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -8,8 +8,8 @@ This verification was run after runtime policy-profile changes to check for regr
8
8
 
9
9
  Covered suites:
10
10
 
11
- 1. `packages/kuralle-core/examples/agents` (Line parity set)
12
- 2. `packages/kuralle-core/examples/flows` (Pipecat parity set)
11
+ 1. `packages/core/examples/agents` (Line parity set)
12
+ 2. `packages/core/examples/flows` (Pipecat parity set)
13
13
  3. Extended package examples (`kuralle-tools`, `kuralle-redis-store`)
14
14
 
15
15
  ## Results
@@ -30,8 +30,8 @@ Interpretation:
30
30
 
31
31
  Non-pass items:
32
32
 
33
- 1. `packages/kuralle-redis-store/examples/local-redis/test.ts` -> `SKIPPED`
34
- 2. `packages/kuralle-redis-store/examples/local-redis/multi-turn.ts` -> `SKIPPED`
33
+ 1. `packages/redis-store/examples/local-redis/test.ts` -> `SKIPPED`
34
+ 2. `packages/redis-store/examples/local-redis/multi-turn.ts` -> `SKIPPED`
35
35
  - Cause: local Redis was not started.
36
36
 
37
37
  ## Verdict
package/package.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kuralle/kuralle-agents.git",
7
- "directory": "packages/kuralle-core"
7
+ "directory": "packages/core"
8
8
  },
9
- "version": "0.12.0",
9
+ "version": "0.13.0",
10
10
  "description": "A framework for structured conversational AI agents",
11
11
  "publishConfig": {
12
12
  "access": "public"
@@ -48,6 +48,14 @@
48
48
  "types": "./dist/session/testing.d.ts",
49
49
  "default": "./dist/session/testing.js"
50
50
  },
51
+ "./tracing": {
52
+ "types": "./dist/tracing/index.d.ts",
53
+ "default": "./dist/tracing/index.js"
54
+ },
55
+ "./tracing/testing": {
56
+ "types": "./dist/tracing/testing.d.ts",
57
+ "default": "./dist/tracing/testing.js"
58
+ },
51
59
  "./testing": {
52
60
  "types": "./dist/testing/index.d.ts",
53
61
  "default": "./dist/testing/index.js"
@@ -94,8 +102,8 @@
94
102
  "zod": "^4.0.0"
95
103
  },
96
104
  "devDependencies": {
97
- "@cloudflare/vitest-pool-workers": "^0.12.7",
98
105
  "@ai-sdk/openai": "^3.0.0",
106
+ "@cloudflare/vitest-pool-workers": "^0.12.7",
99
107
  "@types/node": "^20.11.0",
100
108
  "ai": "^6.0.0",
101
109
  "bun-types": "^1.3.0",
@@ -103,7 +111,8 @@
103
111
  "typescript": "^5.3.0",
104
112
  "vitest": "^3.2.4",
105
113
  "zod": "^4.0.0",
106
- "@kuralle-agents/realtime-audio": "0.12.0"
114
+ "@kuralle-agents/fs": "0.13.0",
115
+ "@kuralle-agents/realtime-audio": "0.13.0"
107
116
  },
108
117
  "dependencies": {
109
118
  "chrono-node": "^2.6.0"