crca 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl

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 (306) hide show
  1. CRCA.py +172 -7
  2. MODEL_CARD.md +53 -0
  3. PKG-INFO +8 -2
  4. RELEASE_NOTES.md +17 -0
  5. STABILITY.md +19 -0
  6. architecture/hybrid/consistency_engine.py +362 -0
  7. architecture/hybrid/conversation_manager.py +421 -0
  8. architecture/hybrid/explanation_generator.py +452 -0
  9. architecture/hybrid/few_shot_learner.py +533 -0
  10. architecture/hybrid/graph_compressor.py +286 -0
  11. architecture/hybrid/hybrid_agent.py +4398 -0
  12. architecture/hybrid/language_compiler.py +623 -0
  13. architecture/hybrid/main,py +0 -0
  14. architecture/hybrid/reasoning_tracker.py +322 -0
  15. architecture/hybrid/self_verifier.py +524 -0
  16. architecture/hybrid/task_decomposer.py +567 -0
  17. architecture/hybrid/text_corrector.py +341 -0
  18. benchmark_results/crca_core_benchmarks.json +178 -0
  19. branches/crca_sd/crca_sd_realtime.py +6 -2
  20. branches/general_agent/__init__.py +102 -0
  21. branches/general_agent/general_agent.py +1400 -0
  22. branches/general_agent/personality.py +169 -0
  23. branches/general_agent/utils/__init__.py +19 -0
  24. branches/general_agent/utils/prompt_builder.py +170 -0
  25. {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/METADATA +8 -2
  26. {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/RECORD +303 -20
  27. crca_core/__init__.py +35 -0
  28. crca_core/benchmarks/__init__.py +14 -0
  29. crca_core/benchmarks/synthetic_scm.py +103 -0
  30. crca_core/core/__init__.py +23 -0
  31. crca_core/core/api.py +120 -0
  32. crca_core/core/estimate.py +208 -0
  33. crca_core/core/godclass.py +72 -0
  34. crca_core/core/intervention_design.py +174 -0
  35. crca_core/core/lifecycle.py +48 -0
  36. crca_core/discovery/__init__.py +9 -0
  37. crca_core/discovery/tabular.py +193 -0
  38. crca_core/identify/__init__.py +171 -0
  39. crca_core/identify/backdoor.py +39 -0
  40. crca_core/identify/frontdoor.py +48 -0
  41. crca_core/identify/graph.py +106 -0
  42. crca_core/identify/id_algorithm.py +43 -0
  43. crca_core/identify/iv.py +48 -0
  44. crca_core/models/__init__.py +67 -0
  45. crca_core/models/provenance.py +56 -0
  46. crca_core/models/refusal.py +39 -0
  47. crca_core/models/result.py +83 -0
  48. crca_core/models/spec.py +151 -0
  49. crca_core/models/validation.py +68 -0
  50. crca_core/scm/__init__.py +9 -0
  51. crca_core/scm/linear_gaussian.py +198 -0
  52. crca_core/timeseries/__init__.py +6 -0
  53. crca_core/timeseries/pcmci.py +181 -0
  54. crca_llm/__init__.py +12 -0
  55. crca_llm/client.py +85 -0
  56. crca_llm/coauthor.py +118 -0
  57. crca_llm/orchestrator.py +289 -0
  58. crca_llm/types.py +21 -0
  59. crca_reasoning/__init__.py +16 -0
  60. crca_reasoning/critique.py +54 -0
  61. crca_reasoning/godclass.py +206 -0
  62. crca_reasoning/memory.py +24 -0
  63. crca_reasoning/rationale.py +10 -0
  64. crca_reasoning/react_controller.py +81 -0
  65. crca_reasoning/tool_router.py +97 -0
  66. crca_reasoning/types.py +40 -0
  67. crca_sd/__init__.py +15 -0
  68. crca_sd/crca_sd_core.py +2 -0
  69. crca_sd/crca_sd_governance.py +2 -0
  70. crca_sd/crca_sd_mpc.py +2 -0
  71. crca_sd/crca_sd_realtime.py +2 -0
  72. crca_sd/crca_sd_tui.py +2 -0
  73. cuda-keyring_1.1-1_all.deb +0 -0
  74. cuda-keyring_1.1-1_all.deb.1 +0 -0
  75. docs/IMAGE_ANNOTATION_USAGE.md +539 -0
  76. docs/INSTALL_DEEPSPEED.md +125 -0
  77. docs/api/branches/crca-cg.md +19 -0
  78. docs/api/branches/crca-q.md +27 -0
  79. docs/api/branches/crca-sd.md +37 -0
  80. docs/api/branches/general-agent.md +24 -0
  81. docs/api/branches/overview.md +19 -0
  82. docs/api/crca/agent-methods.md +62 -0
  83. docs/api/crca/operations.md +79 -0
  84. docs/api/crca/overview.md +32 -0
  85. docs/api/image-annotation/engine.md +52 -0
  86. docs/api/image-annotation/overview.md +17 -0
  87. docs/api/schemas/annotation.md +34 -0
  88. docs/api/schemas/core-schemas.md +82 -0
  89. docs/api/schemas/overview.md +32 -0
  90. docs/api/schemas/policy.md +30 -0
  91. docs/api/utils/conversation.md +22 -0
  92. docs/api/utils/graph-reasoner.md +32 -0
  93. docs/api/utils/overview.md +21 -0
  94. docs/api/utils/router.md +19 -0
  95. docs/api/utils/utilities.md +97 -0
  96. docs/architecture/causal-graphs.md +41 -0
  97. docs/architecture/data-flow.md +29 -0
  98. docs/architecture/design-principles.md +33 -0
  99. docs/architecture/hybrid-agent/components.md +38 -0
  100. docs/architecture/hybrid-agent/consistency.md +26 -0
  101. docs/architecture/hybrid-agent/overview.md +44 -0
  102. docs/architecture/hybrid-agent/reasoning.md +22 -0
  103. docs/architecture/llm-integration.md +26 -0
  104. docs/architecture/modular-structure.md +37 -0
  105. docs/architecture/overview.md +69 -0
  106. docs/architecture/policy-engine-arch.md +29 -0
  107. docs/branches/crca-cg/corposwarm.md +39 -0
  108. docs/branches/crca-cg/esg-scoring.md +30 -0
  109. docs/branches/crca-cg/multi-agent.md +35 -0
  110. docs/branches/crca-cg/overview.md +40 -0
  111. docs/branches/crca-q/alternative-data.md +55 -0
  112. docs/branches/crca-q/architecture.md +71 -0
  113. docs/branches/crca-q/backtesting.md +45 -0
  114. docs/branches/crca-q/causal-engine.md +33 -0
  115. docs/branches/crca-q/execution.md +39 -0
  116. docs/branches/crca-q/market-data.md +60 -0
  117. docs/branches/crca-q/overview.md +58 -0
  118. docs/branches/crca-q/philosophy.md +60 -0
  119. docs/branches/crca-q/portfolio-optimization.md +66 -0
  120. docs/branches/crca-q/risk-management.md +102 -0
  121. docs/branches/crca-q/setup.md +65 -0
  122. docs/branches/crca-q/signal-generation.md +61 -0
  123. docs/branches/crca-q/signal-validation.md +43 -0
  124. docs/branches/crca-sd/core.md +84 -0
  125. docs/branches/crca-sd/governance.md +53 -0
  126. docs/branches/crca-sd/mpc-solver.md +65 -0
  127. docs/branches/crca-sd/overview.md +59 -0
  128. docs/branches/crca-sd/realtime.md +28 -0
  129. docs/branches/crca-sd/tui.md +20 -0
  130. docs/branches/general-agent/overview.md +37 -0
  131. docs/branches/general-agent/personality.md +36 -0
  132. docs/branches/general-agent/prompt-builder.md +30 -0
  133. docs/changelog/index.md +79 -0
  134. docs/contributing/code-style.md +69 -0
  135. docs/contributing/documentation.md +43 -0
  136. docs/contributing/overview.md +29 -0
  137. docs/contributing/testing.md +29 -0
  138. docs/core/crcagent/async-operations.md +65 -0
  139. docs/core/crcagent/automatic-extraction.md +107 -0
  140. docs/core/crcagent/batch-prediction.md +80 -0
  141. docs/core/crcagent/bayesian-inference.md +60 -0
  142. docs/core/crcagent/causal-graph.md +92 -0
  143. docs/core/crcagent/counterfactuals.md +96 -0
  144. docs/core/crcagent/deterministic-simulation.md +78 -0
  145. docs/core/crcagent/dual-mode-operation.md +82 -0
  146. docs/core/crcagent/initialization.md +88 -0
  147. docs/core/crcagent/optimization.md +65 -0
  148. docs/core/crcagent/overview.md +63 -0
  149. docs/core/crcagent/time-series.md +57 -0
  150. docs/core/schemas/annotation.md +30 -0
  151. docs/core/schemas/core-schemas.md +82 -0
  152. docs/core/schemas/overview.md +30 -0
  153. docs/core/schemas/policy.md +41 -0
  154. docs/core/templates/base-agent.md +31 -0
  155. docs/core/templates/feature-mixins.md +31 -0
  156. docs/core/templates/overview.md +29 -0
  157. docs/core/templates/templates-guide.md +75 -0
  158. docs/core/tools/mcp-client.md +34 -0
  159. docs/core/tools/overview.md +24 -0
  160. docs/core/utils/conversation.md +27 -0
  161. docs/core/utils/graph-reasoner.md +29 -0
  162. docs/core/utils/overview.md +27 -0
  163. docs/core/utils/router.md +27 -0
  164. docs/core/utils/utilities.md +97 -0
  165. docs/css/custom.css +84 -0
  166. docs/examples/basic-usage.md +57 -0
  167. docs/examples/general-agent/general-agent-examples.md +50 -0
  168. docs/examples/hybrid-agent/hybrid-agent-examples.md +56 -0
  169. docs/examples/image-annotation/image-annotation-examples.md +54 -0
  170. docs/examples/integration/integration-examples.md +58 -0
  171. docs/examples/overview.md +37 -0
  172. docs/examples/trading/trading-examples.md +46 -0
  173. docs/features/causal-reasoning/advanced-topics.md +101 -0
  174. docs/features/causal-reasoning/counterfactuals.md +43 -0
  175. docs/features/causal-reasoning/do-calculus.md +50 -0
  176. docs/features/causal-reasoning/overview.md +47 -0
  177. docs/features/causal-reasoning/structural-models.md +52 -0
  178. docs/features/hybrid-agent/advanced-components.md +55 -0
  179. docs/features/hybrid-agent/core-components.md +64 -0
  180. docs/features/hybrid-agent/overview.md +34 -0
  181. docs/features/image-annotation/engine.md +82 -0
  182. docs/features/image-annotation/features.md +113 -0
  183. docs/features/image-annotation/integration.md +75 -0
  184. docs/features/image-annotation/overview.md +53 -0
  185. docs/features/image-annotation/quickstart.md +73 -0
  186. docs/features/policy-engine/doctrine-ledger.md +105 -0
  187. docs/features/policy-engine/monitoring.md +44 -0
  188. docs/features/policy-engine/mpc-control.md +89 -0
  189. docs/features/policy-engine/overview.md +46 -0
  190. docs/getting-started/configuration.md +225 -0
  191. docs/getting-started/first-agent.md +164 -0
  192. docs/getting-started/installation.md +144 -0
  193. docs/getting-started/quickstart.md +137 -0
  194. docs/index.md +118 -0
  195. docs/js/mathjax.js +13 -0
  196. docs/lrm/discovery_proof_notes.md +25 -0
  197. docs/lrm/finetune_full.md +83 -0
  198. docs/lrm/math_appendix.md +120 -0
  199. docs/lrm/overview.md +32 -0
  200. docs/mkdocs.yml +238 -0
  201. docs/stylesheets/extra.css +21 -0
  202. docs_generated/crca_core/CounterfactualResult.md +12 -0
  203. docs_generated/crca_core/DiscoveryHypothesisResult.md +13 -0
  204. docs_generated/crca_core/DraftSpec.md +13 -0
  205. docs_generated/crca_core/EstimateResult.md +13 -0
  206. docs_generated/crca_core/IdentificationResult.md +17 -0
  207. docs_generated/crca_core/InterventionDesignResult.md +12 -0
  208. docs_generated/crca_core/LockedSpec.md +15 -0
  209. docs_generated/crca_core/RefusalResult.md +12 -0
  210. docs_generated/crca_core/ValidationReport.md +9 -0
  211. docs_generated/crca_core/index.md +13 -0
  212. examples/general_agent_example.py +277 -0
  213. examples/general_agent_quickstart.py +202 -0
  214. examples/general_agent_simple.py +92 -0
  215. examples/hybrid_agent_auto_extraction.py +84 -0
  216. examples/hybrid_agent_dictionary_demo.py +104 -0
  217. examples/hybrid_agent_enhanced.py +179 -0
  218. examples/hybrid_agent_general_knowledge.py +107 -0
  219. examples/image_annotation_quickstart.py +328 -0
  220. examples/test_hybrid_fixes.py +77 -0
  221. image_annotation/__init__.py +27 -0
  222. image_annotation/annotation_engine.py +2593 -0
  223. install_cuda_wsl2.sh +59 -0
  224. install_deepspeed.sh +56 -0
  225. install_deepspeed_simple.sh +87 -0
  226. mkdocs.yml +252 -0
  227. ollama/Modelfile +8 -0
  228. prompts/__init__.py +2 -1
  229. prompts/default_crca.py +9 -1
  230. prompts/general_agent.py +227 -0
  231. prompts/image_annotation.py +56 -0
  232. pyproject.toml +17 -2
  233. requirements-docs.txt +10 -0
  234. requirements.txt +21 -2
  235. schemas/__init__.py +26 -1
  236. schemas/annotation.py +222 -0
  237. schemas/conversation.py +193 -0
  238. schemas/hybrid.py +211 -0
  239. schemas/reasoning.py +276 -0
  240. schemas_export/crca_core/CounterfactualResult.schema.json +108 -0
  241. schemas_export/crca_core/DiscoveryHypothesisResult.schema.json +113 -0
  242. schemas_export/crca_core/DraftSpec.schema.json +635 -0
  243. schemas_export/crca_core/EstimateResult.schema.json +113 -0
  244. schemas_export/crca_core/IdentificationResult.schema.json +145 -0
  245. schemas_export/crca_core/InterventionDesignResult.schema.json +111 -0
  246. schemas_export/crca_core/LockedSpec.schema.json +646 -0
  247. schemas_export/crca_core/RefusalResult.schema.json +90 -0
  248. schemas_export/crca_core/ValidationReport.schema.json +62 -0
  249. scripts/build_lrm_dataset.py +80 -0
  250. scripts/export_crca_core_schemas.py +54 -0
  251. scripts/export_hf_lrm.py +37 -0
  252. scripts/export_ollama_gguf.py +45 -0
  253. scripts/generate_changelog.py +157 -0
  254. scripts/generate_crca_core_docs_from_schemas.py +86 -0
  255. scripts/run_crca_core_benchmarks.py +163 -0
  256. scripts/run_full_finetune.py +198 -0
  257. scripts/run_lrm_eval.py +31 -0
  258. templates/graph_management.py +29 -0
  259. tests/conftest.py +9 -0
  260. tests/test_core.py +2 -3
  261. tests/test_crca_core_discovery_tabular.py +15 -0
  262. tests/test_crca_core_estimate_dowhy.py +36 -0
  263. tests/test_crca_core_identify.py +18 -0
  264. tests/test_crca_core_intervention_design.py +36 -0
  265. tests/test_crca_core_linear_gaussian_scm.py +69 -0
  266. tests/test_crca_core_spec.py +25 -0
  267. tests/test_crca_core_timeseries_pcmci.py +15 -0
  268. tests/test_crca_llm_coauthor.py +12 -0
  269. tests/test_crca_llm_orchestrator.py +80 -0
  270. tests/test_hybrid_agent_llm_enhanced.py +556 -0
  271. tests/test_image_annotation_demo.py +376 -0
  272. tests/test_image_annotation_operational.py +408 -0
  273. tests/test_image_annotation_unit.py +551 -0
  274. tests/test_training_moe.py +13 -0
  275. training/__init__.py +42 -0
  276. training/datasets.py +140 -0
  277. training/deepspeed_zero2_0_5b.json +22 -0
  278. training/deepspeed_zero2_1_5b.json +22 -0
  279. training/deepspeed_zero3_0_5b.json +28 -0
  280. training/deepspeed_zero3_14b.json +28 -0
  281. training/deepspeed_zero3_h100_3gpu.json +20 -0
  282. training/deepspeed_zero3_offload.json +28 -0
  283. training/eval.py +92 -0
  284. training/finetune.py +516 -0
  285. training/public_datasets.py +89 -0
  286. training_data/react_train.jsonl +7473 -0
  287. utils/agent_discovery.py +311 -0
  288. utils/batch_processor.py +317 -0
  289. utils/conversation.py +78 -0
  290. utils/edit_distance.py +118 -0
  291. utils/formatter.py +33 -0
  292. utils/graph_reasoner.py +530 -0
  293. utils/rate_limiter.py +283 -0
  294. utils/router.py +2 -2
  295. utils/tool_discovery.py +307 -0
  296. webui/__init__.py +10 -0
  297. webui/app.py +229 -0
  298. webui/config.py +104 -0
  299. webui/static/css/style.css +332 -0
  300. webui/static/js/main.js +284 -0
  301. webui/templates/index.html +42 -0
  302. tests/test_crca_excel.py +0 -166
  303. tests/test_data_broker.py +0 -424
  304. tests/test_palantir.py +0 -349
  305. {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/WHEEL +0 -0
  306. {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,84 @@
1
+ # CRCA-SD Core
2
+
3
+ Core components of CRCA-SD including state vectors, control vectors, and dynamics models.
4
+
5
+ ## State Vector
6
+
7
+ The state vector represents the socioeconomic system state with 15 variables:
8
+
9
+ $$\mathbf{x}_t = [P_t, L_t, U_t, W_t, S_t, \ell_t, E_{cap,t}, H_{cap,t}, K_t, I_t, T_{cap,t}, E_{stock,t}, F_{stock,t}, M_{stock,t}, C_t, Y_t]'$$
10
+
11
+ ### Variable Definitions
12
+
13
+ - $P_t$: Population
14
+ - $L_t$: Labor force
15
+ - $U_t$: Unemployment rate $[0, 1]$
16
+ - $W_t$: Average wage proxy
17
+ - $S_t$: Social stability proxy $[0, 1]$
18
+ - $\ell_t$: Literacy rate $[0, 1]$
19
+ - $E_{cap,t}$: Education capacity
20
+ - $H_{cap,t}$: Healthcare capacity
21
+ - $K_t$: Productive capital stock
22
+ - $I_t$: Infrastructure health index $[0, 1]$
23
+ - $T_{cap,t}$: Transport capacity
24
+ - $E_{stock,t}$: Stored energy
25
+ - $F_{stock,t}$: Food stock
26
+ - $M_{stock,t}$: Critical materials stock
27
+ - $C_t$: Ecological damage (irreversible)
28
+ - $Y_t$: GDP proxy
29
+
30
+ ## Control Vector
31
+
32
+ The control vector represents budget allocations:
33
+
34
+ $$\mathbf{u}_t = [b_E, b_F, b_H, b_I, b_K, b_RD, b_welfare, b_security]'$$
35
+
36
+ Where each $b_i$ is a budget share such that:
37
+
38
+ $$\sum_i b_i = 1, \quad b_i \geq 0$$
39
+
40
+ ## Dynamics Model
41
+
42
+ The dynamics model implements discrete-time evolution:
43
+
44
+ $$\mathbf{x}_{t+1} = f(\mathbf{x}_t, \mathbf{u}_t, \mathbf{w}_t)$$
45
+
46
+ ### Key Dynamics
47
+
48
+ **Population Growth**:
49
+ $$P_{t+1} = P_t (1 + \beta - \delta + \mu)$$
50
+
51
+ Where $\beta$ is birth rate, $\delta$ is death rate, and $\mu$ is migration.
52
+
53
+ **Capital Accumulation**:
54
+ $$K_{t+1} = (1 - \delta_K) K_t + \kappa_K b_K B_t$$
55
+
56
+ Where $\delta_K$ is depreciation and $\kappa_K$ is investment efficiency.
57
+
58
+ **Output Production** (Cobb-Douglas with gating):
59
+ $$Y_{t+1} = A_t K_t^\alpha L_t^{1-\alpha} g_E h_T$$
60
+
61
+ Where $g_E$ and $h_T$ are energy and transport gates.
62
+
63
+ ## Usage
64
+
65
+ ```python
66
+ from branches.crca_sd.crca_sd_core import StateVector, ControlVector, DynamicsModel
67
+
68
+ # Initialize state
69
+ state = StateVector(P=1000000, L=500000, U=0.05)
70
+
71
+ # Define control
72
+ control = ControlVector(b_E=0.1, b_F=0.2, b_H=0.15)
73
+
74
+ # Create dynamics model
75
+ dynamics = DynamicsModel()
76
+
77
+ # Step forward
78
+ next_state = dynamics.step(state, control)
79
+ ```
80
+
81
+ ## Next Steps
82
+
83
+ - [MPC Solver](mpc-solver.md) - MPC optimization
84
+ - [Governance](governance.md) - Governance systems
@@ -0,0 +1,53 @@
1
+ # Governance Systems
2
+
3
+ CRCA-SD includes governance systems for policy execution, monitoring, and compliance.
4
+
5
+ ## Overview
6
+
7
+ Governance systems manage policy execution, track performance, ensure compliance, and provide visualization and reporting.
8
+
9
+ ## Components
10
+
11
+ ### Board
12
+
13
+ Policy-making board that defines objectives and constraints.
14
+
15
+ ### Metrics Collector
16
+
17
+ Collects and aggregates performance metrics:
18
+
19
+ $$\bar{M}_t = \frac{1}{T} \sum_{s=t-T+1}^t M_s$$
20
+
21
+ Where $M_s$ are metrics at time $s$.
22
+
23
+ ### Visualization
24
+
25
+ Provides visualizations of system state, trajectories, and performance.
26
+
27
+ ## Mathematical Foundation
28
+
29
+ Governance evaluates policy performance using:
30
+
31
+ $$J(\pi) = \sum_{t=0}^T \gamma^t r(\mathbf{x}_t, \mathbf{u}_t)$$
32
+
33
+ Where:
34
+ - $\pi$: Policy
35
+ - $r$: Reward function
36
+ - $\gamma$: Discount factor
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ from branches.crca_sd.crca_sd_governance import Board, MetricsCollector
42
+
43
+ board = Board(objectives=["maximize_gdp", "minimize_unemployment"])
44
+ collector = MetricsCollector()
45
+
46
+ metrics = collector.collect(state, control)
47
+ performance = board.evaluate(metrics)
48
+ ```
49
+
50
+ ## Next Steps
51
+
52
+ - [Overview](overview.md) - Return to overview
53
+ - [CRCA-CG](../crca-cg/overview.md) - Corporate governance
@@ -0,0 +1,65 @@
1
+ # MPC Solver
2
+
3
+ Model Predictive Control (MPC) solver for CRCA-SD.
4
+
5
+ ## Overview
6
+
7
+ The MPC solver optimizes control actions over a prediction horizon to achieve policy objectives while satisfying constraints.
8
+
9
+ ## Mathematical Foundation
10
+
11
+ ### MPC Optimization Problem
12
+
13
+ $$\min_{\mathbf{u}_{t:t+H-1}} \sum_{k=0}^{H-1} \ell(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) + V(\mathbf{x}_{t+H})$$
14
+
15
+ Subject to:
16
+
17
+ $$\mathbf{x}_{t+k+1} = f(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}, \mathbf{w}_{t+k})$$
18
+ $$\mathbf{g}(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) \leq 0$$
19
+ $$\mathbf{h}(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) = 0$$
20
+
21
+ Where:
22
+ - $H$: Prediction horizon
23
+ - $\ell$: Stage cost function
24
+ - $V$: Terminal cost function
25
+ - $f$: System dynamics
26
+ - $\mathbf{g}, \mathbf{h}$: Inequality and equality constraints
27
+
28
+ ### Stage Cost
29
+
30
+ The stage cost typically includes:
31
+
32
+ $$\ell(\mathbf{x}, \mathbf{u}) = \|\mathbf{x} - \mathbf{x}_{ref}\|_Q^2 + \|\mathbf{u} - \mathbf{u}_{ref}\|_R^2$$
33
+
34
+ Where $Q$ and $R$ are weighting matrices.
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ from branches.crca_sd.crca_sd_mpc import MPCSolver
40
+
41
+ solver = MPCSolver(
42
+ horizon=10,
43
+ state_weights=Q,
44
+ control_weights=R
45
+ )
46
+
47
+ # Solve MPC problem
48
+ optimal_controls = solver.solve(
49
+ current_state=state,
50
+ reference_state=ref_state,
51
+ constraints=constraints
52
+ )
53
+ ```
54
+
55
+ ## State Estimation
56
+
57
+ The solver includes state estimation for unobserved variables:
58
+
59
+ $$\hat{\mathbf{x}}_t = E[\mathbf{x}_t | \mathbf{z}_{0:t}]$$
60
+
61
+ Where $\mathbf{z}_{0:t}$ are observations up to time $t$.
62
+
63
+ ## Next Steps
64
+
65
+ - [Governance](governance.md) - Governance systems
@@ -0,0 +1,59 @@
1
+ # CRCA-SD Overview
2
+
3
+ CRCA-SD (CRCA for Socioeconomic Dynamics) is a constrained, stochastic, multi-objective model-predictive control system for socioeconomic dynamics and logistics optimization.
4
+
5
+ ## Overview
6
+
7
+ CRCA-SD integrates CRCA (Causal Reasoning and Counterfactual Analysis) for:
8
+ - Causal scenario generation
9
+ - Causal policy validation
10
+ - Understanding why policies work
11
+
12
+ ## Key Features
13
+
14
+ - **State Vector**: 15 core socioeconomic variables
15
+ - **Control Vector**: Budget shares and allocations
16
+ - **Dynamics Model**: Macro system dynamics equations
17
+ - **MPC Solver**: Model Predictive Control optimization
18
+ - **Governance Systems**: Policy execution and monitoring
19
+ - **Real-Time Control**: Real-time data acquisition and control
20
+
21
+ ## Mathematical Foundation
22
+
23
+ CRCA-SD models socioeconomic systems using state-space representation:
24
+
25
+ $$\mathbf{x}_{t+1} = f(\mathbf{x}_t, \mathbf{u}_t, \mathbf{w}_t)$$
26
+
27
+ Where:
28
+ - $\mathbf{x}_t$: State vector (15 variables)
29
+ - $\mathbf{u}_t$: Control vector (budget allocations)
30
+ - $\mathbf{w}_t$: Exogenous shocks
31
+
32
+ The MPC optimization problem is:
33
+
34
+ $$\min_{\mathbf{u}_{t:t+H-1}} \sum_{k=0}^{H-1} \ell(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) + V(\mathbf{x}_{t+H})$$
35
+
36
+ Subject to:
37
+
38
+ $$\mathbf{x}_{t+k+1} = f(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}, \mathbf{w}_{t+k})$$
39
+ $$\mathbf{g}(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) \leq 0$$
40
+
41
+ ## State Variables
42
+
43
+ The state vector contains 15 variables:
44
+ - **Macro**: Population (P), Labor (L), Unemployment (U), Wage (W), Stability (S)
45
+ - **Human Capital**: Literacy (ℓ), Education Capacity (Ecap), Healthcare Capacity (Hcap)
46
+ - **Capital**: Capital Stock (K), Infrastructure Health (I), Transport Capacity (Tcap)
47
+ - **Stocks**: Energy (E_stock), Food (F_stock), Materials (M_stock), Ecological Damage (C)
48
+ - **Output**: GDP Proxy (Y)
49
+
50
+ ## Documentation
51
+
52
+ - **[Core](core.md)**: Core CRCA-SD functionality
53
+ - **[MPC Solver](mpc-solver.md)**: Model Predictive Control implementation
54
+ - **[Governance](governance.md)**: Governance systems
55
+
56
+ ## Next Steps
57
+
58
+ - [Core](core.md) - Core functionality
59
+ - [MPC Solver](mpc-solver.md) - MPC optimization
@@ -0,0 +1,28 @@
1
+ # Real-Time Control
2
+
3
+ Real-time control system for CRCA-SD.
4
+
5
+ ## Overview
6
+
7
+ Real-time control enables live operation with data acquisition, state estimation, and automated policy execution.
8
+
9
+ ## Mathematical Foundation
10
+
11
+ Real-time control uses state estimation:
12
+
13
+ $$\hat{\mathbf{x}}_t = E[\mathbf{x}_t | \mathbf{z}_{0:t}]$$
14
+
15
+ Where $\mathbf{z}_{0:t}$ are observations.
16
+
17
+ ## Usage
18
+
19
+ ```python
20
+ from branches.crca_sd.crca_sd_realtime import RealTimeController
21
+
22
+ controller = RealTimeController()
23
+ controller.start()
24
+ ```
25
+
26
+ ## Next Steps
27
+
28
+ - [TUI](tui.md) - Terminal user interface
@@ -0,0 +1,20 @@
1
+ # Terminal User Interface (TUI)
2
+
3
+ Terminal user interface for CRCA-SD.
4
+
5
+ ## Overview
6
+
7
+ TUI provides a command-line interface for monitoring and controlling CRCA-SD systems.
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ from branches.crca_sd.crca_sd_tui import TUI
13
+
14
+ tui = TUI()
15
+ tui.run()
16
+ ```
17
+
18
+ ## Next Steps
19
+
20
+ - [Overview](overview.md) - Return to overview
@@ -0,0 +1,37 @@
1
+ # General Agent Overview
2
+
3
+ GeneralAgent is a flexible general-purpose agent with personality system and multimodal capabilities.
4
+
5
+ ## Overview
6
+
7
+ GeneralAgent provides a general-purpose agent framework that can be customized for various tasks with personality traits and multimodal support.
8
+
9
+ ## Key Features
10
+
11
+ - **Personality System**: Configurable personality traits
12
+ - **Multimodal Support**: Text, image, and other modalities
13
+ - **Prompt Building**: Dynamic prompt construction
14
+ - **Flexible Architecture**: Extensible for various use cases
15
+
16
+ ## Usage
17
+
18
+ ```python
19
+ from branches.general_agent.general_agent import GeneralAgent
20
+
21
+ agent = GeneralAgent(
22
+ model_name="gpt-4o-mini",
23
+ enable_multimodal=True
24
+ )
25
+
26
+ response = agent.run("Analyze this image and text")
27
+ ```
28
+
29
+ ## Documentation
30
+
31
+ - **[Personality](personality.md)**: Personality system
32
+ - **[Prompt Builder](prompt-builder.md)**: Prompt building utilities
33
+
34
+ ## Next Steps
35
+
36
+ - [Personality](personality.md) - Personality system
37
+ - [Prompt Builder](prompt-builder.md) - Prompt building
@@ -0,0 +1,36 @@
1
+ # Personality System
2
+
3
+ GeneralAgent includes a configurable personality system.
4
+
5
+ ## Overview
6
+
7
+ The personality system allows configuring agent behavior, tone, and response style.
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ from branches.general_agent.general_agent import GeneralAgent
13
+ from branches.general_agent.personality import Personality
14
+
15
+ personality = Personality(
16
+ traits=["analytical", "helpful", "concise"]
17
+ )
18
+
19
+ agent = GeneralAgent(
20
+ model_name="gpt-4o-mini",
21
+ personality=personality
22
+ )
23
+ ```
24
+
25
+ ## Personality Traits
26
+
27
+ Common traits include:
28
+ - Analytical
29
+ - Creative
30
+ - Helpful
31
+ - Concise
32
+ - Detailed
33
+
34
+ ## Next Steps
35
+
36
+ - [Prompt Builder](prompt-builder.md) - Prompt building utilities
@@ -0,0 +1,30 @@
1
+ # Prompt Builder
2
+
3
+ Prompt building utilities for GeneralAgent.
4
+
5
+ ## Overview
6
+
7
+ Prompt builder utilities help construct dynamic prompts for agent interactions.
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ from branches.general_agent.utils.prompt_builder import PromptBuilder
13
+
14
+ builder = PromptBuilder()
15
+ prompt = builder.build(
16
+ task="Analyze data",
17
+ context=context,
18
+ examples=examples
19
+ )
20
+ ```
21
+
22
+ ## Features
23
+
24
+ - Dynamic prompt construction
25
+ - Context management
26
+ - Example integration
27
+
28
+ ## Next Steps
29
+
30
+ - [Features](../features/policy-engine/overview.md) - Policy engine features
@@ -0,0 +1,79 @@
1
+ # Changelog
2
+
3
+ All notable changes to CR-CA will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - New features in development
12
+
13
+ ### Changed
14
+ - Changes in development
15
+
16
+ ## [1.4.0] - 2024-01-XX
17
+
18
+ ### Added
19
+ - Comprehensive documentation overhaul
20
+ - Policy Engine System documentation
21
+ - Expanded module documentation
22
+ - Architecture diagrams
23
+ - Integration examples
24
+ - CI/CD documentation
25
+ - Project structure documentation
26
+
27
+ ### Changed
28
+ - Complete README rewrite with 100+ code examples
29
+
30
+ ## [1.3.0] - 2024-01-XX
31
+
32
+ ### Added
33
+ - Automatic variable extraction from natural language (v1.3.0+)
34
+ - Enhanced LLM integration
35
+ - Module expansions
36
+
37
+ ### Changed
38
+ - Comprehensive updates to all modules (utils, tools, templates, schemas)
39
+ - Integration improvements for CRCA-SD, CRCA-CG, and CRCA-Q
40
+
41
+ ## [1.2.0] - 2024-01-XX
42
+
43
+ ### Added
44
+ - Advanced Analysis Suite:
45
+ - Batch prediction with vectorized operations
46
+ - Async/await support for concurrent operations
47
+ - Optimization methods (gradient-based, Bellman dynamic programming)
48
+ - Time-series analysis (Granger causality, VAR estimation)
49
+ - Bayesian inference with credible intervals
50
+ - Information-theoretic measures
51
+ - Advanced analysis (sensitivity, root cause, Shapley values)
52
+
53
+ ### Changed
54
+ - Performance improvements: Parallel bootstrap sampling
55
+ - Code optimization: Reduced file size while maintaining functionality
56
+
57
+ ## [1.1.0] - 2024-01-XX
58
+
59
+ ### Added
60
+ - Production hardening:
61
+ - Thread-safe prediction cache with lock protection
62
+ - Requirements.txt pin list for CI
63
+ - GitHub Actions sanity workflow
64
+ - Pytest smoke tests
65
+ - Cache lock documentation
66
+
67
+ ## [1.0.0] - 2024-01-XX
68
+
69
+ ### Added
70
+ - Initial Release:
71
+ - Core CRCAAgent with LLM integration
72
+ - Causal DAG management
73
+ - Linear SCM evolution
74
+ - Counterfactual generation
75
+ - Basic deterministic simulation
76
+
77
+ ---
78
+
79
+ *This changelog is auto-generated from git history and pyproject.toml. Run `python scripts/generate_changelog.py` to update.*
@@ -0,0 +1,69 @@
1
+ # Code Style Guide
2
+
3
+ Follow these guidelines when contributing code to CR-CA.
4
+
5
+ ## Type Annotations
6
+
7
+ Always use type annotations:
8
+
9
+ ```python
10
+ def calculate_average(numbers: List[float]) -> float:
11
+ """Calculate average."""
12
+ return sum(numbers) / len(numbers)
13
+ ```
14
+
15
+ ## Docstrings
16
+
17
+ Use Google-style docstrings:
18
+
19
+ ```python
20
+ def process_data(data: List[int]) -> int:
21
+ """
22
+ Process data and return result.
23
+
24
+ Args:
25
+ data: List of integers to process.
26
+
27
+ Returns:
28
+ Processed result as integer.
29
+
30
+ Raises:
31
+ ValueError: If data is empty.
32
+ """
33
+ if not data:
34
+ raise ValueError("Data cannot be empty")
35
+ return sum(data)
36
+ ```
37
+
38
+ ## Logging
39
+
40
+ Use Loguru for logging:
41
+
42
+ ```python
43
+ from loguru import logger
44
+
45
+ logger.info("Processing data")
46
+ logger.error(f"Error: {error}")
47
+ ```
48
+
49
+ ## Mathematical Documentation
50
+
51
+ Include mathematical formulations for algorithms:
52
+
53
+ ```python
54
+ def compute_causal_effect(treatment: str, outcome: str) -> float:
55
+ """
56
+ Compute causal effect E[Y | do(X=x)].
57
+
58
+ Uses the formula:
59
+ $$E[Y | do(X=x)] = \sum_{z} E[Y | X=x, Z=z] P(Z=z)$$
60
+
61
+ Where Z are confounders.
62
+ """
63
+ # Implementation
64
+ ```
65
+
66
+ ## Next Steps
67
+
68
+ - [Documentation](documentation.md) - Documentation guidelines
69
+ - [Testing](testing.md) - Testing guidelines
@@ -0,0 +1,43 @@
1
+ # Documentation Contribution Guide
2
+
3
+ Guide for contributing to CR-CA documentation.
4
+
5
+ ## Documentation Structure
6
+
7
+ Documentation is organized in `docs/` with:
8
+ - Getting started guides
9
+ - Core module documentation
10
+ - Feature documentation
11
+ - Examples
12
+ - API reference
13
+
14
+ ## Writing Documentation
15
+
16
+ ### Include Mathematical Formulations
17
+
18
+ All concepts should be explainable mathematically:
19
+
20
+ ```markdown
21
+ The causal effect is:
22
+
23
+ $$E[Y | do(X=x)] = \sum_{z} E[Y | X=x, Z=z] P(Z=z)$$
24
+ ```
25
+
26
+ ### Code Examples
27
+
28
+ Include working code examples:
29
+
30
+ ```python
31
+ from CRCA import CRCAAgent
32
+
33
+ agent = CRCAAgent(model_name="gpt-4o-mini")
34
+ result = agent.run("Analyze X -> Y")
35
+ ```
36
+
37
+ ### No Emojis
38
+
39
+ Do not use emojis in documentation. Use text-based symbols if needed.
40
+
41
+ ## Next Steps
42
+
43
+ - [Testing](testing.md) - Testing guidelines
@@ -0,0 +1,29 @@
1
+ # Contributing to CR-CA
2
+
3
+ Thank you for your interest in contributing to CR-CA! This guide will help you get started.
4
+
5
+ ## How to Contribute
6
+
7
+ - Report bugs
8
+ - Suggest features
9
+ - Submit pull requests
10
+ - Improve documentation
11
+ - Write tests
12
+
13
+ ## Getting Started
14
+
15
+ 1. Fork the repository
16
+ 2. Create a feature branch
17
+ 3. Make your changes
18
+ 4. Submit a pull request
19
+
20
+ ## Documentation
21
+
22
+ - **[Code Style](code-style.md)**: Code style guide
23
+ - **[Documentation](documentation.md)**: Documentation contribution guide
24
+ - **[Testing](testing.md)**: Testing guidelines
25
+
26
+ ## Next Steps
27
+
28
+ - [Code Style](code-style.md) - Follow code style guidelines
29
+ - [Documentation](documentation.md) - Contribute to documentation
@@ -0,0 +1,29 @@
1
+ # Testing Guidelines
2
+
3
+ Guidelines for writing and running tests.
4
+
5
+ ## Test Structure
6
+
7
+ Tests are located in `tests/` directory.
8
+
9
+ ## Writing Tests
10
+
11
+ ```python
12
+ import pytest
13
+ from CRCA import CRCAAgent
14
+
15
+ def test_basic_agent():
16
+ agent = CRCAAgent(model_name="gpt-4o-mini")
17
+ result = agent.run("Test task")
18
+ assert result is not None
19
+ ```
20
+
21
+ ## Running Tests
22
+
23
+ ```bash
24
+ pytest tests/
25
+ ```
26
+
27
+ ## Next Steps
28
+
29
+ - [CI/CD Setup](../../getting-started/configuration.md) - CI/CD configuration