@framers/agentos 0.1.181 → 0.1.182

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 (58) hide show
  1. package/README.md +101 -0
  2. package/dist/api/agent.d.ts +24 -0
  3. package/dist/api/agent.d.ts.map +1 -1
  4. package/dist/api/agent.js.map +1 -1
  5. package/dist/core/validation/ValidatedLlmInvoker.d.ts +80 -0
  6. package/dist/core/validation/ValidatedLlmInvoker.d.ts.map +1 -0
  7. package/dist/core/validation/ValidatedLlmInvoker.js +176 -0
  8. package/dist/core/validation/ValidatedLlmInvoker.js.map +1 -0
  9. package/dist/core/validation/errors.d.ts +53 -0
  10. package/dist/core/validation/errors.d.ts.map +1 -0
  11. package/dist/core/validation/errors.js +42 -0
  12. package/dist/core/validation/errors.js.map +1 -0
  13. package/dist/core/validation/extractJson.d.ts +35 -0
  14. package/dist/core/validation/extractJson.d.ts.map +1 -0
  15. package/dist/core/validation/extractJson.js +179 -0
  16. package/dist/core/validation/extractJson.js.map +1 -0
  17. package/dist/core/validation/index.d.ts +14 -0
  18. package/dist/core/validation/index.d.ts.map +1 -0
  19. package/dist/core/validation/index.js +14 -0
  20. package/dist/core/validation/index.js.map +1 -0
  21. package/dist/core/validation/schema-primitives.d.ts +132 -0
  22. package/dist/core/validation/schema-primitives.d.ts.map +1 -0
  23. package/dist/core/validation/schema-primitives.js +141 -0
  24. package/dist/core/validation/schema-primitives.js.map +1 -0
  25. package/dist/memory/AgentMemory.d.ts +118 -1
  26. package/dist/memory/AgentMemory.d.ts.map +1 -1
  27. package/dist/memory/AgentMemory.js +388 -0
  28. package/dist/memory/AgentMemory.js.map +1 -1
  29. package/dist/memory/CognitiveMemoryManager.d.ts +44 -0
  30. package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -1
  31. package/dist/memory/CognitiveMemoryManager.js +131 -5
  32. package/dist/memory/CognitiveMemoryManager.js.map +1 -1
  33. package/dist/memory/core/config.d.ts +49 -9
  34. package/dist/memory/core/config.d.ts.map +1 -1
  35. package/dist/memory/core/config.js +13 -0
  36. package/dist/memory/core/config.js.map +1 -1
  37. package/dist/memory/core/prompt/MemoryPromptAssembler.d.ts.map +1 -1
  38. package/dist/memory/core/prompt/MemoryPromptAssembler.js +59 -5
  39. package/dist/memory/core/prompt/MemoryPromptAssembler.js.map +1 -1
  40. package/dist/memory/core/types.d.ts +97 -0
  41. package/dist/memory/core/types.d.ts.map +1 -1
  42. package/dist/memory/pipeline/observation/MemoryReflector.d.ts +28 -1
  43. package/dist/memory/pipeline/observation/MemoryReflector.d.ts.map +1 -1
  44. package/dist/memory/pipeline/observation/MemoryReflector.js +80 -8
  45. package/dist/memory/pipeline/observation/MemoryReflector.js.map +1 -1
  46. package/dist/memory/retrieval/hyde/MemoryHydeRetriever.d.ts +69 -0
  47. package/dist/memory/retrieval/hyde/MemoryHydeRetriever.d.ts.map +1 -0
  48. package/dist/memory/retrieval/hyde/MemoryHydeRetriever.js +97 -0
  49. package/dist/memory/retrieval/hyde/MemoryHydeRetriever.js.map +1 -0
  50. package/dist/memory/retrieval/store/MemoryStore.d.ts +15 -0
  51. package/dist/memory/retrieval/store/MemoryStore.d.ts.map +1 -1
  52. package/dist/memory/retrieval/store/MemoryStore.js +67 -0
  53. package/dist/memory/retrieval/store/MemoryStore.js.map +1 -1
  54. package/dist/memory/retrieval/store/SqliteBrain.d.ts +7 -0
  55. package/dist/memory/retrieval/store/SqliteBrain.d.ts.map +1 -1
  56. package/dist/memory/retrieval/store/SqliteBrain.js +39 -0
  57. package/dist/memory/retrieval/store/SqliteBrain.js.map +1 -1
  58. package/package.json +1 -1
package/README.md CHANGED
@@ -584,6 +584,46 @@ Pass `{}` for all defaults, or omit entirely to disable (zero overhead).
584
584
 
585
585
  Memory is organized in a 4-tier hierarchy: `core/` (encoding, decay, working memory), `retrieval/` (composite scoring, graph, prospective), `pipeline/` (consolidation, observation, lifecycle), `io/` (ingestion, import/export).
586
586
 
587
+ **Automatic Memory Type Decomposition** -- the Observer→Reflector pipeline automatically classifies raw conversation into 5 memory types:
588
+
589
+ | Type | What it stores | Example |
590
+ |------|---------------|---------|
591
+ | **Episodic** | Autobiographical events | "User and I discussed deployment on March 5th" |
592
+ | **Semantic** | Durable facts | "User is a software engineer" |
593
+ | **Procedural** | Patterns and preferences | "User prefers concise answers" |
594
+ | **Prospective** | Future intentions | "User said they'd check back Friday" |
595
+ | **Relational** | Trust signals and bonds | "User shared vulnerability about work stress" |
596
+
597
+ The Reflector uses chain-of-thought reasoning and HEXACO personality bias to classify each trace. Commitment notes are auto-registered as prospective reminders.
598
+
599
+ **KnowledgeGraph** is enabled by default -- spreading activation (Collins & Quillian model), Hebbian co-activation learning, conflict detection, and graph-boosted retrieval scoring. Set `graph: { disabled: true }` to opt out.
600
+
601
+ **HyDE Memory Retrieval** -- a memory-specific Hypothetical Document Embedding retriever auto-attaches when an LLM invoker is available. Generates hypothetical stored traces for vague queries like "that thing about cats", improving recall. Opt-in per query via `retrieve({ hyde: true })`.
602
+
603
+ **Prompt Assembly Guidance** -- the `MemoryPromptAssembler` injects a personality-aware preamble that teaches the LLM how to use each memory type differently (semantic as background truth, episodic woven naturally, prospective as action items, relational as tone modulators).
604
+
605
+ **SqliteBrain Persistence** -- the cognitive memory path writes through to SqliteBrain's SQL tables via `@framers/sql-storage-adapter`. Traces survive process restarts. In-memory vector index is the hot read path; SQL is the durable backing store.
606
+
607
+ **Full API Surface** via `AgentMemory`:
608
+
609
+ ```typescript
610
+ const memory = AgentMemory.wrap(cognitiveManager);
611
+
612
+ // Visualization
613
+ const graph = await memory.getGraph(); // nodes, edges, clusters
614
+ const dist = await memory.getStrengthDistribution(); // per-type stats
615
+ const conflicts = await memory.getConflicts(); // contradicting traces
616
+
617
+ // Inspection
618
+ const relational = await memory.getRelationalMemories();
619
+ const working = await memory.getWorkingMemory(); // in-focus slots
620
+ const stats = await memory.getObservationStats(); // pipeline health
621
+
622
+ // Portability
623
+ const snapshot = await memory.exportSnapshot(); // full state export
624
+ await memory.importSnapshot(snapshot); // restore from export
625
+ ```
626
+
587
627
  See [`docs/memory/COGNITIVE_MECHANISMS.md`](./docs/memory/COGNITIVE_MECHANISMS.md) for API reference and 30+ APA citations.
588
628
 
589
629
  ### Multimodal RAG
@@ -599,6 +639,67 @@ Complete retrieval-augmented generation pipeline:
599
639
 
600
640
  See [`docs/memory/RAG_MEMORY_CONFIGURATION.md`](./docs/memory/RAG_MEMORY_CONFIGURATION.md) and [`docs/memory/MULTIMODAL_RAG.md`](./docs/memory/MULTIMODAL_RAG.md).
601
641
 
642
+ ### LLM Output Validation
643
+
644
+ Structured LLM outputs are validated with Zod schemas, retried with error feedback on failure, and use provider-native structured output when available.
645
+
646
+ ```typescript
647
+ import { createValidatedInvoker } from '@framers/agentos/core/validation';
648
+ import { z } from 'zod';
649
+
650
+ const PersonalitySchema = z.object({
651
+ honesty: z.number().min(0).max(100),
652
+ emotionality: z.number().min(0).max(100),
653
+ extraversion: z.number().min(0).max(100),
654
+ });
655
+
656
+ // Wrap any LLM invoker with Zod validation + retry
657
+ const validated = createValidatedInvoker(llmInvoker, PersonalitySchema, {
658
+ maxRetries: 2, // retry with error feedback on failure
659
+ injectSchemaOnRetry: true, // include schema description in retry prompt
660
+ });
661
+
662
+ const personality = await validated(systemPrompt, userPrompt);
663
+ // personality is typed as { honesty: number; emotionality: number; extraversion: number }
664
+ ```
665
+
666
+ **Centralized JSON extraction** handles all messy LLM output formats:
667
+
668
+ ```typescript
669
+ import { extractJson } from '@framers/agentos/core/validation';
670
+
671
+ extractJson('```json\n{"key": "value"}\n```'); // '{"key": "value"}'
672
+ extractJson('<thinking>hmm</thinking>\n{"a": 1}'); // '{"a": 1}'
673
+ extractJson('Result: {"a": 1} done'); // '{"a": 1}'
674
+ extractJson('{"a":1}\n{"b":2}'); // '[{"a":1},{"b":2}]' (JSONL)
675
+ ```
676
+
677
+ **Agent-level validation** via `responseSchema`:
678
+
679
+ ```typescript
680
+ const extractor = agent({
681
+ instructions: 'Extract entities as JSON',
682
+ responseSchema: z.object({ entities: z.array(z.string()) }),
683
+ });
684
+
685
+ const result = await extractor.generate('Find entities in: ...');
686
+ // result.parsed?.entities is string[] — typed and validated
687
+ ```
688
+
689
+ **Schema primitives** for composing domain-specific schemas:
690
+
691
+ ```typescript
692
+ import { MemoryTypeEnum, ConfidenceScore, EntityArray } from '@framers/agentos/core/validation';
693
+
694
+ const MySchema = z.object({
695
+ type: MemoryTypeEnum, // 'episodic' | 'semantic' | 'procedural' | 'prospective' | 'relational'
696
+ confidence: ConfidenceScore, // number 0-1
697
+ entities: EntityArray, // string[], defaults to []
698
+ });
699
+ ```
700
+
701
+ When validation fails after all retries, `LlmOutputValidationError` is thrown with the raw output, Zod errors, retry count, and full retry history for debugging.
702
+
602
703
  ### Adaptive Intelligence & Metacognition
603
704
 
604
705
  Agents don't just respond — they monitor their own performance and adapt their behavior in real-time.
@@ -55,6 +55,30 @@ export interface AgentOptions extends BaseAgentConfig {
55
55
  onFallback?: (error: Error, fallbackProvider: string) => void;
56
56
  /** Model router for intelligent provider selection per-call. */
57
57
  router?: IModelRouter;
58
+ /**
59
+ * Optional Zod schema for validating the LLM's structured output.
60
+ *
61
+ * When provided, the agent's `generate()` result includes a `parsed` field
62
+ * with the Zod-validated and typed output. JSON extraction and validation
63
+ * happen automatically in the `onAfterGeneration` hook. On validation failure,
64
+ * the agent retries internally (up to `controls.maxValidationRetries ?? 1`).
65
+ *
66
+ * When omitted, behavior is unchanged — `result.parsed` is undefined.
67
+ * This is a non-breaking additive change.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { z } from 'zod';
72
+ * const myAgent = agent({
73
+ * name: 'Extractor',
74
+ * instructions: 'Extract entities as JSON',
75
+ * responseSchema: z.object({ entities: z.array(z.string()) }),
76
+ * });
77
+ * const result = await myAgent.generate('Find entities in: ...');
78
+ * console.log(result.parsed?.entities); // string[]
79
+ * ```
80
+ */
81
+ responseSchema?: import('zod').ZodType;
58
82
  /** Pre-generation hook, called before each LLM step. */
59
83
  onBeforeGeneration?: (context: GenerationHookContext) => Promise<GenerationHookContext | void>;
60
84
  /** Post-generation hook, called after each LLM step. */
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/api/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAExG;;;;;;;GAOG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD;;;OAGG;IACH,WAAW,CAAC,EAAE,yBAAyB,CAAC;IACxC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC5C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,gEAAgE;IAChE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,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AAI;KACnB,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @fileoverview Validated LLM invoker wrapper with Zod schema validation and retry.
3
+ *
4
+ * Wraps any `(systemPrompt, userPrompt) => Promise<string>` LLM invoker function
5
+ * with automatic JSON extraction, Zod validation, and retry-with-feedback on failure.
6
+ *
7
+ * Pipeline:
8
+ * 1. Call LLM via the raw invoker
9
+ * 2. Extract JSON from response via `extractJson()` (handles markdown fences, thinking blocks, JSONL)
10
+ * 3. Parse with `JSON.parse`
11
+ * 4. Validate with Zod `.safeParse()` (applies defaults, type coercion)
12
+ * 5. If valid: return typed result
13
+ * 6. If invalid: retry with error feedback + optional schema description
14
+ * 7. If all retries fail: throw `LlmOutputValidationError` with full history
15
+ *
16
+ * @module agentos/core/validation/ValidatedLlmInvoker
17
+ */
18
+ import { type z } from 'zod';
19
+ /** LLM invoker function with optional capability flags. */
20
+ export interface LlmInvokerWithCapabilities {
21
+ (systemPrompt: string, userPrompt: string): Promise<string>;
22
+ /** Provider supports native JSON schema enforcement (Anthropic tool_use, OpenAI json_schema). */
23
+ supportsStructuredOutput?: boolean;
24
+ /** Provider ID for telemetry and logging. */
25
+ providerId?: string;
26
+ }
27
+ /** Options for the validated invoker wrapper. */
28
+ export interface ValidatedInvokerOptions {
29
+ /**
30
+ * Maximum number of retry attempts after the initial call fails validation.
31
+ * Each retry appends error feedback to the system prompt.
32
+ * @default 1
33
+ */
34
+ maxRetries?: number;
35
+ /**
36
+ * Whether to inject the JSON Schema description into the retry prompt
37
+ * so the LLM knows exactly what shape is expected.
38
+ * @default true
39
+ */
40
+ injectSchemaOnRetry?: boolean;
41
+ /**
42
+ * Whether to prefer provider-native structured output when available.
43
+ * When true and the invoker has `supportsStructuredOutput: true`, the
44
+ * Zod schema is converted to JSON Schema and passed to the provider.
45
+ * @default true
46
+ */
47
+ preferStructuredOutput?: boolean;
48
+ }
49
+ /**
50
+ * Create a validated LLM invoker that returns typed, Zod-validated results.
51
+ *
52
+ * Wraps a raw LLM invoker function with:
53
+ * 1. JSON extraction from messy LLM output (markdown fences, thinking blocks, etc.)
54
+ * 2. Zod `.safeParse()` validation with full type inference
55
+ * 3. Retry with error feedback + schema description on failure
56
+ * 4. `LlmOutputValidationError` with retry history when all attempts fail
57
+ *
58
+ * @param invoker - Raw LLM invoker function `(system, user) => Promise<string>`
59
+ * @param schema - Zod schema to validate the extracted JSON against
60
+ * @param options - Retry count, schema injection, structured output preference
61
+ * @returns A function with the same `(system, user)` signature that returns `z.infer<T>`
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const validated = createValidatedInvoker(llmInvoker, PersonalitySchema);
66
+ * const personality = await validated(systemPrompt, userPrompt);
67
+ * // personality is typed as z.infer<typeof PersonalitySchema>
68
+ * ```
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * // With retry configuration
73
+ * const validated = createValidatedInvoker(invoker, Schema, {
74
+ * maxRetries: 2,
75
+ * injectSchemaOnRetry: true,
76
+ * });
77
+ * ```
78
+ */
79
+ export declare function createValidatedInvoker<T extends z.ZodType>(invoker: LlmInvokerWithCapabilities | ((s: string, u: string) => Promise<string>), schema: T, options?: ValidatedInvokerOptions): (systemPrompt: string, userPrompt: string) => Promise<z.infer<T>>;
80
+ //# sourceMappingURL=ValidatedLlmInvoker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedLlmInvoker.d.ts","sourceRoot":"","sources":["../../../src/core/validation/ValidatedLlmInvoker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,CAAC,EAAY,MAAM,KAAK,CAAC;AAMvC,2DAA2D;AAC3D,MAAM,WAAW,0BAA0B;IACzC,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,iGAAiG;IACjG,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EACxD,OAAO,EAAE,0BAA0B,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,EACjF,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,uBAAuB,GAChC,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAiGnE"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @fileoverview Validated LLM invoker wrapper with Zod schema validation and retry.
3
+ *
4
+ * Wraps any `(systemPrompt, userPrompt) => Promise<string>` LLM invoker function
5
+ * with automatic JSON extraction, Zod validation, and retry-with-feedback on failure.
6
+ *
7
+ * Pipeline:
8
+ * 1. Call LLM via the raw invoker
9
+ * 2. Extract JSON from response via `extractJson()` (handles markdown fences, thinking blocks, JSONL)
10
+ * 3. Parse with `JSON.parse`
11
+ * 4. Validate with Zod `.safeParse()` (applies defaults, type coercion)
12
+ * 5. If valid: return typed result
13
+ * 6. If invalid: retry with error feedback + optional schema description
14
+ * 7. If all retries fail: throw `LlmOutputValidationError` with full history
15
+ *
16
+ * @module agentos/core/validation/ValidatedLlmInvoker
17
+ */
18
+ import { ZodError } from 'zod';
19
+ import { extractJson } from './extractJson.js';
20
+ import { LlmOutputValidationError } from './errors.js';
21
+ // ── Implementation ───────────────────────────────────────────────────────
22
+ /**
23
+ * Create a validated LLM invoker that returns typed, Zod-validated results.
24
+ *
25
+ * Wraps a raw LLM invoker function with:
26
+ * 1. JSON extraction from messy LLM output (markdown fences, thinking blocks, etc.)
27
+ * 2. Zod `.safeParse()` validation with full type inference
28
+ * 3. Retry with error feedback + schema description on failure
29
+ * 4. `LlmOutputValidationError` with retry history when all attempts fail
30
+ *
31
+ * @param invoker - Raw LLM invoker function `(system, user) => Promise<string>`
32
+ * @param schema - Zod schema to validate the extracted JSON against
33
+ * @param options - Retry count, schema injection, structured output preference
34
+ * @returns A function with the same `(system, user)` signature that returns `z.infer<T>`
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const validated = createValidatedInvoker(llmInvoker, PersonalitySchema);
39
+ * const personality = await validated(systemPrompt, userPrompt);
40
+ * // personality is typed as z.infer<typeof PersonalitySchema>
41
+ * ```
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // With retry configuration
46
+ * const validated = createValidatedInvoker(invoker, Schema, {
47
+ * maxRetries: 2,
48
+ * injectSchemaOnRetry: true,
49
+ * });
50
+ * ```
51
+ */
52
+ export function createValidatedInvoker(invoker, schema, options) {
53
+ const maxRetries = options?.maxRetries ?? 1;
54
+ const injectSchema = options?.injectSchemaOnRetry ?? true;
55
+ // Pre-compute a human-readable schema description for retry prompts.
56
+ // This is injected into the retry system prompt so the LLM knows
57
+ // exactly what JSON shape is expected on the next attempt.
58
+ const schemaDescription = describeSchema(schema);
59
+ return async (systemPrompt, userPrompt) => {
60
+ const retryHistory = [];
61
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
62
+ // On retries, append error feedback from the previous attempt
63
+ // so the LLM can correct its output. This dramatically improves
64
+ // success rates — most LLMs fix their JSON when told what's wrong.
65
+ let effectiveSystem = systemPrompt;
66
+ if (attempt > 0 && retryHistory.length > 0) {
67
+ const lastError = retryHistory[retryHistory.length - 1];
68
+ effectiveSystem = systemPrompt + '\n\n' +
69
+ `IMPORTANT: Your previous response was not valid. Error: ${lastError.error}\n` +
70
+ `Please output ONLY valid JSON matching the required format.` +
71
+ (injectSchema ? `\n\nRequired JSON format:\n${schemaDescription}` : '');
72
+ }
73
+ // Call the LLM
74
+ const rawOutput = await invoker(effectiveSystem, userPrompt);
75
+ // Extract JSON from the raw output using centralized extraction
76
+ const jsonStr = extractJson(rawOutput);
77
+ if (!jsonStr) {
78
+ retryHistory.push({
79
+ attempt,
80
+ rawOutput,
81
+ error: 'No JSON found in LLM output',
82
+ });
83
+ continue;
84
+ }
85
+ // Parse JSON
86
+ let parsed;
87
+ try {
88
+ parsed = JSON.parse(jsonStr);
89
+ }
90
+ catch (parseErr) {
91
+ retryHistory.push({
92
+ attempt,
93
+ rawOutput,
94
+ error: `JSON parse error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
95
+ });
96
+ continue;
97
+ }
98
+ // Validate with Zod — safeParse applies defaults and type coercion
99
+ const result = schema.safeParse(parsed);
100
+ if (result.success) {
101
+ return result.data;
102
+ }
103
+ // Validation failed — record the Zod error details for retry feedback
104
+ retryHistory.push({
105
+ attempt,
106
+ rawOutput,
107
+ error: `Zod validation: ${(result.error.issues ?? []).map((e) => `${(e.path ?? []).join('.')}: ${e.message}`).join('; ')}`,
108
+ });
109
+ }
110
+ // All attempts exhausted — throw with full history for debugging.
111
+ // The error includes the raw output and Zod errors from the final
112
+ // attempt, plus the complete retry history.
113
+ const lastRaw = retryHistory[retryHistory.length - 1]?.rawOutput ?? '';
114
+ // Build a ZodError from the final attempt's validation.
115
+ // Try to re-parse so we get the actual Zod errors from the last attempt.
116
+ let finalZodError;
117
+ const finalJsonStr = extractJson(lastRaw);
118
+ if (finalJsonStr) {
119
+ try {
120
+ const finalParsed = JSON.parse(finalJsonStr);
121
+ const finalResult = schema.safeParse(finalParsed);
122
+ finalZodError = finalResult.success
123
+ ? new ZodError([])
124
+ : finalResult.error;
125
+ }
126
+ catch {
127
+ finalZodError = new ZodError([]);
128
+ }
129
+ }
130
+ else {
131
+ finalZodError = new ZodError([]);
132
+ }
133
+ throw new LlmOutputValidationError(`LLM output validation failed after ${maxRetries} retries: ${retryHistory[retryHistory.length - 1]?.error ?? 'Unknown error'}`, lastRaw, finalZodError, maxRetries, retryHistory);
134
+ };
135
+ }
136
+ /**
137
+ * Generate a human-readable description of a Zod schema for injection
138
+ * into retry prompts. The LLM sees this and knows what JSON shape to produce.
139
+ *
140
+ * Uses `zod-to-json-schema` when available for accurate conversion.
141
+ * Falls back to a simple string representation when the library is
142
+ * not installed (non-critical — retry still works with error feedback alone).
143
+ *
144
+ * @param schema - Zod schema to describe
145
+ * @returns Multi-line string describing the expected JSON structure
146
+ */
147
+ function describeSchema(schema) {
148
+ // Extract field names from Zod shape for a human-readable description.
149
+ // Zod v4 stores shape as a plain object on `_def.shape`.
150
+ // Zod v3 stores it as a function `_def.shape()`.
151
+ try {
152
+ const rawShape = schema._def?.shape;
153
+ const shape = typeof rawShape === 'function' ? rawShape() : rawShape;
154
+ if (shape && typeof shape === 'object') {
155
+ const fields = Object.keys(shape).join(', ');
156
+ return `A JSON object with these fields: ${fields}`;
157
+ }
158
+ }
159
+ catch {
160
+ // Ignore shape extraction failure
161
+ }
162
+ // Try zod-to-json-schema for complex schemas (optional dependency)
163
+ try {
164
+ const zodToJsonSchema = require('zod-to-json-schema').zodToJsonSchema;
165
+ const jsonSchema = zodToJsonSchema(schema);
166
+ const str = JSON.stringify(jsonSchema, null, 2);
167
+ // zod-to-json-schema may return {} for Zod v4 — check for useful content
168
+ if (str.length > 10)
169
+ return str;
170
+ }
171
+ catch {
172
+ // Not available — use field-name fallback above
173
+ }
174
+ return 'A valid JSON object matching the required schema';
175
+ }
176
+ //# sourceMappingURL=ValidatedLlmInvoker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatedLlmInvoker.js","sourceRoot":"","sources":["../../../src/core/validation/ValidatedLlmInvoker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAg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AK,QAAQ,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,OAAO,oCAAoC,MAAM,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,kCAAkC;IACpC,CAAC;IAED,mEAAmE;IACnE,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,eAAe,CAAC;QACtE,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAChD,yEAAyE;QACzE,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;YAAE,OAAO,GAAG,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,gDAAgD;IAClD,CAAC;IAED,OAAO,kDAAkD,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview Error types for LLM output validation failures.
3
+ *
4
+ * {@link LlmOutputValidationError} is thrown when LLM output fails Zod
5
+ * validation after all retry attempts. It carries the raw output, Zod
6
+ * errors, retry count, and full retry history so callers can debug,
7
+ * log, or surface the failure appropriately.
8
+ *
9
+ * @module agentos/core/validation/errors
10
+ */
11
+ import type { ZodError } from 'zod';
12
+ /** A single retry attempt record for debugging and telemetry. */
13
+ export interface ValidationRetryRecord {
14
+ /** Zero-based attempt index (0 = initial attempt). */
15
+ attempt: number;
16
+ /** Raw LLM output from this attempt. */
17
+ rawOutput: string;
18
+ /** Human-readable error description (parse error or Zod validation error). */
19
+ error: string;
20
+ }
21
+ /**
22
+ * Thrown when LLM output fails Zod validation after all retry attempts.
23
+ *
24
+ * Contains the raw LLM response, Zod validation errors, retry count,
25
+ * and full retry history for debugging and telemetry. Callers can
26
+ * inspect `retryHistory` to understand what the LLM produced on each
27
+ * attempt and why it failed.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * try {
32
+ * const result = await validatedInvoker(system, user);
33
+ * } catch (err) {
34
+ * if (err instanceof LlmOutputValidationError) {
35
+ * console.error('Validation failed after', err.retryCount, 'retries');
36
+ * console.error('Zod errors:', err.zodErrors);
37
+ * console.error('Raw output:', err.rawOutput);
38
+ * }
39
+ * }
40
+ * ```
41
+ */
42
+ export declare class LlmOutputValidationError extends Error {
43
+ /** Raw LLM output from the final attempt. */
44
+ readonly rawOutput: string;
45
+ /** Zod validation errors from the final attempt. */
46
+ readonly zodErrors: ZodError;
47
+ /** Number of retry attempts made (0 = failed on first try with no retries configured). */
48
+ readonly retryCount: number;
49
+ /** Full retry history for debugging — each attempt's raw output and error message. */
50
+ readonly retryHistory: ValidationRetryRecord[];
51
+ constructor(message: string, rawOutput: string, zodErrors: ZodError, retryCount: number, retryHistory: ValidationRetryRecord[]);
52
+ }
53
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/validation/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,iEAAiE;AACjE,MAAM,WAAW,qBAAqB;IACpC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sFAAsF;IACtF,QAAQ,CAAC,YAAY,EAAE,qBAAqB,EAAE,CAAC;gBAG7C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,QAAQ,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,qBAAqB,EAAE;CASxC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview Error types for LLM output validation failures.
3
+ *
4
+ * {@link LlmOutputValidationError} is thrown when LLM output fails Zod
5
+ * validation after all retry attempts. It carries the raw output, Zod
6
+ * errors, retry count, and full retry history so callers can debug,
7
+ * log, or surface the failure appropriately.
8
+ *
9
+ * @module agentos/core/validation/errors
10
+ */
11
+ /**
12
+ * Thrown when LLM output fails Zod validation after all retry attempts.
13
+ *
14
+ * Contains the raw LLM response, Zod validation errors, retry count,
15
+ * and full retry history for debugging and telemetry. Callers can
16
+ * inspect `retryHistory` to understand what the LLM produced on each
17
+ * attempt and why it failed.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * try {
22
+ * const result = await validatedInvoker(system, user);
23
+ * } catch (err) {
24
+ * if (err instanceof LlmOutputValidationError) {
25
+ * console.error('Validation failed after', err.retryCount, 'retries');
26
+ * console.error('Zod errors:', err.zodErrors);
27
+ * console.error('Raw output:', err.rawOutput);
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export class LlmOutputValidationError extends Error {
33
+ constructor(message, rawOutput, zodErrors, retryCount, retryHistory) {
34
+ super(message);
35
+ this.name = 'LlmOutputValidationError';
36
+ this.rawOutput = rawOutput;
37
+ this.zodErrors = zodErrors;
38
+ this.retryCount = retryCount;
39
+ this.retryHistory = retryHistory;
40
+ }
41
+ }
42
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/core/validation/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAcH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAUjD,YACE,OAAe,EACf,SAAiB,EACjB,SAAmB,EACnB,UAAkB,EAClB,YAAqC;QAErC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview Centralized JSON extraction from messy LLM output.
3
+ *
4
+ * LLMs return structured data in many formats: raw JSON, markdown-fenced
5
+ * blocks, JSON wrapped in prose, JSONL, or JSON preceded by chain-of-thought
6
+ * `<thinking>` blocks. This module handles all of them with a priority-ordered
7
+ * extraction pipeline.
8
+ *
9
+ * Replaces the ad-hoc `JSON.parse` + `match()` + `split('\n')` patterns
10
+ * duplicated across 30+ files in AgentOS and wilds-ai.
11
+ *
12
+ * @module agentos/core/validation/extractJson
13
+ */
14
+ /**
15
+ * Extract JSON from raw LLM output text.
16
+ *
17
+ * Tries multiple extraction strategies in priority order:
18
+ * 1. Raw JSON (entire string is valid JSON)
19
+ * 2. Markdown fenced blocks (```json ... ``` or ``` ... ```)
20
+ * 3. Strip `<thinking>` blocks, then retry
21
+ * 4. First `{...}` or `[...]` via greedy brace/bracket matching
22
+ * 5. JSONL (multiple JSON objects on separate lines → array)
23
+ *
24
+ * @param rawText - Raw LLM output that may contain JSON
25
+ * @returns Extracted JSON string, or null if no valid JSON found
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * extractJson('```json\n{"key": "value"}\n```') // '{"key": "value"}'
30
+ * extractJson('<thinking>hmm</thinking>\n{"a":1}') // '{"a":1}'
31
+ * extractJson('no json here') // null
32
+ * ```
33
+ */
34
+ export declare function extractJson(rawText: string): string | null;
35
+ //# sourceMappingURL=extractJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractJson.d.ts","sourceRoot":"","sources":["../../../src/core/validation/extractJson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoE1D"}