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
@@ -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/
@@ -0,0 +1,163 @@
1
+ # The Medicine Wheel as Software Architecture Pattern
2
+
3
+ > Academic brief for the CoAiA.js project — Indigenous Four Directions framework (East/South/West/North) as a holistic, cyclical pattern for software development and AI agent orchestration.
4
+
5
+ ## Abstract
6
+
7
+ Software development methodologies have drawn from diverse intellectual traditions—military planning (waterfall), manufacturing (lean/agile), and evolutionary biology (iterative development). This paper examines the Indigenous Medicine Wheel, a framework used by many First Nations of North America, as an architectural pattern for software development and AI agent orchestration. The Four Directions—East (vision/initiation), South (analysis/growth), West (implementation/reflection), and North (integration/wisdom)—map to a cyclical development model that emphasizes balance, holistic assessment, and continuous renewal. Unlike linear or iterative models, the Medicine Wheel framework treats each phase as equally essential, prevents the common failure of rushing from vision directly to implementation, and provides a natural integration point for multi-agent systems where different agents specialize in different directional capacities. We present this mapping with appropriate acknowledgment of its Indigenous origins and examine its implementation in CoAiA.js's Four Directions orchestration pattern.
8
+
9
+ ## Introduction
10
+
11
+ Modern software development has converged on iterative models—agile sprints, continuous delivery, DevOps cycles—that share a common structure: plan, build, test, deploy, repeat. While effective, these models carry structural biases inherited from their industrial origins: they privilege velocity over reflection, output over wisdom, and individual productivity over relational coherence [1].
12
+
13
+ The Medicine Wheel, a teaching framework used by many Indigenous peoples across North America—including Anishinaabe, Lakota, and Cree traditions among others—offers an alternative structural model. The Wheel organizes experience into four directions, each representing a distinct mode of engagement with the world. While specific associations vary across nations and traditions, the overarching pattern emphasizes balance, cyclical renewal, and the interdependence of all phases [2][3].
14
+
15
+ This paper explores how the Four Directions mapping—East (vision), South (analysis), West (implementation), North (wisdom)—can inform software architecture, development processes, and AI agent orchestration. We proceed with deep respect for the Indigenous traditions from which this framework originates, acknowledging that software development is not the context for which it was created, and that adaptation must be done thoughtfully, in consultation with Indigenous perspectives when possible [4].
16
+
17
+ ## Background
18
+
19
+ ### The Medicine Wheel Teachings
20
+
21
+ The Medicine Wheel is not a single, monolithic teaching—it encompasses diverse traditions across hundreds of nations. Common structural elements include:
22
+
23
+ **East (Waabinong in Anishinaabemowin):** Associated with spring, new beginnings, vision, spiritual insight, and illumination. The direction of sunrise—where light first appears. In developmental terms, the East is where purpose is discovered and vision is formed [2][5].
24
+
25
+ **South (Zhaawanong):** Associated with summer, growth, trust, emotional development, youth, and embodiment. The direction of warmth—where vision begins to take form in lived experience. In developmental terms, the South is where analysis deepens understanding and relationships are built [2][5].
26
+
27
+ **West (Epangishmok):** Associated with autumn, introspection, maturity, physical grounding, and harvest. The direction of setting sun—where experience is processed and integrated. In developmental terms, the West is where implementation occurs through careful, reflective work [2][5].
28
+
29
+ **North (Kiiwedinong):** Associated with winter, wisdom, endurance, transformation, and renewal. The direction of stillness—where accumulated experience crystallizes into knowledge. In developmental terms, the North is where evaluation, documentation, and knowledge transfer prepare for the next cycle [2][5][6].
30
+
31
+ ### The Tech Anishinaabe Medicine Wheel
32
+
33
+ Academic work by Indigenous scholars has explicitly mapped Medicine Wheel teachings to technology contexts. The Tech Anishinaabe Medicine Wheel framework connects the four directions to digital practice:
34
+
35
+ - **East:** Digital dreaming and braiding—weaving technological possibilities with community needs
36
+ - **South:** Embodiment of Indigeneity—ensuring technology reflects and serves cultural values
37
+ - **West:** Decolonial infrastructure—building systems that challenge rather than reproduce colonial structures
38
+ - **North:** Relational governance and wisdom stewardship—managing technology through accountability and elder guidance [7]
39
+
40
+ This scholarly precedent demonstrates that the Medicine Wheel can meaningfully inform technology practice when approached with respect and appropriate contextualization.
41
+
42
+ ## Analysis
43
+
44
+ ### Four Directions Software Architecture
45
+
46
+ Mapping the Medicine Wheel to software development yields a cyclical architecture with four equally-weighted phases:
47
+
48
+ #### East: Vision and Initiation
49
+
50
+ The East phase corresponds to project inception, requirements discovery, and vision articulation. In structural tension terms, this is where the **desired outcome** is formulated.
51
+
52
+ Activities:
53
+ - Articulate what the software should create (not just what problems it should solve)
54
+ - Define the project's purpose and intended impact
55
+ - Establish success criteria from the perspective of all stakeholders
56
+ - Form the structural tension chart that will guide the development cycle
57
+
58
+ The East phase resists the temptation to jump immediately into technical design—it holds space for vision to fully form before committing to architectural decisions.
59
+
60
+ #### South: Analysis and Deep Research
61
+
62
+ The South phase corresponds to research, analysis, prototyping, and technical design. This is where vision meets reality through investigation.
63
+
64
+ Activities:
65
+ - Research existing solutions, prior art, and technical constraints
66
+ - Analyze the current reality relative to the desired outcome
67
+ - Design architecture and data models
68
+ - Prototype critical components to validate assumptions
69
+ - Build the team's shared understanding through collaborative exploration
70
+
71
+ The South phase prevents the "build first, understand later" anti-pattern by dedicating explicit time and energy to deep analysis before implementation begins.
72
+
73
+ #### West: Implementation and Reflection
74
+
75
+ The West phase corresponds to building, testing, and iterative refinement. Implementation is paired with continuous reflection—each build step is followed by assessment of what was learned.
76
+
77
+ Activities:
78
+ - Implement features according to the architectural design
79
+ - Write tests that validate both functional correctness and alignment with the vision
80
+ - Conduct code reviews as reflective practice, not just quality gates
81
+ - Refactor based on implementation insights
82
+ - Update the structural tension chart's current reality with honest observations
83
+
84
+ The West phase treats implementation as a learning process, not merely a production process. The pairing of building with reflection prevents the accumulation of technical and conceptual debt.
85
+
86
+ #### North: Integration and Wisdom
87
+
88
+ The North phase corresponds to deployment, evaluation, documentation, and knowledge synthesis. This is where the cycle's learning is captured and transmitted.
89
+
90
+ Activities:
91
+ - Deploy and monitor the system in production
92
+ - Evaluate outcomes against the structural tension chart's desired outcome (MMOT)
93
+ - Document decisions, rationale, and lessons learned
94
+ - Share knowledge with the broader team and community
95
+ - Identify what the next cycle should create, seeding the next East phase
96
+
97
+ The North phase ensures that wisdom accumulated during the cycle is not lost—it is crystallized into documentation, shared through teaching, and fed forward into the next cycle.
98
+
99
+ ### Cyclical vs. Linear Development
100
+
101
+ A critical property of the Medicine Wheel model is its **cyclical** nature. Unlike waterfall (linear) or even standard agile (iterative but often treated as linear sprints), the Medicine Wheel model establishes that:
102
+
103
+ 1. **Every direction is revisited.** The cycle is not "done"—each completion seeds the next rotation.
104
+ 2. **Skipping a direction creates imbalance.** Rushing from East (vision) to West (implementation), skipping South (analysis), produces fragile systems. Rushing from West (implementation) to East (new vision), skipping North (wisdom), loses accumulated learning.
105
+ 3. **Balance is structural, not aspirational.** The four equal quadrants enforce equal attention to each phase—unlike sprint-based models where "retrospectives" (North) are routinely shortened or skipped.
106
+
107
+ ### Four Directions Agent Orchestration
108
+
109
+ The Medicine Wheel provides a natural model for multi-agent orchestration, where different agents specialize in different directional capacities:
110
+
111
+ **East Agent (Visionary):** Specializes in vision articulation, desired outcome formation, and creative ideation. Uses divergent thinking to explore possibilities.
112
+
113
+ **South Agent (Analyst):** Specializes in research, analysis, and deep investigation. Performs the decomposition and understanding work that grounds vision in reality. This is the PDE (Prompt Decomposition Engine) domain.
114
+
115
+ **West Agent (Builder):** Specializes in implementation, testing, and iterative refinement. Executes the plan with attention to quality and craftsmanship.
116
+
117
+ **North Agent (Evaluator):** Specializes in evaluation, documentation, and wisdom synthesis. Performs MMOT assessments, identifies lessons learned, and prepares for the next cycle.
118
+
119
+ In a multi-agent CoAiA.js system, a task flows through the four directions:
120
+
121
+ ```
122
+ User Prompt → East Agent (vision) → South Agent (analysis/PDE) →
123
+ West Agent (implementation) → North Agent (evaluation/MMOT) →
124
+ [Cycle continues or completes]
125
+ ```
126
+
127
+ Each agent operates within its directional strength, and the handoff between directions creates natural checkpoints for quality assessment and course correction.
128
+
129
+ ### Ethical Considerations
130
+
131
+ Adapting Indigenous frameworks for software architecture requires ethical awareness:
132
+
133
+ 1. **Acknowledgment of origin.** The Medicine Wheel is not a "design pattern" discovered by software engineers—it is a living teaching with deep roots in Indigenous cultures that predate software by millennia.
134
+ 2. **Avoidance of appropriation.** Using the structural pattern while erasing its Indigenous context would constitute appropriation. Proper use includes citation, acknowledgment, and ideally, consultation with Indigenous knowledge keepers.
135
+ 3. **Respect for diversity.** Medicine Wheel teachings vary across nations. No single mapping should be presented as authoritative across all Indigenous traditions.
136
+ 4. **Reciprocity.** If Indigenous frameworks inform profitable software systems, there is an ethical obligation to give back to Indigenous communities—through funding, employment, land acknowledgment, or technology access [4][8].
137
+
138
+ ## Implications for CoAiA.js
139
+
140
+ The Four Directions framework is central to CoAiA.js architecture:
141
+
142
+ 1. **Directional agent specialization.** CoAiA.js supports agent configuration with directional affinities, enabling multi-agent orchestration that maps to the Medicine Wheel cycle.
143
+ 2. **PDE as South-direction work.** Prompt decomposition is explicitly positioned as South-direction analysis—the deep investigation that transforms vision into actionable understanding.
144
+ 3. **MMOT as North-direction work.** Evaluation and self-assessment are positioned as North-direction wisdom—the honest assessment that prepares for the next cycle.
145
+ 4. **Balanced cycle enforcement.** CoAiA.js session templates include all four directions, preventing the common anti-pattern of skipping analysis or evaluation.
146
+ 5. **Ethical framing.** Documentation and agent prompts include acknowledgment of the Medicine Wheel's Indigenous origins and ethical considerations for its use.
147
+
148
+ ## Conclusion
149
+
150
+ The Medicine Wheel offers software architecture a model it has largely lacked: a cyclical, balanced, holistic framework that gives equal weight to vision, analysis, implementation, and wisdom. By mapping the Four Directions to software development phases and AI agent orchestration patterns, we obtain a system that resists the velocity-over-reflection bias of industrial development models. When adopted with appropriate respect for its Indigenous origins, the Medicine Wheel pattern provides not just a development methodology, but an invitation to build technology with greater balance, humility, and relational awareness.
151
+
152
+ ## References
153
+
154
+ 1. Gaia. "Four Directions: Native American Medicine Wheel Meanings." https://www.gaia.com/article/four-directions
155
+ 2. York University. "Tech Anishinaabe Medicine Wheel: Decolonial Design Principles within Technology." https://yorkspace.library.yorku.ca/items/f8a521dc-fc29-4c36-8fde-058e0049ecc6
156
+ 3. Aktá Lakota Museum. "Native American Four Directions." https://aktalakota.stjo.org/lakota-culture/native-american-four-directions/
157
+ 4. University of British Columbia. "The Medicine Wheel - Decolonizing Teaching, Indigenizing Learning." https://indigenizinglearning.educ.ubc.ca/curriculum-bundles/the-medicine-wheel/
158
+ 5. U.S. National Park Service. "The Medicine Wheel." https://www.nps.gov/articles/000/the-medicine-wheel.htm
159
+ 6. Frontiers in Public Health. (2024). "The Medicine Wheel as a Public Health Approach." https://www.frontiersin.org/journals/public-health/articles/10.3389/fpubh.2024.1392517/full
160
+ 7. Beck, P. V., Walters, A. L., & Francisco, N. (1996). *The Sacred: Ways of Knowledge, Sources of Life*. Navajo Community College Press.
161
+ 8. Cajete, G. (2000). *Native Science: Natural Laws of Interdependence*. Clear Light Publishers.
162
+ 9. Senge, P. (1990). *The Fifth Discipline*. Doubleday.
163
+ 10. Fritz, R. (1989). *The Path of Least Resistance*. Fawcett Columbine.
@@ -0,0 +1,156 @@
1
+ # The Managerial Moment of Truth Applied to Autonomous AI Agents
2
+
3
+ > Academic brief for the CoAiA.js project — Fritz and Bodaken's MMOT self-evaluation cycle (acknowledge→analyze→update→recommit) as a computational pattern for agent self-correction.
4
+
5
+ ## Abstract
6
+
7
+ Autonomous AI agents operating over extended sessions face a persistent challenge: drift between intended behavior and actual output. Without structured self-evaluation mechanisms, agents accumulate errors, pursue stale objectives, and fail to adapt when their actions produce unexpected results. This paper examines the Managerial Moment of Truth (MMOT)—a four-step self-evaluation cycle developed by Robert Fritz and Bruce Bodaken for organizational leadership—and its application as a computational pattern for autonomous AI agent self-correction. The MMOT cycle (acknowledge the truth → analyze how it happened → create an action plan → establish feedback) provides a structured framework for agents to detect discrepancies between expected and actual outcomes, understand their causes, plan corrections, and verify improvement. We formalize this cycle as a state machine, define its integration with structural tension charts, and evaluate its effectiveness in preventing the oscillatory patterns that characterize agents without self-evaluation capabilities.
8
+
9
+ ## Introduction
10
+
11
+ The central challenge of autonomous AI agent operation is not capability—modern LLMs can generate code, write documents, and make decisions—but **calibration**: ensuring that what the agent produces matches what was intended. In human organizations, this calibration is achieved through management: periodic assessment of performance against expectations, honest acknowledgment of gaps, and structured correction plans [1].
12
+
13
+ Robert Fritz and Bruce Bodaken formalized this process in *The Managerial Moment of Truth* (2006), identifying a four-step cycle that transforms moments of discrepancy between expected and actual performance into opportunities for genuine advancement rather than blame, avoidance, or oscillation [2]. The MMOT framework was implemented at Blue Shield of California with documented improvements in organizational performance, demonstrating its practical effectiveness in complex, multi-agent (human) systems [3].
14
+
15
+ This paper argues that the MMOT cycle is directly applicable to autonomous AI agents—and that agents equipped with structured self-evaluation outperform those relying solely on reward signals or error correction.
16
+
17
+ ## Background
18
+
19
+ ### The MMOT Four-Step Cycle
20
+
21
+ Fritz and Bodaken define the Managerial Moment of Truth as occurring whenever there is a discrepancy between what was expected and what actually happened. The four steps are:
22
+
23
+ **Step 1: Acknowledge the Truth.** The first and most critical step is honest recognition of the gap between expectation and reality. This requires:
24
+ - Separating objective observations from opinions or rationalizations
25
+ - Neither minimizing ("it's almost right") nor catastrophizing ("everything is broken")
26
+ - Stating the discrepancy clearly and specifically
27
+
28
+ **Step 2: Analyze How It Got to Be That Way.** Understanding the causal chain that produced the discrepancy:
29
+ - What decisions led to this outcome?
30
+ - Were there systemic factors (unclear instructions, missing context, wrong assumptions)?
31
+ - Was the problem in execution, design, or both?
32
+ - This step emphasizes understanding, not blame.
33
+
34
+ **Step 3: Create an Action Plan.** Developing concrete, actionable steps to address the root causes:
35
+ - What specifically needs to change?
36
+ - What resources or information are needed?
37
+ - What is the timeline for correction?
38
+
39
+ **Step 4: Establish a Feedback System.** Implementing mechanisms to monitor whether the correction is working:
40
+ - How will progress be measured?
41
+ - When will the next evaluation occur?
42
+ - What constitutes adequate vs. inadequate improvement? [2][4]
43
+
44
+ ### Self-Evaluation in AI Systems
45
+
46
+ Existing approaches to AI agent self-evaluation include:
47
+
48
+ - **Reward-based correction (RL):** Agents receive scalar rewards and adjust behavior to maximize expected reward. Limited by reward specification quality and temporal credit assignment.
49
+ - **Constitutional AI (Anthropic):** Agents evaluate their own outputs against a set of constitutional principles, revising when violations are detected. Effective for safety but not for task-quality calibration.
50
+ - **Reflection prompting (Reflexion):** Agents are prompted to review and critique their own reasoning, generating improved outputs. Effective but unstructured—no guarantee of systematic causal analysis.
51
+ - **Verifier models:** Separate models evaluate the primary model's output, providing binary or graded acceptance signals. Adds latency and cost without providing causal insight [5].
52
+
53
+ None of these approaches provide the structured, four-phase evaluation cycle that MMOT defines. Most notably, none emphasize the **honest acknowledgment** step that Fritz and Bodaken identify as the critical foundation—without which all subsequent analysis and correction operates on distorted data.
54
+
55
+ ## Analysis
56
+
57
+ ### MMOT as Agent State Machine
58
+
59
+ The MMOT cycle can be formalized as a state machine with four states and well-defined transitions:
60
+
61
+ ```
62
+ ┌──────────────┐ discrepancy ┌─────────────────┐
63
+ │ OPERATING │ ──────detected────► │ ACKNOWLEDGE │
64
+ │ │ │ (observe gap) │
65
+ └──────────────┘ └────────┬─────────┘
66
+ ▲ │
67
+ │ ▼
68
+ ┌──────┴───────┐ ┌─────────────────┐
69
+ │ RECOMMIT │ ◄───────────────── │ ANALYZE │
70
+ │ (feedback) │ │ (understand why)│
71
+ └──────┬───────┘ └────────┬─────────┘
72
+ │ │
73
+ │ ┌─────────────────┐ │
74
+ └────────►│ UPDATE │◄─────────┘
75
+ │ (action plan) │
76
+ └─────────────────┘
77
+ ```
78
+
79
+ Each state has defined inputs, outputs, and transition conditions:
80
+
81
+ - **ACKNOWLEDGE:** Input: expected output + actual output. Processing: compute delta, classify discrepancy type (quality, completeness, correctness, relevance). Output: structured discrepancy report.
82
+ - **ANALYZE:** Input: discrepancy report. Processing: identify causal factors from agent's decision log (which STC was active, what prompt was used, what context was available). Output: root cause analysis.
83
+ - **UPDATE:** Input: root cause analysis. Processing: generate corrective action steps, update structural tension chart with new reality observations. Output: revised action plan.
84
+ - **RECOMMIT:** Input: revised action plan. Processing: verify plan feasibility, set evaluation checkpoints. Output: updated agent state with monitoring triggers [6].
85
+
86
+ ### Elements of Performance
87
+
88
+ A key MMOT concept is "Elements of Performance"—the specific, measurable criteria against which output quality is assessed. For AI agents, these map naturally to evaluation rubrics:
89
+
90
+ ```jsonl
91
+ {"type":"performance_element","chartId":"chart_001","description":"Generated code compiles without errors","category":"EXECUTION"}
92
+ {"type":"performance_element","chartId":"chart_001","description":"API design follows REST conventions","category":"DESIGN"}
93
+ {"type":"performance_element","chartId":"chart_001","description":"Test coverage exceeds 80%","category":"EXECUTION"}
94
+ {"type":"performance_element","chartId":"chart_001","description":"Error messages provide actionable guidance","category":"DESIGN"}
95
+ ```
96
+
97
+ Elements of Performance are defined at chart creation time and serve as the rubric against which the ACKNOWLEDGE step evaluates output. They transform the vague question "is this good?" into the specific assessment "does this meet criterion X?"
98
+
99
+ ### Integration with Structural Tension Charts
100
+
101
+ MMOT and structural tension charts form a complementary system:
102
+
103
+ 1. **STCs define the creative frame.** The desired outcome and current reality establish what the agent is trying to create.
104
+ 2. **MMOT provides the calibration mechanism.** At defined checkpoints (action step completion, session milestones), the MMOT cycle evaluates whether the agent's actions are advancing the chart.
105
+ 3. **Reality updates flow from MMOT to STC.** The ACKNOWLEDGE and ANALYZE steps produce observations that update the structural tension chart's current reality, maintaining honest assessment.
106
+ 4. **Corrective actions flow from MMOT to STC.** The UPDATE step may add new action steps to the chart or revise existing ones based on the evaluation.
107
+
108
+ This integration prevents the "completion theater" failure mode where agents mark tasks as done without verifying that the work actually advanced the desired outcome.
109
+
110
+ ### Preventing Oscillation Through Honest Acknowledgment
111
+
112
+ Fritz's insight that honest acknowledgment is the critical first step has a direct computational analog: **agents must evaluate their actual output, not their intended output.** Common failure modes include:
113
+
114
+ - **Rationalization:** "The code doesn't compile, but the logic is correct." An agent in ACKNOWLEDGE mode must report: "The code does not compile. Expected: compilable code. Actual: 3 syntax errors."
115
+ - **Minimization:** "Minor formatting issues." An honest agent acknowledges: "Output does not meet the formatting Element of Performance. Specific deviations: [list]."
116
+ - **Deflection:** "The instructions were ambiguous." While possibly true, the ACKNOWLEDGE step first establishes the gap; ANALYZE then examines whether instruction ambiguity was a causal factor.
117
+
118
+ By forcing honest acknowledgment before analysis, the MMOT cycle prevents agents from entering the oscillatory pattern where problems are rationalized away, resurface in different forms, and are rationalized away again.
119
+
120
+ ### Directional MMOT: Four-Perspective Evaluation
121
+
122
+ An advanced application integrates MMOT with the Four Directions framework, evaluating output from four complementary perspectives:
123
+
124
+ - **South (DESIGN/Structure):** Does the architecture support the desired outcome? Are structural decisions sound?
125
+ - **East (EXECUTION/Narrative):** Is the implementation clear, coherent, and well-communicated?
126
+ - **West (EXECUTION/Embodied):** Does the output work in practice? Is it operationally sound?
127
+ - **North (DESIGN/Wisdom):** Does the work serve the larger purpose? Is it aligned with long-term goals?
128
+
129
+ Each direction applies the full MMOT cycle, producing a multi-perspective evaluation that catches blind spots inherent in single-viewpoint assessment.
130
+
131
+ ## Implications for CoAiA.js
132
+
133
+ MMOT is a first-class citizen in the CoAiA.js agent lifecycle:
134
+
135
+ 1. **Automatic MMOT triggers.** Agents perform MMOT evaluations at action step completion, session checkpoints, and when error conditions are detected.
136
+ 2. **Elements of Performance per chart.** Every structural tension chart can define evaluation criteria, giving the MMOT cycle concrete rubrics.
137
+ 3. **JSONL-recorded evaluations.** All MMOT evaluations are recorded in the agent's JSONL memory, creating a complete audit trail of self-evaluation and correction.
138
+ 4. **Langfuse integration.** MMOT scores are exported as Langfuse scores, enabling aggregate analysis of agent calibration quality.
139
+ 5. **Four Directions evaluation.** High-stakes charts support directional MMOT, ensuring multi-perspective assessment.
140
+
141
+ ## Conclusion
142
+
143
+ The Managerial Moment of Truth provides a structured, proven framework for the critical but often ad-hoc process of agent self-evaluation. By formalizing the acknowledge→analyze→update→recommit cycle as a computational state machine and integrating it with structural tension charts, CoAiA.js obtains agents that self-correct through honest assessment rather than reward optimization—agents that tell the truth about their own performance and use that truth as a creative force for advancement.
144
+
145
+ ## References
146
+
147
+ 1. Fritz, R., & Bodaken, B. (2006). *The Managerial Moment of Truth: The Essential Step in Helping People Improve Performance*. Free Press.
148
+ 2. Robert Fritz Inc. "Managerial Moment of Truth (MMOT)." https://www.robertfritz.com/wp/programs/managerial-moment-of-truth-mmot/
149
+ 3. LeadershipNow. (2006). "The Managerial Moment of Truth." https://leadershipnow.com/leadingblog/2006/05/the_managerial_moment_of_truth.html
150
+ 4. The Systems Thinker. "The Managerial Moment of Truth." https://thesystemsthinker.com/the-managerial-moment-of-truth/
151
+ 5. KEV LLC. "Seize Your Managerial Moment of Truth: A Four-Step Process." https://kevllc.com/blog/seize-your-managerial-moment-of-truth-a-four-step-process-for-results/
152
+ 6. Simon & Schuster. *The Managerial Moment of Truth* (book page). https://www.simonandschuster.com/books/The-Managerial-Moment-of-Truth/Bruce-Bodaken/9781451655353
153
+ 7. Shinn, N., et al. (2023). "Reflexion: Language Agents with Verbal Reinforcement Learning." *NeurIPS 2023*.
154
+ 8. Bai, Y., et al. (2022). "Constitutional AI: Harmlessness from AI Feedback." *Anthropic*.
155
+ 9. Fritz, R. (1989). *The Path of Least Resistance*. Fawcett Columbine.
156
+ 10. Fritz, R. (1999). *The Path of Least Resistance for Managers*. Berrett-Koehler Publishers.