coaiajs 0.1.2 → 0.2.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 (169) hide show
  1. package/.claude/settings.local.json +16 -0
  2. package/README.md +2 -0
  3. package/articles/academic/NOTES.md +1 -0
  4. package/articles/academic/README.md +1 -0
  5. package/articles/academic/creative-orientation-vs-problem-solving.md +177 -0
  6. package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +142 -0
  7. package/articles/academic/langfuse-observability-llm-pipelines.md +144 -0
  8. package/articles/academic/medicine-wheel-software-architecture.md +163 -0
  9. package/articles/academic/mmot-autonomous-agents.md +156 -0
  10. package/articles/academic/model-context-protocol-interagent.md +161 -0
  11. package/articles/academic/pde-prompt-decomposition.md +186 -0
  12. package/articles/academic/structural-tension-in-ai-agents.md +134 -0
  13. package/articles/reviews/mcp-protocol-design-review.md +170 -0
  14. package/articles/reviews/observability-ai-systems-review.md +176 -0
  15. package/articles/reviews/prompt-engineering-decomposition-review.md +184 -0
  16. package/articles/surveys/agent-orchestration-survey.md +186 -0
  17. package/articles/surveys/knowledge-graph-storage-survey.md +204 -0
  18. package/articles/surveys/structural-tension-methodology-survey.md +154 -0
  19. package/articles/technical/aws-sdk-v3-polly.md +270 -0
  20. package/articles/technical/commander-cli-framework.md +262 -0
  21. package/articles/technical/dotenv-config-patterns.md +360 -0
  22. package/articles/technical/ioredis-vs-redis.md +142 -0
  23. package/articles/technical/langfuse-js-sdk-vs-rest.md +191 -0
  24. package/articles/technical/mcp-sdk-typescript.md +291 -0
  25. package/articles/technical/octokit-github-api.md +293 -0
  26. package/articles/technical/openai-sdk-modern.md +231 -0
  27. package/articles/technical/yaml-parsing-node.md +266 -0
  28. package/articles/technical/zod-runtime-validation.md +212 -0
  29. package/dist/mcp/server.js +5 -3
  30. package/dist/mcp/tools/coaiapy-tools.js +1 -0
  31. package/dist/src/cli.js +41 -5
  32. package/dist/src/langfuse/index.d.ts +1 -1
  33. package/dist/src/langfuse/index.js +1 -1
  34. package/dist/src/langfuse/traces.d.ts +1 -0
  35. package/dist/src/langfuse/traces.js +24 -0
  36. package/dist/src/redis.d.ts +1 -1
  37. package/dist/src/redis.js +2 -2
  38. package/mcp/config.ts +225 -0
  39. package/mcp/prompts.ts +131 -0
  40. package/mcp/resources.ts +84 -0
  41. package/mcp/server.ts +518 -0
  42. package/mcp/tools/coaiapy-tools.ts +366 -0
  43. package/mcp/tools/index.ts +4 -0
  44. package/package.json +2 -67
  45. package/src/audio.ts +76 -0
  46. package/src/cli-helpers.ts +86 -0
  47. package/src/cli.ts +1260 -0
  48. package/src/config.ts +207 -0
  49. package/src/environment.ts +171 -0
  50. package/src/github.ts +143 -0
  51. package/src/index.ts +82 -0
  52. package/src/langfuse/client.ts +105 -0
  53. package/src/langfuse/comments.ts +52 -0
  54. package/src/langfuse/datasets.ts +178 -0
  55. package/src/langfuse/index.ts +33 -0
  56. package/src/langfuse/media.ts +193 -0
  57. package/src/langfuse/observations.ts +131 -0
  58. package/src/langfuse/prompts.ts +157 -0
  59. package/src/langfuse/scores.ts +456 -0
  60. package/src/langfuse/traces.ts +302 -0
  61. package/src/llm.ts +106 -0
  62. package/src/narrative/graph-manager.ts +1358 -0
  63. package/src/narrative/index.ts +188 -0
  64. package/src/narrative/markdown-export.ts +535 -0
  65. package/src/narrative/tool-definitions.ts +635 -0
  66. package/src/narrative/tool-handlers.ts +528 -0
  67. package/src/narrative/types.ts +9 -0
  68. package/src/narrative/validation.ts +179 -0
  69. package/src/pde/index.ts +34 -0
  70. package/src/pde/mcp-handlers.ts +359 -0
  71. package/src/pde/mcp-tools.ts +201 -0
  72. package/src/pde/session-manager.ts +248 -0
  73. package/src/pde/stc-mapper.ts +298 -0
  74. package/src/pipeline/index.ts +7 -0
  75. package/src/pipeline/template-engine.ts +398 -0
  76. package/src/planning/index.ts +32 -0
  77. package/src/planning/mcp-handlers.ts +369 -0
  78. package/src/planning/mcp-tools.ts +155 -0
  79. package/src/planning/plan-parser.ts +587 -0
  80. package/src/redis.ts +111 -0
  81. package/src/types.ts +281 -0
  82. package/test/config.test.mjs +93 -0
  83. package/tsconfig.json +26 -0
  84. package/dist/mcp/config.d.ts.map +0 -1
  85. package/dist/mcp/config.js.map +0 -1
  86. package/dist/mcp/prompts.d.ts.map +0 -1
  87. package/dist/mcp/prompts.js.map +0 -1
  88. package/dist/mcp/resources.d.ts.map +0 -1
  89. package/dist/mcp/resources.js.map +0 -1
  90. package/dist/mcp/server.d.ts.map +0 -1
  91. package/dist/mcp/server.js.map +0 -1
  92. package/dist/mcp/tools/coaiapy-tools.d.ts.map +0 -1
  93. package/dist/mcp/tools/coaiapy-tools.js.map +0 -1
  94. package/dist/mcp/tools/index.d.ts.map +0 -1
  95. package/dist/mcp/tools/index.js.map +0 -1
  96. package/dist/src/audio.d.ts.map +0 -1
  97. package/dist/src/audio.js.map +0 -1
  98. package/dist/src/cli-helpers.d.ts.map +0 -1
  99. package/dist/src/cli-helpers.js.map +0 -1
  100. package/dist/src/cli.d.ts.map +0 -1
  101. package/dist/src/cli.js.map +0 -1
  102. package/dist/src/config.d.ts.map +0 -1
  103. package/dist/src/config.js.map +0 -1
  104. package/dist/src/environment.d.ts.map +0 -1
  105. package/dist/src/environment.js.map +0 -1
  106. package/dist/src/github.d.ts.map +0 -1
  107. package/dist/src/github.js.map +0 -1
  108. package/dist/src/index.d.ts.map +0 -1
  109. package/dist/src/index.js.map +0 -1
  110. package/dist/src/langfuse/client.d.ts.map +0 -1
  111. package/dist/src/langfuse/client.js.map +0 -1
  112. package/dist/src/langfuse/comments.d.ts.map +0 -1
  113. package/dist/src/langfuse/comments.js.map +0 -1
  114. package/dist/src/langfuse/datasets.d.ts.map +0 -1
  115. package/dist/src/langfuse/datasets.js.map +0 -1
  116. package/dist/src/langfuse/index.d.ts.map +0 -1
  117. package/dist/src/langfuse/index.js.map +0 -1
  118. package/dist/src/langfuse/media.d.ts.map +0 -1
  119. package/dist/src/langfuse/media.js.map +0 -1
  120. package/dist/src/langfuse/observations.d.ts.map +0 -1
  121. package/dist/src/langfuse/observations.js.map +0 -1
  122. package/dist/src/langfuse/prompts.d.ts.map +0 -1
  123. package/dist/src/langfuse/prompts.js.map +0 -1
  124. package/dist/src/langfuse/scores.d.ts.map +0 -1
  125. package/dist/src/langfuse/scores.js.map +0 -1
  126. package/dist/src/langfuse/traces.d.ts.map +0 -1
  127. package/dist/src/langfuse/traces.js.map +0 -1
  128. package/dist/src/llm.d.ts.map +0 -1
  129. package/dist/src/llm.js.map +0 -1
  130. package/dist/src/narrative/graph-manager.d.ts.map +0 -1
  131. package/dist/src/narrative/graph-manager.js.map +0 -1
  132. package/dist/src/narrative/index.d.ts.map +0 -1
  133. package/dist/src/narrative/index.js.map +0 -1
  134. package/dist/src/narrative/markdown-export.d.ts.map +0 -1
  135. package/dist/src/narrative/markdown-export.js.map +0 -1
  136. package/dist/src/narrative/tool-definitions.d.ts.map +0 -1
  137. package/dist/src/narrative/tool-definitions.js.map +0 -1
  138. package/dist/src/narrative/tool-handlers.d.ts.map +0 -1
  139. package/dist/src/narrative/tool-handlers.js.map +0 -1
  140. package/dist/src/narrative/types.d.ts.map +0 -1
  141. package/dist/src/narrative/types.js.map +0 -1
  142. package/dist/src/narrative/validation.d.ts.map +0 -1
  143. package/dist/src/narrative/validation.js.map +0 -1
  144. package/dist/src/pde/index.d.ts.map +0 -1
  145. package/dist/src/pde/index.js.map +0 -1
  146. package/dist/src/pde/mcp-handlers.d.ts.map +0 -1
  147. package/dist/src/pde/mcp-handlers.js.map +0 -1
  148. package/dist/src/pde/mcp-tools.d.ts.map +0 -1
  149. package/dist/src/pde/mcp-tools.js.map +0 -1
  150. package/dist/src/pde/session-manager.d.ts.map +0 -1
  151. package/dist/src/pde/session-manager.js.map +0 -1
  152. package/dist/src/pde/stc-mapper.d.ts.map +0 -1
  153. package/dist/src/pde/stc-mapper.js.map +0 -1
  154. package/dist/src/pipeline/index.d.ts.map +0 -1
  155. package/dist/src/pipeline/index.js.map +0 -1
  156. package/dist/src/pipeline/template-engine.d.ts.map +0 -1
  157. package/dist/src/pipeline/template-engine.js.map +0 -1
  158. package/dist/src/planning/index.d.ts.map +0 -1
  159. package/dist/src/planning/index.js.map +0 -1
  160. package/dist/src/planning/mcp-handlers.d.ts.map +0 -1
  161. package/dist/src/planning/mcp-handlers.js.map +0 -1
  162. package/dist/src/planning/mcp-tools.d.ts.map +0 -1
  163. package/dist/src/planning/mcp-tools.js.map +0 -1
  164. package/dist/src/planning/plan-parser.d.ts.map +0 -1
  165. package/dist/src/planning/plan-parser.js.map +0 -1
  166. package/dist/src/redis.d.ts.map +0 -1
  167. package/dist/src/redis.js.map +0 -1
  168. package/dist/src/types.d.ts.map +0 -1
  169. package/dist/src/types.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "mcp__claude_ai_Notion__notion-create-pages",
5
+ "Bash(git add *)",
6
+ "Bash(git config *)",
7
+ "Bash(git commit *)",
8
+ "Bash(gh issue *)",
9
+ "Bash(git rebase *)",
10
+ "Bash(git push *)"
11
+ ],
12
+ "additionalDirectories": [
13
+ "/src/coaiapy"
14
+ ]
15
+ }
16
+ }
package/README.md CHANGED
@@ -87,6 +87,8 @@ Configuration is loaded with the following priority (highest wins):
87
87
  | `AWS_ACCESS_KEY_ID` | AWS credentials for Polly |
88
88
  | `GITHUB_TOKEN` | GitHub API token |
89
89
 
90
+ `coaia tash` follows coaiapy semantics: `-F/--file` reads the value from a file, `-T/--ttl` is interpreted in minutes, and the default CLI TTL is `5555`.
91
+
90
92
  ### coaia.json
91
93
 
92
94
  ```json
@@ -0,0 +1 @@
1
+ These article were written by AI
@@ -0,0 +1 @@
1
+ These article were written by AI
@@ -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
@@ -0,0 +1,144 @@
1
+ # Langfuse and Observability Patterns for LLM Application Pipelines
2
+
3
+ > Academic brief for the CoAiA.js project — Traces, spans, generations, and scores as the observability model for LLM-powered applications, with Langfuse as the open-source reference implementation.
4
+
5
+ ## Abstract
6
+
7
+ The non-deterministic nature of large language model (LLM) applications renders traditional monitoring approaches—based on error rates, response times, and throughput—insufficient for understanding system behavior. LLM applications require observability primitives that capture the semantic content of interactions: what was prompted, what was generated, how long each reasoning step took, what it cost, and whether the output was adequate. This paper examines the trace/span/generation/score observability model that has emerged as the standard for LLM application monitoring, with particular focus on Langfuse—an open-source platform that implements this model with full self-hosting capabilities. We analyze how this observability architecture maps to the structural tension methodology used in CoAiA.js, where traces correspond to structural tension chart progressions and scores correspond to Managerial Moment of Truth evaluations.
8
+
9
+ ## Introduction
10
+
11
+ Observability—the ability to understand a system's internal state from its external outputs—has been a cornerstone of distributed systems engineering since the advent of microservice architectures. The "three pillars" of traditional observability (logs, metrics, traces) were formalized through projects like OpenTelemetry and adopted industry-wide [1].
12
+
13
+ LLM applications introduce a fourth dimension that traditional observability does not address: **semantic quality**. A traditional web service either returns the correct data or fails with an error code. An LLM application can return a syntactically valid response that is semantically wrong—hallucinated, off-topic, harmful, or simply unhelpful. Detecting and monitoring these failure modes requires observability primitives that capture the content of model interactions, not just their operational characteristics [2].
14
+
15
+ Langfuse, founded in 2023 and fully open-sourced under the MIT license by 2025, has emerged as the leading open-source platform for LLM-specific observability. It provides a structured data model for capturing, analyzing, and evaluating LLM application behavior through traces, spans, generations, and scores [3][4].
16
+
17
+ ## Background
18
+
19
+ ### The Limitations of Traditional Observability for LLMs
20
+
21
+ Traditional observability tools monitor operational health: Is the service responding? How fast? What's the error rate? For LLM applications, these metrics miss the most critical failure mode: a service that responds quickly, without errors, but produces wrong or harmful output.
22
+
23
+ Consider an agent that uses an LLM to generate a SQL query based on a natural language question. Traditional monitoring would report: response time 2.3s, status 200, no errors. But the generated SQL might query the wrong table, apply incorrect filters, or produce results that are syntactically valid but semantically incorrect. Only by inspecting the prompt, the model's generation, and the downstream effects can we diagnose such issues [5].
24
+
25
+ ### The Trace/Span/Generation Model
26
+
27
+ Drawing from distributed tracing (Jaeger, Zipkin, OpenTelemetry), the LLM observability community has converged on a hierarchical model:
28
+
29
+ - **Trace:** A complete end-to-end execution, representing a user request or agent session from initiation to final response.
30
+ - **Span:** A logical subdivision within a trace, representing a distinct processing step (retrieval, prompt construction, tool execution, post-processing).
31
+ - **Generation:** A specific LLM completion event within a span, capturing the model, prompt, completion, token usage, and latency.
32
+ - **Score:** A quality assessment attached to a trace, span, or generation—either automated (LLM-as-judge), human-annotated, or computed from downstream metrics [6].
33
+
34
+ ## Analysis
35
+
36
+ ### Langfuse Architecture
37
+
38
+ Langfuse implements the trace/span/generation/score model through a web application backed by PostgreSQL and ClickHouse, deployable as a single Docker container or through managed cloud hosting.
39
+
40
+ #### Data Model
41
+
42
+ ```
43
+ Trace (user session / agent task)
44
+ ├── Span: "Document Retrieval"
45
+ │ ├── Generation: embedding model call (model: text-embedding-3-small, tokens: 124)
46
+ │ └── Span: "Vector DB Query" (duration: 45ms)
47
+ ├── Span: "Prompt Construction"
48
+ │ └── Generation: LLM call (model: claude-sonnet-4-20250514, input_tokens: 2048, output_tokens: 512, cost: $0.012)
49
+ ├── Span: "Response Post-processing"
50
+ │ └── Span: "Citation Extraction"
51
+ └── Score: {"name": "user_satisfaction", "value": 0.8, "source": "user_feedback"}
52
+ ```
53
+
54
+ Each element in this hierarchy captures:
55
+ - **Timing:** Start time, end time, latency
56
+ - **Cost:** Token counts and computed monetary cost per generation
57
+ - **Content:** Full input/output text (with optional redaction for PII)
58
+ - **Metadata:** Model version, temperature, custom tags, user ID
59
+ - **Scores:** Quality assessments at any granularity [7]
60
+
61
+ #### Integration Patterns
62
+
63
+ Langfuse provides multiple integration paths:
64
+
65
+ 1. **SDK instrumentation:** Direct Python/TypeScript SDK calls to create traces, spans, and generations programmatically.
66
+ 2. **Framework callbacks:** Native integration with LangChain, LlamaIndex, and other orchestration frameworks through callback handlers.
67
+ 3. **OpenTelemetry bridge:** As of 2025, Langfuse supports OpenTelemetry data ingestion, enabling teams to use standard OTel instrumentation while routing LLM-specific data to Langfuse [8].
68
+ 4. **LiteLLM proxy:** For teams using multiple LLM providers, LiteLLM can route all completions through Langfuse for unified monitoring.
69
+
70
+ #### Evaluation Capabilities
71
+
72
+ Beyond passive observation, Langfuse provides active evaluation:
73
+
74
+ - **LLM-as-Judge:** Automated quality scoring where a judge model evaluates the output of a target model against criteria.
75
+ - **Annotation Queues:** Human review workflows where team members score outputs and provide feedback.
76
+ - **Prompt Experimentation:** A/B testing of prompt variants with tracked performance metrics.
77
+ - **Dataset Management:** Curated evaluation datasets for regression testing and continuous quality monitoring [9].
78
+
79
+ ### Observability as Creative Orientation
80
+
81
+ The structural tension methodology provides a reframing of observability that aligns with creative orientation rather than problem-solving:
82
+
83
+ **Problem-solving observability** asks: "What went wrong? Where are the errors? What needs fixing?" This is the default mode for traditional monitoring—dashboards full of red/green indicators and error-rate alerts.
84
+
85
+ **Creative-orientation observability** asks: "What is the current reality of our system's behavior? How does it compare to the desired outcome of our quality standards? What is the structural tension, and how do we advance?" This reframing transforms observability from a reactive defensive tool into a creative instrument for advancing system quality.
86
+
87
+ In CoAiA.js, this manifests as:
88
+ - **Traces map to STC progressions.** Each agent session trace corresponds to progress along a structural tension chart.
89
+ - **Scores map to MMOT evaluations.** Quality scores correspond to Managerial Moment of Truth assessments—honest acknowledgment of the gap between desired and actual output quality.
90
+ - **Reality updates derive from observation data.** The current reality of a structural tension chart is continuously updated based on observability data—trace durations, generation quality scores, cost metrics.
91
+
92
+ ### Cost and Token Economics
93
+
94
+ A critical dimension of LLM observability absent from traditional monitoring is cost attribution. Each LLM generation consumes tokens with direct monetary cost:
95
+
96
+ - **Input tokens:** Charged per token of prompt content (context, instructions, examples)
97
+ - **Output tokens:** Charged per token of generated response (typically 2-4x input token price)
98
+ - **Embedding tokens:** Charged for vector embedding operations
99
+
100
+ Langfuse automatically computes and attributes costs across traces, enabling:
101
+ - Per-user cost tracking
102
+ - Per-feature cost attribution
103
+ - Cost anomaly detection
104
+ - Budget enforcement and alerting [10]
105
+
106
+ ### Self-Hosting and Data Sovereignty
107
+
108
+ A distinguishing feature of Langfuse in the LLM observability landscape is its full self-hosting capability. For organizations with strict data sovereignty requirements—common in healthcare, finance, and government—self-hosted Langfuse provides:
109
+
110
+ - Complete control over prompt and completion data
111
+ - No data transmission to third-party services
112
+ - Compliance with GDPR, HIPAA, and other regulatory frameworks
113
+ - Deployment as a single Docker container with minimal infrastructure requirements
114
+
115
+ This self-hosting model aligns with CoAiA.js's philosophy of zero-dependency, portable agent infrastructure.
116
+
117
+ ## Implications for CoAiA.js
118
+
119
+ Langfuse integration in CoAiA.js provides:
120
+
121
+ 1. **Structural tension observability.** Every STC progression generates Langfuse traces, making the creative process visible and analyzable.
122
+ 2. **MMOT-as-score.** Managerial Moment of Truth evaluations are recorded as Langfuse scores, creating a structured quality signal.
123
+ 3. **Cost-aware agents.** Agents can access their own cost metrics through Langfuse, enabling cost-conscious decision-making (e.g., choosing cheaper models for low-stakes operations).
124
+ 4. **Prompt management.** Langfuse's prompt versioning integrates with CoAiA.js's prompt decomposition pipeline, tracking which prompt versions produce which quality outcomes.
125
+ 5. **Self-hosted by default.** CoAiA.js recommends self-hosted Langfuse deployment to maintain the zero-external-dependency philosophy.
126
+
127
+ ## Conclusion
128
+
129
+ LLM observability represents a necessary evolution of monitoring practices for a new class of non-deterministic applications. The trace/span/generation/score model provides the right level of abstraction for understanding LLM application behavior, and Langfuse's open-source implementation makes this capability accessible without vendor lock-in. When combined with structural tension methodology, observability transforms from a problem-detection tool into a creative advancement instrument—continuously informing the honest assessment of current reality that drives purposeful progress.
130
+
131
+ ## References
132
+
133
+ 1. OpenTelemetry. "What is OpenTelemetry?" https://opentelemetry.io/docs/what-is-opentelemetry/
134
+ 2. Langfuse. (2024). "OpenTelemetry for LLM Observability." https://langfuse.com/blog/2024-10-opentelemetry-for-llm-observability
135
+ 3. Langfuse GitHub. https://github.com/langfuse/langfuse
136
+ 4. It's FOSS. (2025). "LLM Analytics Platform Langfuse Goes Open Source." https://itsfoss.com/news/langfuse-open-source/
137
+ 5. Toward Data Science. (2024). "LLM Monitoring and Observability: Hands-on with Langfuse." https://towardsdatascience.com/llm-monitoring-and-observability-hands-on-with-langfuse/
138
+ 6. Langfuse. "LLM Observability & Application Tracing." https://langfuse.com/docs/observability/overview
139
+ 7. Mayol, M. (2025). "Langfuse: The Definitive LLM Observability Platform in 2025." https://marcmayol.com/blog/en/langfuse_the_definitive_observability_platform_for_llms_in_2025/
140
+ 8. AWS. (2024). "Transform Large Language Model Observability with Langfuse." https://aws.amazon.com/blogs/apn/transform-large-language-model-observability-with-langfuse/
141
+ 9. Pondhouse Data. "Langfuse: The Open Source Observability Platform." https://www.pondhouse-data.com/blog/langfuse-observability-platform
142
+ 10. Star History. (2024). "Starlet #27 Langfuse: Open-source LLM Observability." https://www.star-history.com/blog/langfuse
143
+ 11. Maniak. (2026). "Open Source LLM Observability: Tracing AI Calls with AgentGateway and Langfuse." https://maniak.io/articles/2026-02-14-llm-observability-agentgateway-langfuse/
144
+ 12. Duvall, P. (2024). "LLM Observability with Langfuse: A Complete Guide." https://www.paulmduvall.com/llm-observability-with-langfuse-a-complete-guide/