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,161 @@
1
+ # Model Context Protocol as Standardized Interagent Communication
2
+
3
+ > Academic brief for the CoAiA.js project — MCP as the universal protocol for tool-using AI agents, examining Anthropic's design, transport mechanisms, and the tool/resource/prompt primitive model.
4
+
5
+ ## Abstract
6
+
7
+ The Model Context Protocol (MCP), introduced by Anthropic in late 2024, establishes an open standard for connecting AI language models to external tools, data sources, and services. Often described as "USB-C for AI integration," MCP addresses the N×M integration problem that has plagued agent-tool ecosystems by defining a single, well-typed protocol through which any compliant AI host can communicate with any compliant tool server. This paper analyzes MCP's architectural design—its JSON-RPC 2.0 foundation, dual-transport model (stdio for local, HTTP for distributed), and three-primitive abstraction (tools, resources, prompts). We examine how MCP enables dynamic tool discovery, maintains session state, and enforces human-in-the-loop safety boundaries. The analysis situates MCP within the broader landscape of agent communication protocols and evaluates its implications for building composable, observable, and secure AI agent systems within CoAiA.js.
8
+
9
+ ## Introduction
10
+
11
+ The proliferation of AI agents that interact with external tools—databases, APIs, file systems, code execution environments—has created a fragmentation crisis. Each tool integration requires custom adapter code: prompt formatting, response parsing, error handling, and authentication logic unique to that specific tool-host pairing. For an ecosystem with N AI hosts and M tools, this produces N×M integration points, each independently maintained and tested [1].
12
+
13
+ The Language Server Protocol (LSP), developed by Microsoft for IDE integration, demonstrated that a well-designed protocol can collapse this N×M problem to N+M: each host implements the protocol once, each tool implements it once, and all combinations work. MCP applies this same principle to AI agent-tool communication [2].
14
+
15
+ Anthropic released MCP as an open specification in November 2024, accompanied by reference implementations in TypeScript and Python, and a growing ecosystem of community-built MCP servers for systems including GitHub, PostgreSQL, Slack, Puppeteer, and file systems [3].
16
+
17
+ ## Background
18
+
19
+ ### The Agent-Tool Integration Problem
20
+
21
+ Modern AI agents require access to diverse external capabilities:
22
+ - **Data retrieval:** Querying databases, searching documents, reading files
23
+ - **Action execution:** Creating records, sending messages, deploying code
24
+ - **Context provision:** Fetching project structure, reading configuration, accessing knowledge bases
25
+ - **Observation:** Monitoring system state, checking test results, reading logs
26
+
27
+ Without a standard protocol, each capability requires bespoke integration logic within each agent framework—LangChain, CrewAI, AutoGen, and custom implementations each maintain their own tool interfaces, parsing logic, and error handling.
28
+
29
+ ### Prior Art: Language Server Protocol
30
+
31
+ LSP, standardized by Microsoft in 2016, provides a direct architectural precedent for MCP. LSP defines:
32
+ - A JSON-RPC 2.0 message protocol
33
+ - Capability negotiation between client and server
34
+ - A standard set of operations (completions, diagnostics, hover info)
35
+ - Transport over stdio or TCP
36
+
37
+ MCP follows this design closely, adapting it from IDE-language tool communication to AI agent-tool communication [4].
38
+
39
+ ## Analysis
40
+
41
+ ### Protocol Architecture
42
+
43
+ MCP defines three roles in a clear hierarchy:
44
+
45
+ 1. **Host:** The overarching application (IDE, chat interface, agent runtime) that manages one or more MCP clients.
46
+ 2. **Client:** A protocol handler that maintains a 1:1 session with a single MCP server. The client translates between the host's intent and the server's capabilities.
47
+ 3. **Server:** A process that exposes tools, resources, and prompts to the client, handling actual execution and data access.
48
+
49
+ This separation enables clean architectural boundaries: the host manages user interaction and policy decisions, the client handles protocol mechanics, and the server encapsulates tool-specific logic.
50
+
51
+ ### Message Protocol: JSON-RPC 2.0
52
+
53
+ All MCP communication uses JSON-RPC 2.0, a lightweight remote procedure call protocol that defines:
54
+
55
+ ```json
56
+ // Request
57
+ {"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "read_file", "arguments": {"path": "/src/index.ts"}}}
58
+
59
+ // Response
60
+ {"jsonrpc": "2.0", "id": 1, "result": {"content": [{"type": "text", "text": "import { Server } from '@modelcontextprotocol/sdk';"}]}}
61
+
62
+ // Notification (no response expected)
63
+ {"jsonrpc": "2.0", "method": "notifications/progress", "params": {"progressToken": "abc", "progress": 50, "total": 100}}
64
+ ```
65
+
66
+ The choice of JSON-RPC over alternatives (Protocol Buffers, MessagePack) prioritizes debuggability and ecosystem accessibility over raw performance—a deliberate trade-off for a protocol intended to be adopted broadly across diverse language ecosystems [5].
67
+
68
+ ### Transport Mechanisms
69
+
70
+ MCP supports two transport modes, each optimized for different deployment contexts:
71
+
72
+ **Stdio Transport:** For local, same-machine integration. The MCP server runs as a child process of the client, communicating through standard input/output streams. This mode:
73
+ - Requires zero network configuration
74
+ - Provides natural process lifecycle management (client starts/stops the server)
75
+ - Offers inherent security through process isolation
76
+ - Is ideal for development environments, desktop applications, and single-machine agent runtimes
77
+
78
+ **HTTP Transport (Streamable HTTP):** For distributed deployments where the MCP server runs on a different machine or as a shared service. This mode:
79
+ - Supports Server-Sent Events (SSE) for real-time server-to-client notifications
80
+ - Requires authentication and authorization mechanisms
81
+ - Enables shared tool servers serving multiple clients
82
+ - Is suited for production, cloud, and multi-agent deployments [6]
83
+
84
+ ### The Three Primitives
85
+
86
+ MCP's abstraction model centers on three primitive types that encompass the full range of agent-tool interactions:
87
+
88
+ **Tools:** Executable functions that the AI agent can invoke. Tools are the most dynamic primitive—they represent actions with side effects.
89
+
90
+ ```json
91
+ {
92
+ "name": "create_issue",
93
+ "description": "Create a new GitHub issue",
94
+ "inputSchema": {
95
+ "type": "object",
96
+ "properties": {
97
+ "title": {"type": "string"},
98
+ "body": {"type": "string"},
99
+ "labels": {"type": "array", "items": {"type": "string"}}
100
+ },
101
+ "required": ["title"]
102
+ }
103
+ }
104
+ ```
105
+
106
+ **Resources:** Data sources that provide context to the model. Resources are read-oriented and can be static (file contents) or dynamic (database query results).
107
+
108
+ **Prompts:** Instruction templates that guide the model's behavior. Prompts enable servers to provide domain-specific guidance that shapes how the model uses the server's tools and resources.
109
+
110
+ ### Dynamic Tool Discovery
111
+
112
+ A critical innovation in MCP is runtime tool discovery. Rather than requiring static configuration of available tools, clients can query servers for their capabilities at session initialization:
113
+
114
+ ```json
115
+ // Client requests available tools
116
+ {"jsonrpc": "2.0", "id": 1, "method": "tools/list"}
117
+
118
+ // Server responds with tool schemas
119
+ {"jsonrpc": "2.0", "id": 1, "result": {"tools": [
120
+ {"name": "read_file", "description": "Read a file's contents", "inputSchema": {...}},
121
+ {"name": "search_code", "description": "Search for patterns in code", "inputSchema": {...}}
122
+ ]}}
123
+ ```
124
+
125
+ This dynamic discovery enables:
126
+ - **Modular tool composition:** Agents connect to different MCP servers based on the task, discovering capabilities at runtime.
127
+ - **Graceful degradation:** If a server is unavailable, the agent operates with reduced capabilities rather than failing entirely.
128
+ - **Semantic tool selection:** LLMs can choose tools based on their descriptions, eliminating the need for hard-coded tool routing logic.
129
+
130
+ ### Human-in-the-Loop Safety
131
+
132
+ MCP explicitly incorporates human approval gates for sensitive operations. The specification defines that tool invocations may require user consent, with the host application presenting confirmation dialogs for operations that modify state, access sensitive data, or perform irreversible actions [7].
133
+
134
+ This design philosophy—making the human a mandatory checkpoint for high-impact operations—aligns with the creative orientation principle that agents should advance toward desired outcomes under human guidance, rather than operating autonomously on problem-solving heuristics.
135
+
136
+ ## Implications for CoAiA.js
137
+
138
+ MCP serves as the standard communication layer in CoAiA.js for all external tool interactions:
139
+
140
+ 1. **Structural tension charts as MCP resources.** Active STCs are exposed as MCP resources, enabling any MCP-compliant host to read agent state.
141
+ 2. **MMOT evaluations as MCP tools.** The Managerial Moment of Truth cycle is exposed as an invocable tool, enabling external orchestrators to trigger self-evaluation.
142
+ 3. **JSONL memory as MCP resource.** Agent memory files are exposed through MCP's resource primitive, supporting both direct access and subscription to updates.
143
+ 4. **Multi-server composition.** A CoAiA.js agent can connect to multiple MCP servers simultaneously—one for code operations, one for observability (Langfuse), one for knowledge graph queries—composing capabilities dynamically.
144
+ 5. **Observability through protocol traces.** MCP's JSON-RPC format produces naturally structured logs that feed into the observability pipeline.
145
+
146
+ ## Conclusion
147
+
148
+ The Model Context Protocol represents a maturation point for the AI agent ecosystem—the transition from bespoke, framework-specific tool integrations to a universal, well-typed protocol that enables composable agent architectures. By standardizing the three fundamental primitives of agent-tool interaction (tools, resources, prompts) over a debuggable JSON-RPC protocol with dual-transport support, MCP establishes the infrastructure layer that makes complex, multi-tool agent systems viable for production deployment.
149
+
150
+ ## References
151
+
152
+ 1. Anthropic. (2024). "Introducing the Model Context Protocol." https://www.anthropic.com/news/model-context-protocol
153
+ 2. Model Context Protocol Specification. (2025). https://modelcontextprotocol.io/specification/2025-03-26
154
+ 3. Model Context Protocol GitHub. https://github.com/modelcontextprotocol/modelcontextprotocol
155
+ 4. InfoQ. (2024). "Anthropic Publishes Model Context Protocol Specification." https://www.infoq.com/news/2024/12/anthropic-model-context-protocol/
156
+ 5. LogRocket. (2024). "Understanding Anthropic's Model Context Protocol." https://blog.logrocket.com/understanding-anthropic-model-context-protocol-mcp/
157
+ 6. BridgeApp AI. (2024). "A Complete Guide to MCP: Architecture, Integration, and Best Practices." https://bridgeapp.ai/resources/blog/a-complete-guide-to-model-context-protocol-mcp-architecture-integration-and-best-practices
158
+ 7. Model Context Protocol Info. "MCP Docs." https://modelcontextprotocol.info/docs/
159
+ 8. Wikipedia. (2025). "Model Context Protocol." https://en.wikipedia.org/wiki/Model_Context_Protocol
160
+ 9. UPP Technology. (2024). "Anthropic's MCP: The USB-C Standard for AI Integration." https://www.upp-technology.com/en/news/anthropics-model-context-protocol-mcp-the-usb-c-standard-for-ai-integration/
161
+ 10. Weights & Biases. (2024). "The Model Context Protocol by Anthropic: Origins, Functionality, and Impact." https://wandb.ai/onlineinference/mcp/reports/The-Model-Context-Protocol-MCP-by-Anthropic
@@ -0,0 +1,186 @@
1
+ # Prompt Decomposition as Engineering Methodology
2
+
3
+ > Academic brief for the CoAiA.js project — Breaking complex prompts into primary/secondary intents, context requirements, and Four Directions action stacks through systematic decomposition.
4
+
5
+ ## Abstract
6
+
7
+ Complex prompts submitted to large language models frequently contain multiple intents—some explicit, some implied by hedging language or contextual assumptions. When processed holistically, LLMs tend to prioritize salient explicit intents while dropping implicit ones, resulting in incomplete task execution. This paper presents Prompt Decomposition Engineering (PDE) as a systematic methodology for analyzing complex prompts before execution. PDE identifies primary and secondary intents, extracts implicit requirements from hedging language ("maybe," "also consider," "if possible"), maps dependencies between action items, and organizes them into executable Four Directions action stacks. We compare PDE with existing reasoning strategies—Chain-of-Thought (CoT), Tree-of-Thought (ToT), Self-Consistency, and Decomposed Prompting (DecomP)—and argue that PDE operates at a fundamentally different level: it decomposes the *input prompt* rather than the *reasoning process*, serving as a completeness safeguard rather than a reasoning enhancer. The methodology is evaluated in the context of the CoAiA.js PDE engine.
8
+
9
+ ## Introduction
10
+
11
+ A user submits the following prompt to an AI agent:
12
+
13
+ > "Set up the project with TypeScript, add ESLint and Prettier, maybe also configure Husky for pre-commit hooks, and write a basic README. Oh and we'll probably need tests too—Jest should work. Make sure the CI/CD pipeline runs everything."
14
+
15
+ This 44-word prompt contains at least seven distinct action items, three implicit dependencies, two hedged requests ("maybe," "probably"), and one underdetermined requirement ("runs everything"). A capable LLM might execute the most salient items (TypeScript setup, ESLint, README) while dropping the hedged ones (Husky, Jest) and underdetermining others (CI/CD scope) [1].
16
+
17
+ The fundamental issue is not that LLMs lack capability—it's that complex prompts exceed the scope of single-pass intent extraction. Prompt Decomposition Engineering addresses this by introducing a systematic pre-processing phase that decomposes complex prompts into structured, complete, and dependency-mapped action specifications before execution begins.
18
+
19
+ ## Background
20
+
21
+ ### Existing Prompt Engineering Strategies
22
+
23
+ The prompt engineering landscape has produced several strategies for improving LLM reasoning on complex tasks:
24
+
25
+ **Chain-of-Thought (CoT):** Introduced by Wei et al. (2022), CoT prompts models to "think step by step," revealing intermediate reasoning. This improves accuracy on multi-step problems but does not prevent intent loss—the model may reason carefully about a subset of intents while still dropping others [2].
26
+
27
+ **Tree-of-Thought (ToT):** Yao et al. (2023) extended CoT to explore multiple reasoning branches simultaneously, evaluating alternative solution paths. ToT improves exploration of solution spaces but addresses reasoning quality, not input completeness—it assumes all intents have been correctly identified [3].
28
+
29
+ **Self-Consistency:** Wang et al. (2022) proposed sampling multiple reasoning paths and selecting the most consistent answer. This reduces errors in reasoning but does not address the prior problem of intent extraction from complex inputs [4].
30
+
31
+ **Decomposed Prompting (DecomP):** Khot et al. (2022) introduced decomposition of complex questions into sub-questions, each handled by specialized sub-prompts. DecomP is the closest precursor to PDE but operates on reasoning decomposition rather than input prompt decomposition—it assumes the question is well-specified and decomposes the answer strategy [5].
32
+
33
+ **Plan-and-Solve (PS):** Wang et al. (2023) proposed devising a plan before executing, then following the plan step-by-step. PS addresses sequencing but not completeness—the plan may omit implicit intents [6].
34
+
35
+ ### The Completeness Gap
36
+
37
+ All existing strategies share a common assumption: the model correctly identifies all intents in the input prompt. This assumption fails for complex, multi-intent prompts—particularly those containing:
38
+
39
+ - **Hedging language:** "maybe," "perhaps," "if possible," "also consider"
40
+ - **Embedded conditionals:** "if X then also Y"
41
+ - **Implied requirements:** "set up CI/CD" implies test execution, linting, build verification
42
+ - **Conversational asides:** "oh and we'll need..." signals an afterthought the model may deprioritize
43
+ - **Scope ambiguity:** "make sure everything works" requires decomposition to define "everything"
44
+
45
+ PDE addresses this completeness gap by operating on the prompt itself, before any reasoning strategy is applied.
46
+
47
+ ## Analysis
48
+
49
+ ### The PDE Methodology
50
+
51
+ PDE operates in three phases:
52
+
53
+ #### Phase 1: Intent Extraction
54
+
55
+ The complex prompt is analyzed for:
56
+
57
+ **Primary Intents:** Directly stated, unhedged action items.
58
+ ```json
59
+ [
60
+ {"intent": "Set up project with TypeScript", "confidence": "high", "explicit": true},
61
+ {"intent": "Add ESLint and Prettier", "confidence": "high", "explicit": true},
62
+ {"intent": "Write a basic README", "confidence": "high", "explicit": true}
63
+ ]
64
+ ```
65
+
66
+ **Secondary Intents:** Hedged, implied, or conditionally stated items.
67
+ ```json
68
+ [
69
+ {"intent": "Configure Husky for pre-commit hooks", "confidence": "medium", "marker": "maybe also"},
70
+ {"intent": "Set up Jest testing", "confidence": "medium", "marker": "probably need"},
71
+ {"intent": "Configure CI/CD pipeline", "confidence": "high", "explicit": true, "underdetermined": true}
72
+ ]
73
+ ```
74
+
75
+ **Implicit Intents:** Requirements not stated but logically entailed.
76
+ ```json
77
+ [
78
+ {"intent": "Create package.json with scripts", "derivedFrom": "TypeScript setup + tooling"},
79
+ {"intent": "Create tsconfig.json", "derivedFrom": "TypeScript setup"},
80
+ {"intent": "Define CI/CD scope (lint, test, build)", "derivedFrom": "CI/CD + all tools mentioned"}
81
+ ]
82
+ ```
83
+
84
+ #### Phase 2: Dependency Mapping
85
+
86
+ Extracted intents are analyzed for dependencies:
87
+
88
+ ```
89
+ TypeScript setup ← ESLint config (needs tsconfig)
90
+ TypeScript setup ← Jest config (needs ts-jest)
91
+ ESLint + Prettier ← Husky pre-commit hooks (hooks run lint/format)
92
+ All tooling ← CI/CD pipeline (pipeline runs all tools)
93
+ All tooling ← README (documents all tools)
94
+ ```
95
+
96
+ This dependency graph prevents execution ordering errors (e.g., configuring Husky before ESLint exists).
97
+
98
+ #### Phase 3: Four Directions Organization
99
+
100
+ Extracted and dependency-mapped intents are organized into a Four Directions action stack:
101
+
102
+ **East (Vision/Initiation):** Understand the project requirements, establish the desired architecture, define what "done" looks like.
103
+
104
+ **South (Analysis/Design):** Decompose into specific, executable tasks. This is where PDE's output resides—the structured decomposition.
105
+
106
+ **West (Implementation/Testing):** Execute the tasks in dependency order, verifying each step.
107
+
108
+ **North (Integration/Wisdom):** Review the complete result, verify all intents (including secondary and implicit) have been addressed, document the outcome.
109
+
110
+ ### Comparison with Existing Strategies
111
+
112
+ | Strategy | Operates On | Addresses | Completeness |
113
+ |----------|------------|-----------|-------------|
114
+ | CoT | Reasoning process | Accuracy | No |
115
+ | ToT | Solution exploration | Creativity | No |
116
+ | Self-Consistency | Answer validation | Reliability | No |
117
+ | DecomP | Question structure | Complexity | Partial |
118
+ | Plan-and-Solve | Execution plan | Sequencing | Partial |
119
+ | **PDE** | **Input prompt** | **Completeness** | **Yes** |
120
+
121
+ PDE is complementary to, not competitive with, existing strategies. A system can first apply PDE to ensure all intents are captured, then apply CoT or ToT to reason about each extracted intent.
122
+
123
+ ### Hedging Language as Signal, Not Noise
124
+
125
+ A distinctive contribution of PDE is its treatment of hedging language. Traditional NLP treats hedging ("maybe," "perhaps," "if possible") as uncertainty markers to be discounted. PDE treats them as **intent signals with reduced confidence**—the user wants the thing, but is expressing it with social softening or conditional framing.
126
+
127
+ When a user says "maybe also configure Husky," they almost certainly want Husky configured—the "maybe" reflects conversational politeness or uncertainty about whether it's the right tool, not genuine indifference to the outcome. PDE captures this as a secondary intent with a confidence annotation, ensuring it is not dropped during execution.
128
+
129
+ ### The Decomposition Result Schema
130
+
131
+ PDE produces a structured `DecompositionResult` object:
132
+
133
+ ```typescript
134
+ interface DecompositionResult {
135
+ id: string;
136
+ timestamp: string;
137
+ originalPrompt: string;
138
+ primaryIntents: Intent[];
139
+ secondaryIntents: Intent[];
140
+ implicitIntents: Intent[];
141
+ contextRequirements: ContextRequirement[];
142
+ dependencies: Dependency[];
143
+ fourDirectionsStack: {
144
+ east: ActionItem[]; // Vision
145
+ south: ActionItem[]; // Analysis
146
+ west: ActionItem[]; // Implementation
147
+ north: ActionItem[]; // Integration
148
+ };
149
+ ambiguityFlags: AmbiguityFlag[];
150
+ }
151
+ ```
152
+
153
+ This schema is serialized as JSON and stored in a `.pde/` directory alongside the project, creating a persistent record of prompt decompositions that can be reviewed, edited, and versioned.
154
+
155
+ ### PDE as Completeness Safeguard
156
+
157
+ The primary value proposition of PDE is not sophistication but **completeness.** In multi-mission agent sessions where a single prompt may contain dozens of intents spanning multiple domains, the risk of intent loss is the primary failure mode. PDE functions as a safeguard against this loss—a systematic check that everything the user asked for has been identified before execution begins.
158
+
159
+ This is particularly critical in voice-transcription handoff scenarios, where speech-to-text produces raw verbatim text with conversational hedging, tangential asides, and implicit assumptions that text-based prompts typically refine away.
160
+
161
+ ## Implications for CoAiA.js
162
+
163
+ PDE is the entry point of the CoAiA.js agent pipeline:
164
+
165
+ 1. **Session start decomposition.** Every agent session begins with PDE decomposition of the user's initial prompt, ensuring no intents are lost before work begins.
166
+ 2. **Structural tension chart generation.** PDE's output feeds directly into STC creation—primary intents become desired outcomes, current reality is assessed, and action steps are populated from the Four Directions stack.
167
+ 3. **MMOT completeness checks.** During evaluation, agents verify that all extracted intents (including secondary and implicit) have been addressed, using PDE's output as the completeness checklist.
168
+ 4. **Version-controlled decompositions.** PDE results stored in `.pde/` directories provide audit trails showing exactly how complex prompts were interpreted.
169
+ 5. **MCP integration.** The PDE engine is exposed as an MCP tool, enabling any MCP-compliant host to decompose prompts using the same methodology.
170
+
171
+ ## Conclusion
172
+
173
+ Prompt Decomposition Engineering addresses a fundamental gap in the prompt engineering landscape: the completeness of intent extraction from complex, multi-intent prompts. By operating on the input prompt rather than the reasoning process, PDE complements existing strategies (CoT, ToT, DecomP) while solving a distinct problem. The methodology's systematic extraction of primary, secondary, and implicit intents—combined with dependency mapping and Four Directions organization—provides the completeness safeguard that complex agent sessions require.
174
+
175
+ ## References
176
+
177
+ 1. LearnPrompting. (2024). "Advanced Decomposition Techniques for Improved Prompting in LLMs." https://learnprompting.org/docs/advanced/decomposition/introduction
178
+ 2. Wei, J., et al. (2022). "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models." *NeurIPS 2022*.
179
+ 3. Yao, S., et al. (2023). "Tree of Thoughts: Deliberate Problem Solving with Large Language Models." *NeurIPS 2023*.
180
+ 4. Wang, X., et al. (2022). "Self-Consistency Improves Chain of Thought Reasoning in Language Models." *ICLR 2023*.
181
+ 5. Khot, T., et al. (2022). "Decomposed Prompting: A Modular Approach for Solving Complex Tasks." *ICLR 2023*.
182
+ 6. Wang, L., et al. (2023). "Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning." *ACL 2023*.
183
+ 7. Oxen.ai. (2024). "The Prompt Report Part 2: Plan and Solve, Tree of Thought, and Decomposition Prompting." https://ghost.oxen.ai/the-prompt-report-part-2-thought-generation-tree-of-thought-and-decomposition-prompting/
184
+ 8. CalmOps. (2024). "Prompt Engineering Patterns: CoT, ReAct, and ToT." https://calmops.com/ai/prompt-engineering-patterns-cot-react-tot/
185
+ 9. Exploratio Journal. (2024). "Zooming-in On Prompting: A Comparative Study." https://exploratiojournal.com/zooming-in-on-prompting/
186
+ 10. Coupler.io. (2024). "Advanced Prompting Techniques for Complex AI Reasoning." https://blog.coupler.io/advanced-prompting-techniques/
@@ -0,0 +1,134 @@
1
+ # Structural Tension in AI Agents: Robert Fritz's Methodology Applied to Autonomous Goal Management
2
+
3
+ > Academic brief for the CoAiA.js project — Structural tension charts as computational data structures for tracking desired outcomes versus current reality in autonomous AI agent systems.
4
+
5
+ ## Abstract
6
+
7
+ Autonomous AI agents face a fundamental challenge: maintaining coherent progress toward goals while continuously adapting to evolving environments. This paper examines how Robert Fritz's structural tension methodology—originally developed for human creative processes—can be formalized as a computational framework for AI agent goal management. We define structural tension charts (STCs) as first-class data structures encoding the gap between a desired outcome and an assessed current reality, with tension resolution driving agent behavior. Unlike traditional goal-stack or utility-maximization approaches, structural tension provides a creative orientation that sustains forward momentum without the oscillatory patterns characteristic of problem-solving architectures. We analyze the formal properties of STCs, their implementation as JSONL-backed state machines, and their implications for agent autonomy, self-correction, and telescoping goal decomposition. The framework is evaluated in the context of CoAiA.js, a JavaScript runtime for structurally-tensioned AI agents.
8
+
9
+ ## Introduction
10
+
11
+ The design of AI agent goal management systems has historically drawn from planning literature (STRIPS, HTN), reinforcement learning (reward maximization), and behavioral architectures (subsumption, BDI). While these approaches have proven effective in constrained domains, they share a common structural limitation: they are fundamentally problem-solving architectures, oriented toward the elimination of undesirable states rather than the creation of desired ones.
12
+
13
+ Robert Fritz, in *The Path of Least Resistance* (1989) and *Creating* (1991), identified a critical distinction between two orientations toward action. Problem-solving orientation generates energy by moving away from what is unwanted; creative orientation generates energy by moving toward what is desired. Fritz demonstrated that problem-solving architectures produce oscillatory dynamics—as the problem diminishes, so does motivation, leading to cyclical regression. Creative orientation, by contrast, produces advancing dynamics through structural tension: the sustained gap between a clearly articulated desired outcome and an honestly assessed current reality [1].
14
+
15
+ This paper formalizes structural tension as a computational construct for AI agent systems. We argue that encoding desired outcomes and current reality as co-evolving data structures—with the tension between them as the primary driver of agent behavior—produces agents with superior goal coherence, self-correction capabilities, and resistance to the oscillatory patterns that plague reactive architectures.
16
+
17
+ ## Background
18
+
19
+ ### Fritz's Structural Tension Model
20
+
21
+ The structural tension model rests on three axioms:
22
+
23
+ 1. **Tension seeks resolution.** A system with a gap between desired outcome and current reality will tend toward resolution of that gap, following the path of least resistance.
24
+ 2. **The path of least resistance is determined by underlying structure.** The arrangement of elements in a system determines how tension resolves—whether through advancement toward the desired outcome or oscillation between states.
25
+ 3. **Creative orientation produces advancing structures.** When the desired outcome is held constant and current reality is honestly assessed, tension resolves through advancement. When the problem is the primary reference point, tension resolves through oscillation [1][2].
26
+
27
+ Fritz's methodology requires practitioners to: (a) clearly articulate what they want to create, (b) honestly assess current reality relative to that vision, and (c) hold both simultaneously, allowing the structural tension to drive action [3].
28
+
29
+ ### Existing Agent Goal Architectures
30
+
31
+ Traditional agent architectures encode goals in several ways:
32
+
33
+ - **Goal stacks** (STRIPS/PDDL): Goals as predicate conditions to satisfy. No notion of ongoing tension; goals are binary (achieved/not achieved).
34
+ - **Utility functions** (RL/MDPs): Goals as reward signals to maximize. Susceptible to reward hacking and lacks semantic richness.
35
+ - **BDI architectures**: Beliefs-Desires-Intentions model maintains goal hierarchies but lacks the structural tension dynamic that prevents oscillation.
36
+ - **Behavior trees**: Reactive architectures that respond to conditions without maintaining creative tension toward outcomes [4].
37
+
38
+ None of these architectures encode the dual-reference-point structure (desired outcome + current reality) that Fritz identifies as essential for sustained creative advancement.
39
+
40
+ ## Analysis
41
+
42
+ ### Structural Tension Charts as Data Structures
43
+
44
+ We define a Structural Tension Chart (STC) as a tuple:
45
+
46
+ ```
47
+ STC = (D, R, A[], T, Δ)
48
+ ```
49
+
50
+ Where:
51
+ - **D** (Desired Outcome): A natural-language description of the target state, held constant unless explicitly revised.
52
+ - **R** (Current Reality): A timestamped, append-only log of observations about the present state. Critically, R must be an honest assessment—not a readiness statement or aspiration.
53
+ - **A[]** (Action Steps): An ordered set of intermediate goals, each of which is itself a telescoped STC.
54
+ - **T** (Tension): The computed gap between D and R, which drives agent decision-making.
55
+ - **Δ** (Delta History): A temporal record of reality updates, enabling the agent to assess whether it is advancing or oscillating.
56
+
57
+ The key innovation is that **tension is not a problem to solve but a creative force to harness**. The agent does not minimize a loss function; it moves toward a desired creation while continuously updating its understanding of reality.
58
+
59
+ ### Telescoping: Recursive Goal Decomposition
60
+
61
+ A critical feature of structural tension methodology is telescoping—the ability to decompose any action step into its own full STC. This creates a recursive hierarchy:
62
+
63
+ ```
64
+ Master STC
65
+ ├── Action Step 1 → Telescoped STC₁
66
+ │ ├── Sub-action 1a → Telescoped STC₁ₐ
67
+ │ └── Sub-action 1b → Telescoped STC₁ᵦ
68
+ ├── Action Step 2 → Telescoped STC₂
69
+ └── Action Step 3 → Telescoped STC₃
70
+ ```
71
+
72
+ Each telescoped STC maintains its own desired outcome, current reality, and tension. This structure enables agents to work at multiple levels of abstraction simultaneously, focusing on immediate sub-tasks while maintaining alignment with higher-level creative intent.
73
+
74
+ ### Preventing Oscillation: The Structural Advantage
75
+
76
+ Fritz observed that problem-solving systems oscillate because their energy source (the problem) diminishes as progress is made. In computational terms, a reward-minimization agent that reduces error from 0.8 to 0.2 experiences diminishing gradient—the "problem" is mostly "solved," and momentum collapses.
77
+
78
+ Structural tension charts prevent this because:
79
+
80
+ 1. **The desired outcome remains constant.** The vision does not diminish as reality improves.
81
+ 2. **Current reality is continuously re-assessed.** New observations may reveal previously unknown gaps, maintaining or even increasing tension.
82
+ 3. **Completion is binary and explicit.** An action step is marked complete through deliberate assessment (the Managerial Moment of Truth), not through gradient convergence.
83
+
84
+ ### Implementation: JSONL-Backed State Machines
85
+
86
+ In the CoAiA.js implementation, STCs are stored as append-only JSONL (JSON Lines) records:
87
+
88
+ ```jsonl
89
+ {"type":"chart","id":"chart_001","desiredOutcome":"Production-ready MCP server","currentReality":"Prototype exists with 3 tools; no tests, no error handling","createdAt":"2026-03-10T14:00:00Z"}
90
+ {"type":"action","chartId":"chart_001","name":"chart_001_action_1","title":"Implement error handling","currentReality":"No try-catch patterns; errors crash the process"}
91
+ {"type":"reality_update","chartId":"chart_001","observation":"Added error boundaries to tool dispatch; 2 of 5 tools now handle errors gracefully","timestamp":"2026-03-10T16:30:00Z"}
92
+ {"type":"completion","actionName":"chart_001_action_1","timestamp":"2026-03-10T18:00:00Z"}
93
+ ```
94
+
95
+ The append-only format ensures that no historical state is lost—every observation, update, and completion is preserved. This enables temporal analysis of tension dynamics: is the agent advancing, oscillating, or stalled?
96
+
97
+ ### Tension as Agent Decision Driver
98
+
99
+ Rather than selecting actions through utility maximization or plan execution, a structurally-tensioned agent operates through the following cycle:
100
+
101
+ 1. **Assess tension:** Compare desired outcome against current reality across all active STCs.
102
+ 2. **Select highest-tension chart:** The STC with the greatest gap between D and R receives attention.
103
+ 3. **Identify next action:** Within the selected chart, find the next incomplete action step.
104
+ 4. **Execute and observe:** Perform the action and update current reality with honest observations.
105
+ 5. **Evaluate via MMOT:** Apply the Managerial Moment of Truth to assess whether the action advanced the chart or revealed new gaps.
106
+
107
+ This cycle naturally produces depth-first progress on high-priority goals while enabling context switching when new information shifts the tension landscape.
108
+
109
+ ## Implications for CoAiA.js
110
+
111
+ CoAiA.js implements structural tension charts as its primary goal management primitive. The implications are:
112
+
113
+ 1. **Agent sessions are organized around STCs**, not task lists. Every agent session begins with chart creation—articulating a desired outcome and honestly assessing current reality.
114
+ 2. **Progress is measured by reality advancement**, not task completion counts. An agent that completes 10 tasks but fails to advance current reality toward the desired outcome has not made meaningful progress.
115
+ 3. **Telescoping enables multi-scale operation.** Agents can decompose complex goals into nested STCs, each maintaining its own tension dynamics, while the master chart provides coherence.
116
+ 4. **JSONL storage provides full auditability.** Every decision, observation, and completion is recorded, enabling post-hoc analysis of agent behavior and tension dynamics.
117
+ 5. **The MMOT cycle provides self-correction.** Agents can detect oscillation by analyzing their Δ history and adjust their approach when advancement stalls.
118
+
119
+ ## Conclusion
120
+
121
+ Structural tension charts offer a fundamentally different paradigm for AI agent goal management—one rooted in creative orientation rather than problem-solving. By encoding the gap between desired outcomes and current reality as a first-class data structure, and by driving agent behavior through tension resolution rather than reward maximization, we obtain agents that advance coherently toward creative goals without the oscillatory dynamics that plague reactive architectures. The formalization presented here provides a foundation for building AI systems that create rather than merely optimize.
122
+
123
+ ## References
124
+
125
+ 1. Fritz, R. (1989). *The Path of Least Resistance: Learning to Become the Creative Force in Your Own Life*. Fawcett Columbine.
126
+ 2. Fritz, R. (1999). *The Path of Least Resistance for Managers*. Berrett-Koehler Publishers.
127
+ 3. Foss, L. "Structural Tension Model." https://www.larafoss.com/structural-tension
128
+ 4. Wooldridge, M. (2009). *An Introduction to MultiAgent Systems*. 2nd ed. Wiley.
129
+ 5. Fritz, R. "Tension Seeks Resolution." Robert Fritz Inc. https://www.robertfritz.com/wp/principles/tension-seeks-resolution/
130
+ 6. Think-2-Thrive. (2024). "Leading with Creative Tension." https://think-2-thrive.com/2024/12/02/blog-55-leading-with-creative-tension/
131
+ 7. Thwink.org. "Structural Tension." https://www.thwink.org/soft/info/process/structural/StructuralTension.html
132
+ 8. Senge, P. (1990). *The Fifth Discipline: The Art & Practice of the Learning Organization*. Doubleday.
133
+ 9. Rao, A. S., & Georgeff, M. P. (1995). "BDI Agents: From Theory to Practice." *Proceedings of the First International Conference on Multi-Agent Systems (ICMAS-95)*.
134
+ 10. Fritz, R., & Bodaken, B. (2006). *The Managerial Moment of Truth*. Free Press.