coaiajs 0.1.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 (162) hide show
  1. package/CLAUDE.md +56 -0
  2. package/KINSHIP.md +63 -0
  3. package/README.md +148 -0
  4. package/articles/academic/creative-orientation-vs-problem-solving.md +177 -0
  5. package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +142 -0
  6. package/articles/academic/langfuse-observability-llm-pipelines.md +144 -0
  7. package/articles/academic/medicine-wheel-software-architecture.md +163 -0
  8. package/articles/academic/mmot-autonomous-agents.md +156 -0
  9. package/articles/academic/model-context-protocol-interagent.md +161 -0
  10. package/articles/academic/pde-prompt-decomposition.md +186 -0
  11. package/articles/academic/structural-tension-in-ai-agents.md +134 -0
  12. package/articles/reviews/mcp-protocol-design-review.md +170 -0
  13. package/articles/reviews/observability-ai-systems-review.md +176 -0
  14. package/articles/reviews/prompt-engineering-decomposition-review.md +184 -0
  15. package/articles/surveys/agent-orchestration-survey.md +186 -0
  16. package/articles/surveys/knowledge-graph-storage-survey.md +204 -0
  17. package/articles/surveys/structural-tension-methodology-survey.md +154 -0
  18. package/articles/technical/aws-sdk-v3-polly.md +270 -0
  19. package/articles/technical/commander-cli-framework.md +262 -0
  20. package/articles/technical/dotenv-config-patterns.md +360 -0
  21. package/articles/technical/ioredis-vs-redis.md +142 -0
  22. package/articles/technical/langfuse-js-sdk-vs-rest.md +191 -0
  23. package/articles/technical/mcp-sdk-typescript.md +291 -0
  24. package/articles/technical/octokit-github-api.md +293 -0
  25. package/articles/technical/openai-sdk-modern.md +231 -0
  26. package/articles/technical/yaml-parsing-node.md +266 -0
  27. package/articles/technical/zod-runtime-validation.md +212 -0
  28. package/dist/mcp/config.d.ts +14 -0
  29. package/dist/mcp/config.js +185 -0
  30. package/dist/mcp/server.d.ts +3 -0
  31. package/dist/mcp/server.js +324 -0
  32. package/dist/mcp/tools/coaiapy-tools.d.ts +8 -0
  33. package/dist/mcp/tools/coaiapy-tools.js +326 -0
  34. package/dist/mcp/tools/index.d.ts +3 -0
  35. package/dist/mcp/tools/index.js +3 -0
  36. package/dist/src/audio.d.ts +12 -0
  37. package/dist/src/audio.js +57 -0
  38. package/dist/src/cli-helpers.d.ts +9 -0
  39. package/dist/src/cli-helpers.js +78 -0
  40. package/dist/src/cli.d.ts +3 -0
  41. package/dist/src/cli.js +1086 -0
  42. package/dist/src/config.d.ts +15 -0
  43. package/dist/src/config.js +145 -0
  44. package/dist/src/environment.d.ts +44 -0
  45. package/dist/src/environment.js +146 -0
  46. package/dist/src/github.d.ts +47 -0
  47. package/dist/src/github.js +79 -0
  48. package/dist/src/langfuse/client.d.ts +30 -0
  49. package/dist/src/langfuse/client.js +75 -0
  50. package/dist/src/langfuse/comments.d.ts +16 -0
  51. package/dist/src/langfuse/comments.js +36 -0
  52. package/dist/src/langfuse/datasets.d.ts +19 -0
  53. package/dist/src/langfuse/datasets.js +140 -0
  54. package/dist/src/langfuse/index.d.ts +13 -0
  55. package/dist/src/langfuse/index.js +10 -0
  56. package/dist/src/langfuse/media.d.ts +11 -0
  57. package/dist/src/langfuse/media.js +167 -0
  58. package/dist/src/langfuse/observations.d.ts +18 -0
  59. package/dist/src/langfuse/observations.js +113 -0
  60. package/dist/src/langfuse/prompts.d.ts +14 -0
  61. package/dist/src/langfuse/prompts.js +127 -0
  62. package/dist/src/langfuse/scores.d.ts +54 -0
  63. package/dist/src/langfuse/scores.js +366 -0
  64. package/dist/src/langfuse/traces.d.ts +29 -0
  65. package/dist/src/langfuse/traces.js +225 -0
  66. package/dist/src/llm.d.ts +23 -0
  67. package/dist/src/llm.js +76 -0
  68. package/dist/src/narrative/graph-manager.d.ts +106 -0
  69. package/dist/src/narrative/graph-manager.js +915 -0
  70. package/dist/src/narrative/index.d.ts +9 -0
  71. package/dist/src/narrative/index.js +7 -0
  72. package/dist/src/narrative/markdown-export.d.ts +21 -0
  73. package/dist/src/narrative/markdown-export.js +383 -0
  74. package/dist/src/narrative/tool-definitions.d.ts +21 -0
  75. package/dist/src/narrative/tool-definitions.js +588 -0
  76. package/dist/src/narrative/tool-handlers.d.ts +11 -0
  77. package/dist/src/narrative/tool-handlers.js +462 -0
  78. package/dist/src/narrative/types.d.ts +2 -0
  79. package/dist/src/narrative/types.js +2 -0
  80. package/dist/src/narrative/validation.d.ts +29 -0
  81. package/dist/src/narrative/validation.js +144 -0
  82. package/dist/src/pde/index.d.ts +8 -0
  83. package/dist/src/pde/index.js +8 -0
  84. package/dist/src/pde/mcp-handlers.d.ts +7 -0
  85. package/dist/src/pde/mcp-handlers.js +300 -0
  86. package/dist/src/pde/mcp-tools.d.ts +15 -0
  87. package/dist/src/pde/mcp-tools.js +191 -0
  88. package/dist/src/pde/session-manager.d.ts +32 -0
  89. package/dist/src/pde/session-manager.js +205 -0
  90. package/dist/src/pde/stc-mapper.d.ts +26 -0
  91. package/dist/src/pde/stc-mapper.js +234 -0
  92. package/dist/src/pipeline/index.d.ts +2 -0
  93. package/dist/src/pipeline/index.js +3 -0
  94. package/dist/src/pipeline/template-engine.d.ts +20 -0
  95. package/dist/src/pipeline/template-engine.js +361 -0
  96. package/dist/src/planning/index.d.ts +7 -0
  97. package/dist/src/planning/index.js +7 -0
  98. package/dist/src/planning/mcp-handlers.d.ts +7 -0
  99. package/dist/src/planning/mcp-handlers.js +310 -0
  100. package/dist/src/planning/mcp-tools.d.ts +15 -0
  101. package/dist/src/planning/mcp-tools.js +145 -0
  102. package/dist/src/planning/plan-parser.d.ts +35 -0
  103. package/dist/src/planning/plan-parser.js +506 -0
  104. package/dist/src/redis.d.ts +21 -0
  105. package/dist/src/redis.js +78 -0
  106. package/dist/src/types.d.ts +244 -0
  107. package/dist/src/types.js +8 -0
  108. package/mcp/config.ts +196 -0
  109. package/mcp/server.ts +402 -0
  110. package/mcp/tools/coaiapy-tools.ts +364 -0
  111. package/mcp/tools/index.ts +4 -0
  112. package/package.json +52 -0
  113. package/rispecs/00-coaiajs-platform.spec.md +102 -0
  114. package/rispecs/01-core-config.spec.md +89 -0
  115. package/rispecs/02-redis-module.spec.md +62 -0
  116. package/rispecs/03-langfuse-module.spec.md +101 -0
  117. package/rispecs/04-narrative-engine.spec.md +185 -0
  118. package/rispecs/05-pde-engine.spec.md +112 -0
  119. package/rispecs/06-planning-engine.spec.md +128 -0
  120. package/rispecs/07-pipeline-templates.spec.md +97 -0
  121. package/rispecs/08-cli-interface.spec.md +134 -0
  122. package/rispecs/09-mcp-server.spec.md +140 -0
  123. package/rispecs/10-audio-module.spec.md +63 -0
  124. package/rispecs/KINSHIP.md +56 -0
  125. package/rispecs/README.md +100 -0
  126. package/src/audio.ts +76 -0
  127. package/src/cli-helpers.ts +86 -0
  128. package/src/cli.ts +1223 -0
  129. package/src/config.ts +172 -0
  130. package/src/environment.ts +171 -0
  131. package/src/github.ts +143 -0
  132. package/src/langfuse/client.ts +105 -0
  133. package/src/langfuse/comments.ts +52 -0
  134. package/src/langfuse/datasets.ts +178 -0
  135. package/src/langfuse/index.ts +33 -0
  136. package/src/langfuse/media.ts +193 -0
  137. package/src/langfuse/observations.ts +131 -0
  138. package/src/langfuse/prompts.ts +157 -0
  139. package/src/langfuse/scores.ts +456 -0
  140. package/src/langfuse/traces.ts +276 -0
  141. package/src/llm.ts +106 -0
  142. package/src/narrative/graph-manager.ts +1358 -0
  143. package/src/narrative/index.ts +32 -0
  144. package/src/narrative/markdown-export.ts +535 -0
  145. package/src/narrative/tool-definitions.ts +635 -0
  146. package/src/narrative/tool-handlers.ts +528 -0
  147. package/src/narrative/types.ts +9 -0
  148. package/src/narrative/validation.ts +179 -0
  149. package/src/pde/index.ts +8 -0
  150. package/src/pde/mcp-handlers.ts +359 -0
  151. package/src/pde/mcp-tools.ts +201 -0
  152. package/src/pde/session-manager.ts +248 -0
  153. package/src/pde/stc-mapper.ts +298 -0
  154. package/src/pipeline/index.ts +7 -0
  155. package/src/pipeline/template-engine.ts +398 -0
  156. package/src/planning/index.ts +13 -0
  157. package/src/planning/mcp-handlers.ts +369 -0
  158. package/src/planning/mcp-tools.ts +155 -0
  159. package/src/planning/plan-parser.ts +587 -0
  160. package/src/redis.ts +97 -0
  161. package/src/types.ts +280 -0
  162. package/tsconfig.json +26 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,56 @@
1
+ # CLAUDE.md — coaiajs
2
+
3
+ ## Project Identity
4
+
5
+ `coaiajs` is the TypeScript consolidation of four CoAIA sub-projects into one monorepo. It produces a CLI (`coaia`), an MCP server (`coaiajs-mcp`), and a library.
6
+
7
+ ## Build & Test
8
+
9
+ ```bash
10
+ npm run build # tsc
11
+ npm run lint # tsc --noEmit
12
+ npm test # node --test
13
+ npm run dev # tsc --watch
14
+ ```
15
+
16
+ ## Conventions
17
+
18
+ - **ESM only** — `"type": "module"` in package.json. All imports use `.js` extensions.
19
+ - **Strict TypeScript** — `strict: true`, no `any` without justification.
20
+ - **Shared types** — All types live in `src/types.ts`. Sub-modules import from there.
21
+ - **Config** — `src/config.ts` handles all config loading. Env vars > .env > coaia.json.
22
+ - **Lazy clients** — Redis, OpenAI, Polly, Octokit clients are created lazily on first use. Each module exports a `resetClient()` for testing.
23
+ - **No side effects at import** — Modules must not connect to services or read files when imported.
24
+
25
+ ## Structure
26
+
27
+ - `src/` — Core library (types, config, redis, llm, audio, github, environment) and CLI
28
+ - `src/narrative/` — Knowledge graph and structural tension charts (from coaia-narrative)
29
+ - `src/pde/` — Prompt Decomposition Engine (from coaia-pde / mcp-pde)
30
+ - `src/planning/` — Action planning (from coaia-planning)
31
+ - `src/langfuse/` — Langfuse tracing integration
32
+ - `src/pipeline/` — Pipeline template engine
33
+ - `mcp/` — MCP server and tool definitions
34
+ - `tests/` — Test files using node:test
35
+
36
+ ## Type System
37
+
38
+ `src/types.ts` is the single source of truth for all types. It is the union of:
39
+ - Entity/Relation/KnowledgeGraph (from coaia-narrative)
40
+ - DecompositionResult/PDE types (from coaia-pde / mcp-pde)
41
+ - StructuralTensionPlan (from coaia-planning)
42
+ - Pipeline/Langfuse/Config types (from coaiapy)
43
+
44
+ ## Git
45
+
46
+ - This is a sub-project inside `jgwill/src`. It has its own `.git`.
47
+ - Always `cd /a/src/coaiajs` before git operations.
48
+ - Commit messages: conventional commits preferred (`feat:`, `fix:`, `chore:`).
49
+
50
+ ## Key Patterns
51
+
52
+ - **tash/fetch** — Redis SET/GET shorthand, from coaiapy convention.
53
+ - **Structural Tension Charts** — desired outcome + current reality + action steps. The core data model.
54
+ - **MMOT** — Managerial Moment of Truth: acknowledge → analyze → plan → recommit.
55
+ - **PDE** — Prompt Decomposition Engine: decompose complex prompts into actionable intent maps.
56
+ - **Four Directions** — North (vision), East (intention), South (emotion), West (introspection).
package/KINSHIP.md ADDED
@@ -0,0 +1,63 @@
1
+ # KINSHIP.md — coaiajs
2
+
3
+ ## Identity
4
+
5
+ **Name:** coaiajs
6
+ **Role:** TypeScript consolidation monorepo — CLI, MCP server, and library
7
+ **Status:** Genesis (v0.1.0)
8
+
9
+ ## Lineage
10
+
11
+ `coaiajs` is born from the convergence of four parent projects. It carries their patterns, types, and responsibilities forward into a unified TypeScript codebase.
12
+
13
+ ### Parent Projects
14
+
15
+ | Project | Relation | What was inherited |
16
+ |---|---|---|
17
+ | **coaiapy** (`/src/coaiapy/`) | Primary ancestor | Config management, Redis tash/fetch, LLM wrapper, audio synthesis, GitHub API, environment management, CLI patterns |
18
+ | **coaia-narrative** (`/src/coaia-narrative/`) | Structural parent | Entity/Relation/KnowledgeGraph types, JSONL storage, structural tension charts, narrative beats, MMOT evaluations |
19
+ | **coaia-pde** (`/src/coaia-pde/`) | Structural parent | DecompositionResult types, PDE session management, direction mapping |
20
+ | **coaia-planning** (`/src/coaia-planning/`) | Structural parent | StructuralTensionPlan, plan parsing, action step telescoping |
21
+
22
+ ### Type Lineage
23
+
24
+ The canonical type source is `src/types.ts`, which is the **union** of:
25
+ - `coaia-narrative/src/types.ts` → Entity, Relation, KnowledgeGraph, EntityMetadata, McpToolResult
26
+ - `mcp-pde/src/types.ts` (via `IAIP/lib/pde/types.ts`) → DecompositionResult, PrimaryIntent, SecondaryIntent, DirectionMap, ActionItem, AmbiguityFlag
27
+ - `coaia-planning/src/types.ts` → StructuralTensionPlan, StructuralElement
28
+ - `coaiapy` (Python → TS port) → CoaiaConfig, PipelineTemplate, ScoreConfig
29
+
30
+ ### Sibling Projects
31
+
32
+ | Project | Relationship |
33
+ |---|---|
34
+ | **mcp-pde** (`/src/mcp-pde/`) | PDE MCP server — coaiajs absorbs its types and will eventually absorb its MCP tools |
35
+ | **mcp-medicine-wheel** (`/src/mcp-medicine-wheel/`) | Four Directions ceremony MCP — remains separate, shares Redis |
36
+ | **coaia-visualizer** (`/src/coaia-visualizer/`) | Web UI — will consume coaiajs as a library |
37
+ | **IAIP** (`/src/IAIP/`) | Houses canonical PDE types in `lib/pde/types.ts` |
38
+
39
+ ## Accountabilities
40
+
41
+ 1. **Type unification** — `src/types.ts` is the single source of truth. Parent projects should eventually import from here.
42
+ 2. **Config parity** — `src/config.ts` must support every config path that `coaiapy` supports.
43
+ 3. **Redis parity** — `src/redis.ts` tash/fetch must behave identically to coaiapy's.
44
+ 4. **MCP consolidation** — `mcp/` will eventually host all CoAIA MCP tools in one server.
45
+ 5. **CLI consolidation** — `src/cli.ts` will eventually replace coaiapy's CLI.
46
+
47
+ ## Structural Tension
48
+
49
+ **Desired Outcome:** A single `npm install coaiajs` provides CLI, MCP server, and library for the entire CoAIA ecosystem.
50
+
51
+ **Current Reality:** Core types and config scaffolded. Sub-modules (narrative, pde, planning, langfuse, pipeline) are empty directories awaiting implementation.
52
+
53
+ **Action Steps:**
54
+ 1. ✅ Scaffold monorepo structure
55
+ 2. ✅ Implement shared types (union of all parents)
56
+ 3. ✅ Implement config, redis, environment, llm, audio, github
57
+ 4. ⬜ Implement narrative module (port from coaia-narrative)
58
+ 5. ⬜ Implement PDE module (port from mcp-pde)
59
+ 6. ⬜ Implement planning module (port from coaia-planning)
60
+ 7. ⬜ Implement MCP server with all tools
61
+ 8. ⬜ Implement CLI
62
+ 9. ⬜ Implement Langfuse integration
63
+ 10. ⬜ Implement pipeline template engine
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # coaiajs
2
+
3
+ **CoAIA unified TypeScript monorepo** — CLI, MCP server, and library consolidating `coaia-narrative`, `coaia-pde`, `coaia-planning`, and `coaiapy` patterns into a single package.
4
+
5
+ ## What is this?
6
+
7
+ `coaiajs` is the TypeScript consolidation of the CoAIA (Creative Orientation AI Architecture) ecosystem. It unifies four previously separate projects:
8
+
9
+ | Origin Project | What it did | Where it lives now |
10
+ |---|---|---|
11
+ | `coaia-narrative` | JSONL knowledge graph, structural tension charts, narrative beats | `src/narrative/` |
12
+ | `coaia-pde` | Prompt Decomposition Engine | `src/pde/` |
13
+ | `coaia-planning` | Action planning, structural tension chart management | `src/planning/` |
14
+ | `coaiapy` | Python CLI with Redis, LLM, audio, GitHub, config, environment | `src/` (core modules) |
15
+
16
+ The shared type system in `src/types.ts` is the union of all four projects.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Clone and install
22
+ cd coaiajs
23
+ npm install
24
+
25
+ # Build
26
+ npm run build
27
+ ```
28
+
29
+ ### Requirements
30
+
31
+ - Node.js >= 20.0.0
32
+ - TypeScript >= 5.7
33
+
34
+ ## Usage
35
+
36
+ ### CLI
37
+
38
+ ```bash
39
+ # Run the CLI
40
+ npx coaia <command>
41
+
42
+ # Or after global install
43
+ coaia <command>
44
+ ```
45
+
46
+ ### MCP Server
47
+
48
+ ```bash
49
+ # Start the MCP server (for Claude, Copilot, etc.)
50
+ npx coaiajs-mcp
51
+
52
+ # Or via npm script
53
+ npm run mcp
54
+ ```
55
+
56
+ ### Library
57
+
58
+ ```typescript
59
+ import { readConfig } from 'coaiajs/src/config.js';
60
+ import { tash, fetch } from 'coaiajs/src/redis.js';
61
+ import { llm } from 'coaiajs/src/llm.js';
62
+ import { createEnvironment } from 'coaiajs/src/environment.js';
63
+ import type { Entity, DecompositionResult, CoaiaConfig } from 'coaiajs/src/types.js';
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ Configuration is loaded with the following priority (highest wins):
69
+
70
+ 1. **Environment variables** — `REDIS_URL`, `OPENAI_API_KEY`, `LANGFUSE_PUBLIC_KEY`, etc.
71
+ 2. **`.env` file** — in current working directory
72
+ 3. **`coaia.json`** — searched in `./coaia.json`, `~/coaia.json`, `~/.coaia/config.json`
73
+ 4. **Defaults**
74
+
75
+ ### Environment Variables
76
+
77
+ | Variable | Description |
78
+ |---|---|
79
+ | `REDIS_URL` | Redis connection URL |
80
+ | `OPENAI_API_KEY` | OpenAI API key |
81
+ | `LANGFUSE_PUBLIC_KEY` | Langfuse public key |
82
+ | `LANGFUSE_SECRET_KEY` | Langfuse secret key |
83
+ | `AWS_ACCESS_KEY_ID` | AWS credentials for Polly |
84
+ | `GITHUB_TOKEN` | GitHub API token |
85
+
86
+ ### coaia.json
87
+
88
+ ```json
89
+ {
90
+ "redis": { "url": "redis://localhost:6379" },
91
+ "openai": { "apiKey": "sk-...", "model": "gpt-4o" },
92
+ "langfuse": { "publicKey": "pk-...", "secretKey": "sk-..." },
93
+ "github": { "token": "ghp_..." }
94
+ }
95
+ ```
96
+
97
+ ## Project Structure
98
+
99
+ ```
100
+ coaiajs/
101
+ ├── src/ # Core library and CLI
102
+ │ ├── types.ts # Shared type definitions (union of all projects)
103
+ │ ├── config.ts # Configuration management
104
+ │ ├── redis.ts # Redis tash/fetch operations
105
+ │ ├── environment.ts # Environment variable management
106
+ │ ├── llm.ts # OpenAI LLM wrapper
107
+ │ ├── audio.ts # AWS Polly text-to-speech
108
+ │ ├── github.ts # GitHub API wrapper
109
+ │ ├── cli.ts # CLI entry point
110
+ │ ├── langfuse/ # Langfuse observability integration
111
+ │ ├── narrative/ # Knowledge graph, STC, narrative beats
112
+ │ ├── pde/ # Prompt Decomposition Engine
113
+ │ ├── planning/ # Action planning and STC management
114
+ │ └── pipeline/ # Pipeline template engine
115
+ ├── mcp/ # MCP server
116
+ │ ├── server.ts # MCP server entry point
117
+ │ └── tools/ # MCP tool definitions
118
+ ├── tests/ # Test files
119
+ ├── articles/ # Documentation articles
120
+ └── rispecs/ # RISE specification files
121
+ ```
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ # Watch mode
127
+ npm run dev
128
+
129
+ # Type checking without emit
130
+ npm run lint
131
+
132
+ # Run tests
133
+ npm test
134
+ ```
135
+
136
+ ## Architecture
137
+
138
+ The architecture follows the **Structural Tension** pattern from Robert Fritz's creative process framework:
139
+
140
+ - **Desired Outcome** — what you want to create
141
+ - **Current Reality** — honest assessment of where you are
142
+ - **Action Steps** — telescoped sub-charts bridging the gap
143
+
144
+ Each module operates independently but shares the unified type system (`src/types.ts`), enabling the MCP server to expose all capabilities through a single protocol.
145
+
146
+ ## License
147
+
148
+ MIT
@@ -0,0 +1,177 @@
1
+ # Creative Orientation vs. Problem-Solving in AI Agent Design
2
+
3
+ > Academic brief for the CoAiA.js project — Why Robert Fritz's distinction between creative orientation (advancing toward desired outcomes) and problem-solving orientation (retreating from problems) is foundational for AI agent architecture.
4
+
5
+ ## Abstract
6
+
7
+ AI agent architectures predominantly operate from what Robert Fritz terms "problem-solving orientation"—systems designed to detect undesirable states and take corrective action to eliminate them. This paper argues that problem-solving orientation produces structurally oscillatory agents: as problems diminish, the energy driving correction also diminishes, leading to cyclical regression. We present Fritz's alternative—creative orientation, where agents are structured to advance toward clearly articulated desired outcomes—and analyze its implications for AI agent design. Creative orientation produces advancing rather than oscillating dynamics by maintaining structural tension between a constant vision and an evolving reality. We examine how this distinction manifests in agent goal management, reward design, evaluation criteria, and long-term behavioral patterns. The analysis provides the theoretical foundation for CoAiA.js's creative-orientation-first architecture.
8
+
9
+ ## Introduction
10
+
11
+ Consider two agents given the same objective—"improve code quality in this repository."
12
+
13
+ **Agent A (Problem-Solving)** scans for problems: lint errors, security vulnerabilities, code smells, missing tests. It fixes each issue found. As the issue count drops from 200 to 20, its rate of productive activity slows—there are fewer problems to find. When a team member introduces new issues, Agent A reactivates. It oscillates between "fixing problems" and "waiting for problems."
14
+
15
+ **Agent B (Creative Orientation)** begins by articulating a desired outcome: "A codebase with consistent architecture patterns, comprehensive test coverage, clear documentation, and proactive error handling." It then honestly assesses current reality. The structural tension between vision and reality drives sustained action—not just fixing what's wrong, but creating what's desired. When the issue count drops from 200 to 20, Agent B's energy does not diminish: the vision includes positive qualities (clarity, consistency, comprehensiveness) that have not yet been fully realized [1].
16
+
17
+ This distinction—between agents that react to problems and agents that create toward visions—is the central contribution of Robert Fritz's work to AI agent design.
18
+
19
+ ## Background
20
+
21
+ ### Fritz's Structural Dynamics
22
+
23
+ Robert Fritz, in *The Path of Least Resistance* (1989) and subsequent works, identified two fundamental orientations toward action:
24
+
25
+ **Problem-Solving Orientation (Reactive-Responsive):**
26
+ - Motivation comes from what you don't want
27
+ - Energy is generated by the presence of a problem
28
+ - As the problem diminishes, energy for action also diminishes
29
+ - This creates oscillating structures: action → problem reduced → motivation reduced → problem returns → action resumes
30
+ - The system perpetually returns to a baseline state
31
+
32
+ **Creative Orientation (Generative):**
33
+ - Motivation comes from what you want to create
34
+ - Energy is generated by the vision of a desired outcome
35
+ - As current reality advances toward the vision, new aspects of the vision become relevant
36
+ - This creates advancing structures: action → reality improves → new creative possibilities emerge → further action
37
+ - The system progressively builds upon prior achievements [2][3]
38
+
39
+ Fritz demonstrated this pattern across domains: personal development, organizational leadership, artistic creation, and strategic planning. The key insight is that these are **structural** properties—not motivational or psychological ones. The underlying structure of the goal system determines whether it oscillates or advances, regardless of the effort or intention of the agents operating within it.
40
+
41
+ ### Problem-Solving in Traditional AI
42
+
43
+ The dominant paradigms in AI agent design are structurally problem-solving:
44
+
45
+ **Reinforcement Learning:** An agent receives negative reward (penalty) for undesirable states and learns to avoid them. The reward signal is fundamentally reactive—it measures distance from problems, not proximity to creative vision. Reward shaping can approximate creative orientation, but the underlying structure remains problem-reactive.
46
+
47
+ **Loss Minimization:** Neural networks are trained to minimize a loss function—the gap between predicted and target outputs. This is structurally identical to problem-solving: the "problem" (high loss) drives action, and as loss approaches zero, gradient magnitude diminishes.
48
+
49
+ **Error Correction:** Agent architectures that detect errors and trigger correction routines (retry logic, fallback strategies, error handlers) are purely reactive—they activate only when problems occur.
50
+
51
+ **Goal Satisfaction:** STRIPS-style planning treats goals as conditions to satisfy. Once satisfied, no further action occurs—there is no mechanism for ongoing creative advancement [4].
52
+
53
+ ## Analysis
54
+
55
+ ### Structural Properties of Oscillation
56
+
57
+ Oscillation in problem-solving systems follows a predictable pattern:
58
+
59
+ ```
60
+ Problem Detected → High Energy → Action → Problem Reduced →
61
+ Low Energy → Inaction → Problem Returns → High Energy → Action...
62
+ ```
63
+
64
+ In AI agent terms:
65
+ 1. Agent detects high error rate in generated code
66
+ 2. Agent focuses energy on fixing errors
67
+ 3. Error rate drops to acceptable level
68
+ 4. Agent shifts attention away (to other tasks or enters idle state)
69
+ 5. Without ongoing attention, new errors accumulate or latent issues surface
70
+ 6. Agent re-detects high error rate
71
+ 7. Cycle repeats
72
+
73
+ The oscillation is not a failure of the agent's capabilities—it is a structural property of the problem-solving architecture. The more capable the agent, the faster it oscillates, but oscillation remains.
74
+
75
+ ### Structural Properties of Advancement
76
+
77
+ Creative orientation produces a different dynamic:
78
+
79
+ ```
80
+ Vision Articulated → Structural Tension → Action → Reality Advances →
81
+ New Aspects of Vision Become Relevant → Renewed Tension → Further Action...
82
+ ```
83
+
84
+ In AI agent terms:
85
+ 1. Agent articulates desired outcome: "A robust, well-documented API with comprehensive error handling, 95% test coverage, and clear usage examples"
86
+ 2. Agent assesses current reality: "API has 12 endpoints, 4 undocumented, 62% test coverage, no error handling pattern"
87
+ 3. Structural tension drives action toward the vision
88
+ 4. After improving documentation and adding tests: current reality is now "12 endpoints, all documented, 78% test coverage, basic error handling"
89
+ 5. The vision hasn't changed—new aspects (usage examples, comprehensive error handling, 95% coverage) maintain tension
90
+ 6. Agent continues advancing rather than oscillating
91
+
92
+ ### Design Implications for AI Agents
93
+
94
+ #### Goal Representation
95
+
96
+ Problem-solving agents encode goals as conditions to eliminate:
97
+ ```json
98
+ {"goal": "reduce_lint_errors", "target": 0, "current": 47}
99
+ ```
100
+
101
+ Creative-orientation agents encode goals as outcomes to create:
102
+ ```json
103
+ {
104
+ "desiredOutcome": "A codebase with consistent naming conventions, modular architecture, and clear documentation at every public interface",
105
+ "currentReality": "Mixed naming conventions across 3 historical styles. 40% of modules have circular dependencies. 12 of 45 public functions undocumented."
106
+ }
107
+ ```
108
+
109
+ The creative-orientation representation is richer, more nuanced, and maintains tension even when any single metric improves.
110
+
111
+ #### Evaluation Criteria
112
+
113
+ Problem-solving evaluation asks: "Is the problem gone?"
114
+ Creative-orientation evaluation asks: "How does the current state compare to the desired creation?"
115
+
116
+ The MMOT (Managerial Moment of Truth) cycle is inherently creative-orientation: it evaluates against Elements of Performance derived from the desired outcome, not against a problem checklist.
117
+
118
+ #### Energy Management
119
+
120
+ Problem-solving agents need external triggers (error events, threshold violations) to activate. Creative-orientation agents generate their own energy through structural tension—the gap between vision and reality is an intrinsic motivator that doesn't require external events.
121
+
122
+ This has practical implications for agent scheduling: problem-solving agents need polling loops or event subscriptions; creative-orientation agents can self-schedule based on tension assessment.
123
+
124
+ #### Long-Term Behavioral Patterns
125
+
126
+ Over extended operation:
127
+ - **Problem-solving agents** produce a sawtooth pattern: rapid improvement followed by plateau and regression
128
+ - **Creative-orientation agents** produce a staircase pattern: sustained improvement with each step building on the previous one
129
+
130
+ This is because creative-orientation agents "lock in" progress by updating their current reality assessment. Once a capability is created, it becomes part of the new baseline—the agent doesn't need to re-create it, and can build further upon it.
131
+
132
+ ### The Hybrid Case: Creative Orientation with Problem Awareness
133
+
134
+ Fritz does not argue that problem-solving is always wrong—sometimes urgent problems require immediate reactive response. The key insight is that problem-solving should be *subordinate to* creative orientation, not the primary driver:
135
+
136
+ 1. **Primary:** Maintain structural tension toward the desired outcome
137
+ 2. **Secondary:** Address problems that arise as obstacles to advancement
138
+ 3. **Never:** Let problem-solving become the primary orientation
139
+
140
+ In agent architecture terms: the structural tension chart defines the creative frame; error handlers and correction routines address specific problems within that frame; but the frame itself is creative, not reactive [5].
141
+
142
+ ### Fritz's Insight Applied to Reward Engineering
143
+
144
+ In reinforcement learning, reward design is notoriously difficult—reward hacking, sparse rewards, and reward misspecification are persistent challenges. Fritz's creative/problem-solving distinction suggests a fundamental issue: most reward functions are problem-solving in structure (penalizing bad states) rather than creative (describing desired creations).
145
+
146
+ A creative-orientation reward function would:
147
+ - Describe the desired state in positive, compositional terms
148
+ - Maintain its value even as the agent approaches the goal (because the description is rich enough to reveal new aspects)
149
+ - Not diminish as specific problems are resolved
150
+ - Be evaluated holistically (how does reality compare to the full vision?) rather than componentally (which problems remain?)
151
+
152
+ ## Implications for CoAiA.js
153
+
154
+ Creative orientation is the architectural foundation of CoAiA.js:
155
+
156
+ 1. **All agent sessions begin with vision articulation.** Before any action, agents define what they want to create—not what problems they want to solve.
157
+ 2. **Structural tension charts, not task lists.** The primary data structure is the STC (desired outcome + current reality), not a problem backlog.
158
+ 3. **MMOT evaluates against creative criteria.** Self-evaluation measures advancement toward the desired outcome, not merely problem elimination.
159
+ 4. **Reality assessment is continuous and honest.** Agents regularly update their current reality assessment, maintaining the tension that drives creative advancement.
160
+ 5. **Problem-solving is subordinate.** Error handlers and correction routines operate within the creative frame, addressing obstacles to advancement without becoming the primary orientation.
161
+
162
+ ## Conclusion
163
+
164
+ The distinction between creative orientation and problem-solving is not philosophical decoration—it is a structural property with measurable behavioral consequences. Agents designed around problem-solving oscillate; agents designed around creative orientation advance. CoAiA.js implements this insight at the architectural level, producing agents that create toward visions rather than merely react to problems. The result is sustained forward momentum, resistance to oscillation, and the capacity for genuine creative advancement in autonomous AI systems.
165
+
166
+ ## References
167
+
168
+ 1. Fritz, R. (1989). *The Path of Least Resistance: Learning to Become the Creative Force in Your Own Life*. Fawcett Columbine.
169
+ 2. Fritz, R. "The Creative Process." Robert Fritz Inc. https://www.robertfritz.com/wp/the-creative-process/
170
+ 3. Fritz, R. "Thinking in Structures." Robert Fritz Inc. https://www.robertfritz.com/wp/thinking-in-structures/
171
+ 4. Systems Field Book. "Creative Orientation." https://www.systemsfieldbook.org/creative-orientation
172
+ 5. jgwill/llms-txt. "Creative Orientation Documentation." https://github.com/jgwill/llms-txt/blob/main/docs/creative-orientation.md
173
+ 6. Fritz, R. "Writings." Robert Fritz Inc. https://www.robertfritz.com/wp/writings/
174
+ 7. Senge, P. (1990). *The Fifth Discipline: The Art & Practice of the Learning Organization*. Doubleday.
175
+ 8. Sutton, R. S., & Barto, A. G. (2018). *Reinforcement Learning: An Introduction*. 2nd ed. MIT Press.
176
+ 9. Think-2-Thrive. (2024). "Leading with Creative Tension." https://think-2-thrive.com/2024/12/02/blog-55-leading-with-creative-tension/
177
+ 10. Springer. (2024). "A TRIZ and Socratic AI-Based Problem-Solving Framework." https://link.springer.com/chapter/10.1007/978-3-032-08847-5_20
@@ -0,0 +1,142 @@
1
+ # JSONL as Lightweight Knowledge Graph Storage for AI Agent Memory
2
+
3
+ > Academic brief for the CoAiA.js project — Append-only line-delimited JSON as a knowledge graph substrate for agent state, compared with Neo4j, SQLite, and vector databases.
4
+
5
+ ## Abstract
6
+
7
+ AI agent systems require persistent memory that balances expressiveness, queryability, and operational simplicity. This paper evaluates JSON Lines (JSONL)—an append-only, line-delimited JSON format—as a lightweight knowledge graph storage mechanism for agent memory. We compare JSONL entity-relation storage against established alternatives: Neo4j (property graphs), SQLite (relational), and vector databases (embedding-based retrieval). Our analysis demonstrates that JSONL offers unique advantages for agent memory workloads: zero-dependency deployment, natural append-only semantics aligned with temporal agent state, human-readable audit trails, and sufficient query performance for single-agent session contexts. We formalize the JSONL entity-relation model used in CoAiA.js, analyze its trade-offs against richer graph storage, and identify the operational sweet spot where JSONL-backed knowledge graphs outperform heavier alternatives.
8
+
9
+ ## Introduction
10
+
11
+ The rise of autonomous AI agents—systems that maintain state across interactions, learn from observations, and pursue multi-step goals—has created an urgent need for agent memory architectures that are both expressive and operationally lightweight. An agent's memory must encode entities (concepts, observations, decisions), relations between entities (causal links, dependencies, temporal orderings), and evolving state (current reality assessments, progress markers) [1].
12
+
13
+ The knowledge graph community has traditionally addressed such requirements through property graph databases (Neo4j, Memgraph), RDF triple stores (GraphDB, Fuseki), or more recently, vector databases (Pinecone, Weaviate, Chroma). Each brings significant capabilities but also operational overhead: server processes, schema management, connection pooling, and deployment complexity [2][3].
14
+
15
+ For many agent memory workloads—particularly single-agent sessions, development environments, and edge deployments—this overhead is disproportionate to the actual storage and query requirements. This paper argues that JSONL, combined with in-memory indexing, provides a knowledge graph storage substrate that is adequate for the majority of agent memory use cases while dramatically reducing operational complexity.
16
+
17
+ ## Background
18
+
19
+ ### JSON Lines (JSONL) Format
20
+
21
+ JSONL (also called newline-delimited JSON or NDJSON) is a text format where each line is a valid JSON object, separated by newline characters. The format has several properties relevant to knowledge graph storage:
22
+
23
+ 1. **Append-only by nature.** New records are written by appending lines; existing records are never modified in place.
24
+ 2. **Streamable.** Files can be processed line-by-line without loading the entire dataset into memory.
25
+ 3. **Human-readable.** Records are inspectable with standard text tools (cat, grep, head, tail).
26
+ 4. **Schema-flexible.** Each line can have a different structure, enabling heterogeneous entity types in a single file.
27
+ 5. **Zero-dependency.** No server process, no driver library, no connection management [4].
28
+
29
+ ### Knowledge Graph Storage Models
30
+
31
+ The landscape of knowledge graph storage can be categorized into four primary models:
32
+
33
+ - **Property Graphs (Neo4j, Memgraph, KuzuDB):** Nodes and edges with key-value properties; Cypher query language; optimized for traversals and path queries.
34
+ - **RDF Triple Stores (GraphDB, Fuseki, Blazegraph):** Subject-predicate-object triples with URI-based identification; SPARQL query language; strong semantic reasoning.
35
+ - **Relational (SQLite, PostgreSQL):** Tables with foreign key relationships; SQL query language; mature tooling but impedance mismatch with graph structures.
36
+ - **Vector Databases (Pinecone, Weaviate, Chroma):** Embedding-based storage optimized for similarity search; excellent for semantic retrieval but lacking explicit relational structure [5][6].
37
+
38
+ ## Analysis
39
+
40
+ ### The JSONL Entity-Relation Model
41
+
42
+ In the CoAiA.js implementation, knowledge graphs are stored as typed JSONL records with the following schema:
43
+
44
+ ```jsonl
45
+ {"type":"entity","name":"mcp_server","entityType":"component","observations":["Handles tool dispatch","Uses stdio transport"]}
46
+ {"type":"entity","name":"langfuse_integration","entityType":"service","observations":["Traces LLM generations","MIT licensed"]}
47
+ {"type":"relation","from":"mcp_server","to":"langfuse_integration","relationType":"depends_on"}
48
+ {"type":"observation","entityName":"mcp_server","content":"Added error handling for malformed JSON-RPC requests","timestamp":"2026-03-10T14:00:00Z"}
49
+ ```
50
+
51
+ This model encodes:
52
+ - **Entities** with typed classifications and evolving observation lists
53
+ - **Relations** between entities with typed edges
54
+ - **Temporal observations** that append new knowledge without modifying existing records
55
+
56
+ The append-only semantics are not a limitation but a feature: they naturally encode the temporal evolution of agent knowledge, enabling queries like "what did the agent know at time T?" without requiring event sourcing or temporal tables.
57
+
58
+ ### Comparative Analysis
59
+
60
+ #### JSONL vs. Neo4j
61
+
62
+ Neo4j provides mature graph traversal capabilities, Cypher query language, and ACID transactions. For agent memory workloads, the key trade-offs are:
63
+
64
+ | Dimension | JSONL | Neo4j |
65
+ |-----------|-------|-------|
66
+ | Deployment | Zero-config file | JVM server process |
67
+ | Query Language | In-memory JavaScript/grep | Cypher |
68
+ | Path Queries | O(n) scan or in-memory index | Optimized native |
69
+ | Write Pattern | Append line | Transaction commit |
70
+ | Concurrent Access | Single-writer safe | Multi-writer ACID |
71
+ | Portability | Copy file | Export/import pipeline |
72
+ | Cost | Zero | Community/Enterprise licensing |
73
+
74
+ For single-agent sessions with knowledge graphs under 100,000 entities—which covers the vast majority of agent session workloads—JSONL with in-memory indexing provides sub-millisecond query times with zero operational overhead. Neo4j becomes necessary only when path query complexity or multi-user concurrency demands it.
75
+
76
+ #### JSONL vs. SQLite
77
+
78
+ SQLite offers a compelling middle ground: embedded, zero-config, yet supporting SQL queries and ACID transactions. However, SQLite's relational model creates impedance mismatch with graph structures:
79
+
80
+ - Graph traversals require recursive CTEs, which are syntactically complex and performance-limited.
81
+ - Schema changes (new entity types, new relation types) require ALTER TABLE operations.
82
+ - The append-only temporal model must be explicitly implemented rather than arising naturally from the storage format.
83
+
84
+ JSONL's schema flexibility and natural append semantics make it better suited to the evolving, heterogeneous nature of agent knowledge.
85
+
86
+ #### JSONL vs. Vector Databases
87
+
88
+ Vector databases excel at semantic similarity search—finding entities "similar to" a query embedding. However, they fundamentally lack explicit relational structure:
89
+
90
+ - Relations between entities must be encoded implicitly through embedding proximity or metadata filters.
91
+ - Temporal ordering is not native; timestamps must be stored as metadata and filtered externally.
92
+ - The retrieval model (top-k nearest neighbors) does not naturally support the "desired outcome vs. current reality" structural tension queries that drive agent behavior.
93
+
94
+ JSONL and vector databases are complementary rather than competing: JSONL provides the relational graph structure while vector embeddings (stored as entity properties) enable semantic retrieval within that structure.
95
+
96
+ ### Performance Characteristics
97
+
98
+ For typical agent memory workloads (1,000–50,000 records per session), JSONL with in-memory indexing provides:
99
+
100
+ - **Write latency:** <1ms (file append)
101
+ - **Entity lookup:** <1ms (hash map)
102
+ - **Relation traversal:** <5ms (adjacency list)
103
+ - **Full scan:** <50ms for 50K records
104
+ - **File size:** ~5MB for 50K records (highly compressible)
105
+
106
+ These characteristics are more than adequate for interactive agent sessions where the bottleneck is LLM inference (typically 1-30 seconds per generation), not memory access.
107
+
108
+ ### Limitations and Mitigations
109
+
110
+ JSONL-backed knowledge graphs have real limitations:
111
+
112
+ 1. **No native query language.** Queries must be implemented in application code or via streaming filters. *Mitigation:* CoAiA.js provides a query API that loads JSONL into an in-memory graph structure on startup.
113
+ 2. **No concurrent write safety.** Multiple writers can corrupt the file. *Mitigation:* Agent sessions are single-writer by design; file locking can be added for multi-agent scenarios.
114
+ 3. **Linear scan for complex queries.** Path queries and graph algorithms require full load into memory. *Mitigation:* Agent session graphs are small enough for full in-memory operation.
115
+ 4. **No built-in indexing.** Unlike databases, JSONL files have no persistent index structures. *Mitigation:* In-memory indexes are rebuilt on load, which takes <100ms for typical session sizes.
116
+
117
+ ## Implications for CoAiA.js
118
+
119
+ CoAiA.js adopts JSONL as its primary knowledge graph storage format based on the analysis above. The implications are:
120
+
121
+ 1. **Zero-dependency memory.** Agent sessions can persist state without any external service, enabling deployment in constrained environments (edge, CI/CD, development workstations).
122
+ 2. **Full audit trail.** Every observation, entity, and relation ever created is preserved in temporal order, enabling complete reconstruction of agent reasoning.
123
+ 3. **Git-friendly storage.** JSONL files produce clean diffs, enabling version control of agent memory—a critical capability for reproducible agent behavior.
124
+ 4. **Composable with richer stores.** When workloads demand it, JSONL can be batch-imported into Neo4j or vector databases for advanced analysis without changing the write-time format.
125
+ 5. **Human-debuggable.** Developers can inspect agent memory with `cat`, `grep`, and `jq`—no specialized tooling required.
126
+
127
+ ## Conclusion
128
+
129
+ JSONL-backed knowledge graphs represent an underappreciated sweet spot in the agent memory design space. For single-agent session workloads—the dominant pattern in current AI agent architectures—JSONL provides the expressiveness of a knowledge graph with the operational simplicity of a log file. By embracing append-only semantics as a feature rather than a limitation, and by leveraging in-memory indexing for query performance, CoAiA.js demonstrates that lightweight storage can be adequate without being simplistic.
130
+
131
+ ## References
132
+
133
+ 1. Graphlit Blog. (2024). "Survey of AI Agent Memory Frameworks." https://www.graphlit.com/blog/survey-of-ai-agent-memory-frameworks
134
+ 2. Neo4j Labs. (2025). "Agent Memory: A Graph-Native Memory System for AI." https://github.com/neo4j-labs/agent-memory
135
+ 3. Vela Partners. (2025). "KuzuDB for Production AI Agents." https://www.vela.partners/blog/kuzudb-ai-agent-memory-graph-database
136
+ 4. NDJSON Specification. https://github.com/ndjson/ndjson-spec
137
+ 5. Enterprise Knowledge. (2024). "Cutting Through the Noise: An Introduction to RDF & LPG Graphs." https://enterprise-knowledge.com/cutting-through-the-noise-an-introduction-to-rdf-lpg-graphs/
138
+ 6. Neo4j. (2024). "RDF Triple Stores vs. Property Graphs." https://neo4j.com/blog/knowledge-graph/rdf-vs-property-graphs-knowledge-graphs/
139
+ 7. FuturesSmart AI. (2024). "Building AI Knowledge Graph Using Graphiti and Neo4j." https://blog.futuresmart.ai/building-ai-knowledge-graph-using-graphiti-and-neo4j
140
+ 8. Memento MCP. (2024). "A Knowledge Graph Memory System for LLMs." https://github.com/gannonh/memento-mcp
141
+ 9. Ontotext. (2024). "Choosing A Graph Data Model to Best Serve Your Use Case." https://www.ontotext.com/blog/choosing-a-graph-data-model-to-best-serve-your-use-case/
142
+ 10. SAP Community. (2025). "Choosing Between Knowledge Graphs and Property Graphs in SAP HANA Cloud." https://community.sap.com/t5/technology-blog-posts-by-sap/choosing-between-knowledge-graphs-and-property-graphs-in-sap-hana-cloud-and/ba-p/14074575