dir-core 0.1.0__tar.gz

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 (57) hide show
  1. dir_core-0.1.0/LICENSE +201 -0
  2. dir_core-0.1.0/PKG-INFO +281 -0
  3. dir_core-0.1.0/README.md +239 -0
  4. dir_core-0.1.0/pyproject.toml +85 -0
  5. dir_core-0.1.0/setup.cfg +4 -0
  6. dir_core-0.1.0/src/dir_core/__init__.py +270 -0
  7. dir_core-0.1.0/src/dir_core/agent_registry.py +209 -0
  8. dir_core-0.1.0/src/dir_core/arbitration.py +53 -0
  9. dir_core-0.1.0/src/dir_core/context_store.py +110 -0
  10. dir_core-0.1.0/src/dir_core/data_types.py +121 -0
  11. dir_core-0.1.0/src/dir_core/dfid.py +27 -0
  12. dir_core-0.1.0/src/dir_core/dim.py +112 -0
  13. dir_core-0.1.0/src/dir_core/escalation.py +178 -0
  14. dir_core-0.1.0/src/dir_core/event_bus.py +272 -0
  15. dir_core-0.1.0/src/dir_core/idempotency.py +81 -0
  16. dir_core-0.1.0/src/dir_core/intent_retry.py +64 -0
  17. dir_core-0.1.0/src/dir_core/jit.py +96 -0
  18. dir_core-0.1.0/src/dir_core/ledger.py +44 -0
  19. dir_core-0.1.0/src/dir_core/lifecycle.py +61 -0
  20. dir_core-0.1.0/src/dir_core/models.py +466 -0
  21. dir_core-0.1.0/src/dir_core/pci.py +98 -0
  22. dir_core-0.1.0/src/dir_core/resource_lock.py +116 -0
  23. dir_core-0.1.0/src/dir_core/runtime.py +135 -0
  24. dir_core-0.1.0/src/dir_core/saga.py +142 -0
  25. dir_core-0.1.0/src/dir_core/storage/__init__.py +171 -0
  26. dir_core-0.1.0/src/dir_core/storage/base.py +369 -0
  27. dir_core-0.1.0/src/dir_core/storage/json_util.py +22 -0
  28. dir_core-0.1.0/src/dir_core/storage/memory.py +365 -0
  29. dir_core-0.1.0/src/dir_core/storage/schema.sql +256 -0
  30. dir_core-0.1.0/src/dir_core/storage/sqlite.py +640 -0
  31. dir_core-0.1.0/src/dir_core/utils/__init__.py +18 -0
  32. dir_core-0.1.0/src/dir_core/utils/llm_client.py +16 -0
  33. dir_core-0.1.0/src/dir_core/utils/logging_utils.py +27 -0
  34. dir_core-0.1.0/src/dir_core/wakeup.py +63 -0
  35. dir_core-0.1.0/src/dir_core.egg-info/PKG-INFO +281 -0
  36. dir_core-0.1.0/src/dir_core.egg-info/SOURCES.txt +55 -0
  37. dir_core-0.1.0/src/dir_core.egg-info/dependency_links.txt +1 -0
  38. dir_core-0.1.0/src/dir_core.egg-info/requires.txt +26 -0
  39. dir_core-0.1.0/src/dir_core.egg-info/top_level.txt +1 -0
  40. dir_core-0.1.0/tests/test_agent_registry.py +70 -0
  41. dir_core-0.1.0/tests/test_arbitration.py +42 -0
  42. dir_core-0.1.0/tests/test_context_store.py +64 -0
  43. dir_core-0.1.0/tests/test_dfid.py +22 -0
  44. dir_core-0.1.0/tests/test_dim_ttl.py +147 -0
  45. dir_core-0.1.0/tests/test_escalation.py +117 -0
  46. dir_core-0.1.0/tests/test_event_bus.py +167 -0
  47. dir_core-0.1.0/tests/test_idempotency.py +43 -0
  48. dir_core-0.1.0/tests/test_intent_retry.py +63 -0
  49. dir_core-0.1.0/tests/test_jit.py +65 -0
  50. dir_core-0.1.0/tests/test_ledger.py +52 -0
  51. dir_core-0.1.0/tests/test_lifecycle.py +112 -0
  52. dir_core-0.1.0/tests/test_ollama.py +61 -0
  53. dir_core-0.1.0/tests/test_pci.py +76 -0
  54. dir_core-0.1.0/tests/test_resource_lock.py +53 -0
  55. dir_core-0.1.0/tests/test_runtime.py +85 -0
  56. dir_core-0.1.0/tests/test_saga.py +89 -0
  57. dir_core-0.1.0/tests/test_wakeup.py +56 -0
dir_core-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Artur Huk
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,281 @@
1
+ Metadata-Version: 2.4
2
+ Name: dir-core
3
+ Version: 0.1.0
4
+ Summary: Decision Intelligence Runtime - deterministic Kernel Space for agentic AI
5
+ Author: Artur Huk
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/huka81/decision-intelligence-runtime
8
+ Project-URL: Repository, https://github.com/huka81/decision-intelligence-runtime
9
+ Project-URL: Issues, https://github.com/huka81/decision-intelligence-runtime/issues
10
+ Keywords: ai,agents,decision-intelligence,roa,dir,llm,governance
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Topic :: Security
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: pydantic>=2.0
22
+ Requires-Dist: structlog>=24.1.0
23
+ Requires-Dist: PyYAML>=6.0
24
+ Provides-Extra: sqlite
25
+ Provides-Extra: postgres
26
+ Requires-Dist: psycopg[binary]>=3.1; extra == "postgres"
27
+ Provides-Extra: asyncpg
28
+ Requires-Dist: asyncpg>=0.29; extra == "asyncpg"
29
+ Provides-Extra: frameworks
30
+ Requires-Dist: langchain-core; extra == "frameworks"
31
+ Requires-Dist: crewai; extra == "frameworks"
32
+ Provides-Extra: samples
33
+ Requires-Dist: markdown>=3.5; extra == "samples"
34
+ Requires-Dist: httpx; extra == "samples"
35
+ Requires-Dist: plotly; extra == "samples"
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=7; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4; extra == "dev"
39
+ Requires-Dist: ruff>=0.3.0; extra == "dev"
40
+ Requires-Dist: mypy>=1.8; extra == "dev"
41
+ Dynamic: license-file
42
+
43
+ # Decision Intelligence Runtime (DIR)
44
+
45
+ **An architectural framework for building reliable, accountable, and stateful AI decision systems.**
46
+
47
+ ![Responsibility-Oriented Agents](./assets/images/2_dir_roa_scratch.png)
48
+
49
+ ## Project Goal
50
+
51
+ Current "agent frameworks" treat Large Language Models (LLMs) as autonomous executors, resulting in non-deterministic behaviors, hallucinations in critical control paths, and insufficient accountability mechanisms.
52
+
53
+ **Decision Intelligence Runtime** addresses this by enforcing a strict separation between **Reasoning** (LLM-based, semantic, probabilistic) and **Execution** (code-based, deterministic, verifiable). This separation is implemented through a Kernel Space / User Space architectural boundary, inspired by operating system design principles.
54
+
55
+ Unlike purely theoretical frameworks, DIR provides a concrete, executable implementation of safe delegation patterns.
56
+
57
+ ### Origins
58
+
59
+ DIR emerged from production constraints in the **AIvestor** automated trading system, where the cost of reasoning failures is measured in capital loss. The patterns documented here are not theoretical-they represent battle-tested solutions to "Day Two" failure modes: state drift, non-idempotent operations, TOCTOU vulnerabilities, and the collapse of accountability in multi-agent systems.
60
+
61
+ This repository contains the architectural concepts, formal specifications, and reference implementations of the DIR framework.
62
+
63
+ ---
64
+
65
+ ## Architectural Convergence & Validation
66
+
67
+ The publication of *Intelligent AI Delegation* by Google DeepMind (February 2026, arXiv:2602.11865) confirms the architectural direction we have been developing since early 2025. Their formalization of "Responsibility Transfer," "Auditability," and "Permission Handling" as fundamental requirements for agentic systems aligns with the patterns we have been validating in production environments.
68
+
69
+ The independent convergence is notable:
70
+
71
+ * **Google's "Responsibility Transfer"** ≈ **ROA Responsibility Contracts**
72
+ * **Google's "Auditability"** ≈ **DecisionFlow ID (DFID)**
73
+ * **Google's "Permission Handling"** ≈ **Decision Integrity Module (DIM)**
74
+
75
+ This alignment reinforces that these patterns are not vendor-specific abstractions-they are architectural necessities for production-grade agentic systems.
76
+
77
+ ### Industry Validation: Google DeepMind vs. DIR Implementation
78
+
79
+ While Google's *Intelligent AI Delegation* (2026) outlines the *theoretical* requirements for safe agentic systems, **DIR provides the open-source architectural implementation available today.**
80
+
81
+ | Requirement (Google DeepMind) | DIR Implementation (This Repo) | Status |
82
+ | :--- | :--- | :--- |
83
+ | **Verifiable Task Completion** | **Topology C (DL+PCI)** <br> *Cryptographic Proof-Carrying Intents* | ✅ Implemented |
84
+ | **Transfer of Authority** | **Responsibility Contracts** <br> *Machine-readable scope definitions* | ✅ Implemented |
85
+ | **Permission Handling** | **Kernel Space (DIM)** <br> *Deterministic policy enforcement* | ✅ Implemented |
86
+ | **Structural Transparency** | **DecisionFlow ID (DFID)** <br> *End-to-end distributed tracing* | ✅ Implemented |
87
+
88
+
89
+ **[Read the full framework comparison: Google DeepMind vs. DIR/ROA](./docs/00-introduction/Intelligent_Delegation_Framework_Mapping.md)**
90
+
91
+ ---
92
+
93
+ ## Quick Start
94
+
95
+ The fastest way to see the DIR architecture in action:
96
+
97
+ ```bash
98
+ pip install -e .
99
+ python samples/00_quick_start/run.py
100
+ ```
101
+
102
+ This sample demonstrates protection against catastrophic actions (e.g. parsing error turning 15.5 ETH into 15,500 ETH) and prompt injection in external data. High-level overview of the full architecture. See [samples/00_quick_start](samples/00_quick_start/README.md).
103
+
104
+ ---
105
+
106
+ ## Start Here
107
+
108
+ If you are new to DIR/ROA, begin with the introduction article. It explains the core motivation ("Day Two" failures in production systems), the Kernel Space vs. User Space architectural boundary, and why traditional agentic loops are insufficient for high-stakes environments.
109
+
110
+ **[Read: Beyond Prompt Engineering - Building a Deterministic Runtime for Responsible AI Agents](./docs/00-introduction/DIR-introduction.md)**
111
+
112
+ ## Why use DIR today?
113
+
114
+ Big Tech providers are beginning to theorize about "Agent Runtimes" as proprietary cloud services. **DIR is the first open-source implementation of the Zero Trust Agents philosophy** - agents propose, the runtime verifies; no implicit trust in LLM output.
115
+
116
+ * **No Vendor Lock-in:** Run your agents on AWS, Azure, GCP, or on-premise. The runtime logic is yours.
117
+ * **Ready for Production:** Solves "Day Two" problems (loops, drifts, audit) that simple orchestration libraries ignore.
118
+ * **Works with Existing Frameworks:** DIR is not a competitor to LangChain, AutoGen, or LangGraph - it's the execution shell. Wrap task-oriented agents in ROA contracts, inject mission boundaries, and enforce deterministic validation. *(See: [34_langchain_roa_wrapper](samples/34_langchain_roa_wrapper/), [35_crewai_roa_wrapper](samples/35_crewai_roa_wrapper/))*
119
+ * **Language Agnostic Architecture:** While the reference implementation is Python, the patterns (Kernel/User separation, DFID) are universal.
120
+ * **Context as Code:** Documentation is the new compiler - Markdown files act as system prompts for AI agents. *([Context as Code](./docs/08-conclusion/Context_as_Code.md))*
121
+
122
+ ## Core Concepts
123
+
124
+ ### 1. Responsibility-Oriented Agents (ROA)
125
+ *Current Status: Published*
126
+
127
+ ROA is the architectural pattern for agents themselves. Instead of open-ended control loops, ROA constrains agents through explicit contracts:
128
+ * **Responsibility Contracts:** Formal scope boundaries and authority limits.
129
+ * **Missions:** Explicit optimization objectives defining agent purpose.
130
+ * **Stateful Existence:** Long-lived memory and persistent identity.
131
+ * **Decision Lifecycle:** Explain → Policy → Proposal (strict separation of reasoning from execution).
132
+
133
+ **[Read the ROA Manifesto](./docs/01-roa-manifesto/ROA_Manifesto.md)**
134
+
135
+ ### 2. The Runtime Architecture
136
+ *Current Status: Published*
137
+
138
+ The execution environment that enforces deterministic guarantees:
139
+ * **Decision Integrity Module (DIM):** Kernel-space validation layer (schema enforcement, RBAC, state consistency checks).
140
+ * **Context Compilation:** Immutable state snapshots preventing TOCTOU vulnerabilities.
141
+ * **DecisionFlow ID (DFID):** Distributed tracing for reasoning chain reconstruction.
142
+ * **Safety Invariants:** Idempotency guarantees, TTL enforcement, and escalation protocols.
143
+
144
+ **[Read the DIR Architectural Pattern](./docs/02-decision-runtime/DIR_Architectural_Pattern.md)**
145
+
146
+ ### 3. Decision Intelligence Topologies
147
+ *Current Status: Work in Progress*
148
+
149
+ A pluralistic approach to agent orchestration. No single execution model satisfies all operational requirements. DIR defines three distinct topologies optimized for different constraint profiles:
150
+ * **Topology A (EOAM):** Event-Oriented Agent Mesh for decentralized strategy coordination.
151
+ * **Topology B (SDS):** Structural Decision Streams for high-velocity, grammar-constrained execution.
152
+ * **Topology C (DL+PCI):** Decision Ledger with Proof-Carrying Intents for cryptographically verifiable audit trails.
153
+
154
+ **[Read Decision Intelligence Topologies](./docs/03-topologies/DIR_Topologies.md)**
155
+
156
+ ### 4. Post-Execution Governance & Drift
157
+ *Current Status: Work in Progress*
158
+
159
+ An architectural defense against "Day Three" problems, where an agent's individual decisions are technically valid (Kernel Compliance), but its aggregate behavior over time erodes business intent (Business Health).
160
+ * **Agent Drift Taxonomy:** Formal classification of Optimization (Reward Hacking), Semantic, and Environmental drift.
161
+ * **Rolling Window Monitors:** Asynchronous analysis of execution logs and context snapshots linked via DFID.
162
+ * **Circuit Breaking:** Automated mechanism to transition an agent's Registry status to `SUSPENDED` upon detecting statistically significant drift.
163
+
164
+ **[Read Governance & Agent Drift](./docs/04-governance/DIR_Governance.md)**
165
+
166
+ ---
167
+
168
+ # Getting Started
169
+
170
+ ## Prerequisites
171
+ - **Python 3.12+**
172
+ - **SQLite3** (optional - only for samples that use persistent storage)
173
+ - **Ollama** (optional - for local LLM inference in samples such as `31_finance_trading`; use `USE_MOCK_LLM=1` to run without it)
174
+
175
+ ## Installation
176
+
177
+ 1. Clone the repository.
178
+ 2. Install the package in editable mode:
179
+
180
+ ```bash
181
+ pip install -e .
182
+ ```
183
+ *This installs the `dir_core` package (source in `src/dir_core`), making it available to all sample implementations.*
184
+
185
+ ## Repository Structure
186
+
187
+ ```text
188
+ decision-intelligence-runtime/
189
+ ├── README.md
190
+ ├── FAQ.md # Frequently asked questions (architecture, adoption, compliance)
191
+ ├── pyproject.toml # pip install -e . installs dir_core (incl. dir_core.utils for samples)
192
+ ├── requirements.txt # Shared dependencies
193
+ ├── src/
194
+ │ └── dir_core/ # Core DIR/ROA components (per docs spec)
195
+ │ # DFID, EventBus, DIM, Context Store, models, arbitration, PCI, etc.
196
+ │ └── utils/ # Supporting utilities for samples
197
+ │ # logging_utils, config_loader, llm_client (synthetic market: samples/31_finance_trading/mocks/)
198
+ ├── samples/ # Reference implementations (01–11 mechanics, 31+ use cases)
199
+ │ ├── README.md # Sample catalog and run instructions
200
+ │ ├── 00_quick_start/ … 08_custom_repo_psql/ … 11_topology_c_dl_pci/
201
+ │ ├── 31_finance_trading/ … 35_crewai_roa_wrapper/ … 36_drift_optimization_discount/ … 37_drift_semantic_refund/ … 38_drift_environmental_bidding/
202
+ │ └── 88_meta_context_engineering/ # Meta-sample: System Prompt Toolkit
203
+ ├── docs/ # Architectural documentation
204
+ │ ├── 00-introduction/ # DIR intro, framework mapping
205
+ │ ├── 01-roa-manifesto/
206
+ │ ├── 02-decision-runtime/
207
+ │ ├── 03-topologies/
208
+ │ ├── 07-dir-minified/ # Machine-optimized single-file spec (DIR-minified.md)
209
+ │ └── 08-conclusion/ # Context as Code concept
210
+ └── assets/ # Images, diagrams
211
+ ```
212
+
213
+ ## Samples & Reference Implementations
214
+
215
+ Execute any sample from the repository root: `python samples/<folder>/run.py`
216
+
217
+ *Full list and details: [samples/README.md](samples/README.md)*
218
+
219
+ ### Mechanics & Topologies (00–11)
220
+
221
+ | # | Sample | Focus | Description |
222
+ |---|--------|-------|--------------|
223
+ | 00 | `00_quick_start` | Quick Start | High-level overview: comma catastrophe, prompt injection |
224
+ | 01 | `01_roa_agent` | ROA Manifesto | Contract, Explain → Policy → Proposal |
225
+ | 02 | `02_dfid_propagation` | DIR Pattern | DecisionFlow ID: generation, propagation, logging |
226
+ | 03 | `03_idempotency_guard` | DIR Pattern | Idempotency: preventing duplicate side effects |
227
+ | 04 | `04_context_store` | DIR Pattern | 4 Layers of Context: Session, State, Memory, Artifacts |
228
+ | 05 | `05_dim_validation` | DIR Pattern | Decision Integrity Module: deterministic validation gate |
229
+ | 06 | `06_agent_registry` | DIR Pattern | Agent Registry: manifests and capability handshake |
230
+ | 07 | `07_event_bus_swappable` | Infrastructure | In-memory Event Bus; note on swapping for Kafka/PubSub |
231
+ | 08 | `08_custom_repo_psql` | Infrastructure | **PostgreSQL `StorageBundle`**: `setup_environment` with `database.provider: postgres` and env `DB_*`; minimal classic ROA + DIM run so audit and context land in the shared PostgreSQL adapter. See [sample README](samples/08_custom_repo_psql/README.md). |
232
+ | 09 | `09_topology_a_eoam` | Topology A | Event-Oriented Agent Mesh |
233
+ | 10 | `10_topology_b_sds` | Topology B | Sovereign Decision Stream |
234
+ | 11 | `11_topology_c_dl_pci` | Topology C | Decision Ledger & Proof-Carrying Intents |
235
+ | 88 | `88_meta_context_engineering` | Meta-Sample | **Travel/insurance**: System Prompt Toolkit. Domain: flight delay refunds. Generates Flight Delay Refund System (Topology C). |
236
+
237
+ ### Business Use Cases (31+)
238
+
239
+ | # | Sample | Domain | What it checks |
240
+ |---|--------|--------|----------------|
241
+ | 31 | `31_finance_trading` | **Finance/trading** | Market quotes, news, parallel agents; position spawning and execution. **(Topology: EOAM)** |
242
+ | 32 | `32_fraud_gate` | **Fraud detection** | YAML-driven fraud gate: ROA, DIM, JIT drift via `verify_drift`, StorageBundle audit, mock settlement idempotency. **(Topology: classic + scenarios)** |
243
+ | 33 | `33_insurance_underwriting` | **Insurance underwriting** | Risk evaluation with cryptographic Proof-Carrying Intents (PCI). **(Topology: DL+PCI)** |
244
+ | 34 | `34_langchain_roa_wrapper` | **FinOps** | LangChain ReAct → ROA. Cloud cost management. Verifies mission injection blocks PROD termination. |
245
+ | 35 | `35_crewai_roa_wrapper` | **Customer claims/refunds** | CrewAI Crew → ROA. E-commerce refunds (EUR). Verifies ACCEPT/ESCALATE/REJECT by category, return window, amount; NL intake. |
246
+ | 36 | `36_drift_optimization_discount` | **Retention discounts** | Optimization drift (reward hacking): agent offers discounts within DIM hard cap but profitability decays in aggregate. PerformanceMonitor detects rolling-average breach and suspends the agent. Shows that **kernel compliance ≠ business health**. *(See [Governance & Drift](./docs/04-governance/DIR_Governance.md))* |
247
+ | 37 | `37_drift_semantic_refund` | **Support refunds** | Semantic drift (emotional manipulation): refunds stay under a EUR cap so DIM accepts, but the delay policy is violated. ComplianceMonitor uses rolling `REFUND_EXECUTED` telemetry (`delay_hours` in audit details) and suspends when the semantic violation rate exceeds the threshold. *(See [Governance & Drift](./docs/04-governance/DIR_Governance.md))* |
248
+ | 38 | `38_drift_environmental_bidding` | **AdTech / bidding** | Environmental drift: market CPC escalates; bids stay under a contract cap so DIM accepts, but rolling average CPC exceeds LTV. BusinessROIMonitor joins `execution_log` to `market_snapshots` and suspends after consecutive negative ROI cycles. *(See [Governance & Drift](./docs/04-governance/DIR_Governance.md))* |
249
+
250
+ ---
251
+ ## Documentation
252
+
253
+ - **[DIR Introduction](./docs/00-introduction/DIR-introduction.md)** - Architectural motivation and Kernel Space / User Space boundary.
254
+ - **[ROA Manifesto](./docs/01-roa-manifesto/ROA_Manifesto.md)** - Responsibility-oriented agent design.
255
+ - **[DIR Architecture](./docs/02-decision-runtime/DIR_Architectural_Pattern.md)** - Runtime components and invariants.
256
+ - **[Topologies](./docs/03-topologies/DIR_Topologies.md)** - Operational modes (EOAM, SDS, DL+PCI).
257
+ - **[Governance & Drift](./docs/04-governance/DIR_Governance.md)** - Managing aggregate safety and business health over time.
258
+ - **[Context as Code](./docs/08-conclusion/Context_as_Code.md)** - Treating documentation as a system prompt.
259
+ - **[FAQ](./FAQ.md)** - Answers to common engineering questions about DIR/ROA: "Day Two" failure modes, Kernel vs User Space, comparison with orchestration frameworks, JIT state verification, idempotency, compliance (e.g. EU AI Act and Proof-Carrying Intents), and incremental adoption.
260
+
261
+
262
+ ### Machine-optimized specification: DIR-minified.md
263
+
264
+ **[DIR-minified](./docs/07-dir-minified/DIR-minified.md)** is a **single-file, machine-optimized** version of the framework specification. It is intended **for use as context** by LLMs and code-generation agents (e.g. Cursor, Claude, Devin), not as primary reading for humans.
265
+
266
+ The document is intentionally **radical** (dense, exhaustive) and **redundant** (repeats key constraints and examples in multiple places) so that a model loading it as context has a complete, self-contained picture of ROA, DIR, and the three topologies without chasing links. If you are feeding this repo to an AI to implement or extend DIR, attach **DIR-minified.md** as the main spec; the human-oriented docs in `docs/` remain the narrative and tutorial layer.
267
+
268
+ ---
269
+
270
+ ## License
271
+
272
+ This project is licensed under the Apache License, Version 2.0 – see the [LICENSE](LICENSE) file for details.
273
+
274
+ ---
275
+
276
+ ## Author
277
+
278
+ **Artur Huk** - [LinkedIn](https://www.linkedin.com/in/arturhuk/)
279
+
280
+ ---
281
+ *This repository represents an evolving architectural framework derived from production constraints in high-stakes AI decision systems.*