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.
- CRCA.py +172 -7
- MODEL_CARD.md +53 -0
- PKG-INFO +8 -2
- RELEASE_NOTES.md +17 -0
- STABILITY.md +19 -0
- architecture/hybrid/consistency_engine.py +362 -0
- architecture/hybrid/conversation_manager.py +421 -0
- architecture/hybrid/explanation_generator.py +452 -0
- architecture/hybrid/few_shot_learner.py +533 -0
- architecture/hybrid/graph_compressor.py +286 -0
- architecture/hybrid/hybrid_agent.py +4398 -0
- architecture/hybrid/language_compiler.py +623 -0
- architecture/hybrid/main,py +0 -0
- architecture/hybrid/reasoning_tracker.py +322 -0
- architecture/hybrid/self_verifier.py +524 -0
- architecture/hybrid/task_decomposer.py +567 -0
- architecture/hybrid/text_corrector.py +341 -0
- benchmark_results/crca_core_benchmarks.json +178 -0
- branches/crca_sd/crca_sd_realtime.py +6 -2
- branches/general_agent/__init__.py +102 -0
- branches/general_agent/general_agent.py +1400 -0
- branches/general_agent/personality.py +169 -0
- branches/general_agent/utils/__init__.py +19 -0
- branches/general_agent/utils/prompt_builder.py +170 -0
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/METADATA +8 -2
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/RECORD +303 -20
- crca_core/__init__.py +35 -0
- crca_core/benchmarks/__init__.py +14 -0
- crca_core/benchmarks/synthetic_scm.py +103 -0
- crca_core/core/__init__.py +23 -0
- crca_core/core/api.py +120 -0
- crca_core/core/estimate.py +208 -0
- crca_core/core/godclass.py +72 -0
- crca_core/core/intervention_design.py +174 -0
- crca_core/core/lifecycle.py +48 -0
- crca_core/discovery/__init__.py +9 -0
- crca_core/discovery/tabular.py +193 -0
- crca_core/identify/__init__.py +171 -0
- crca_core/identify/backdoor.py +39 -0
- crca_core/identify/frontdoor.py +48 -0
- crca_core/identify/graph.py +106 -0
- crca_core/identify/id_algorithm.py +43 -0
- crca_core/identify/iv.py +48 -0
- crca_core/models/__init__.py +67 -0
- crca_core/models/provenance.py +56 -0
- crca_core/models/refusal.py +39 -0
- crca_core/models/result.py +83 -0
- crca_core/models/spec.py +151 -0
- crca_core/models/validation.py +68 -0
- crca_core/scm/__init__.py +9 -0
- crca_core/scm/linear_gaussian.py +198 -0
- crca_core/timeseries/__init__.py +6 -0
- crca_core/timeseries/pcmci.py +181 -0
- crca_llm/__init__.py +12 -0
- crca_llm/client.py +85 -0
- crca_llm/coauthor.py +118 -0
- crca_llm/orchestrator.py +289 -0
- crca_llm/types.py +21 -0
- crca_reasoning/__init__.py +16 -0
- crca_reasoning/critique.py +54 -0
- crca_reasoning/godclass.py +206 -0
- crca_reasoning/memory.py +24 -0
- crca_reasoning/rationale.py +10 -0
- crca_reasoning/react_controller.py +81 -0
- crca_reasoning/tool_router.py +97 -0
- crca_reasoning/types.py +40 -0
- crca_sd/__init__.py +15 -0
- crca_sd/crca_sd_core.py +2 -0
- crca_sd/crca_sd_governance.py +2 -0
- crca_sd/crca_sd_mpc.py +2 -0
- crca_sd/crca_sd_realtime.py +2 -0
- crca_sd/crca_sd_tui.py +2 -0
- cuda-keyring_1.1-1_all.deb +0 -0
- cuda-keyring_1.1-1_all.deb.1 +0 -0
- docs/IMAGE_ANNOTATION_USAGE.md +539 -0
- docs/INSTALL_DEEPSPEED.md +125 -0
- docs/api/branches/crca-cg.md +19 -0
- docs/api/branches/crca-q.md +27 -0
- docs/api/branches/crca-sd.md +37 -0
- docs/api/branches/general-agent.md +24 -0
- docs/api/branches/overview.md +19 -0
- docs/api/crca/agent-methods.md +62 -0
- docs/api/crca/operations.md +79 -0
- docs/api/crca/overview.md +32 -0
- docs/api/image-annotation/engine.md +52 -0
- docs/api/image-annotation/overview.md +17 -0
- docs/api/schemas/annotation.md +34 -0
- docs/api/schemas/core-schemas.md +82 -0
- docs/api/schemas/overview.md +32 -0
- docs/api/schemas/policy.md +30 -0
- docs/api/utils/conversation.md +22 -0
- docs/api/utils/graph-reasoner.md +32 -0
- docs/api/utils/overview.md +21 -0
- docs/api/utils/router.md +19 -0
- docs/api/utils/utilities.md +97 -0
- docs/architecture/causal-graphs.md +41 -0
- docs/architecture/data-flow.md +29 -0
- docs/architecture/design-principles.md +33 -0
- docs/architecture/hybrid-agent/components.md +38 -0
- docs/architecture/hybrid-agent/consistency.md +26 -0
- docs/architecture/hybrid-agent/overview.md +44 -0
- docs/architecture/hybrid-agent/reasoning.md +22 -0
- docs/architecture/llm-integration.md +26 -0
- docs/architecture/modular-structure.md +37 -0
- docs/architecture/overview.md +69 -0
- docs/architecture/policy-engine-arch.md +29 -0
- docs/branches/crca-cg/corposwarm.md +39 -0
- docs/branches/crca-cg/esg-scoring.md +30 -0
- docs/branches/crca-cg/multi-agent.md +35 -0
- docs/branches/crca-cg/overview.md +40 -0
- docs/branches/crca-q/alternative-data.md +55 -0
- docs/branches/crca-q/architecture.md +71 -0
- docs/branches/crca-q/backtesting.md +45 -0
- docs/branches/crca-q/causal-engine.md +33 -0
- docs/branches/crca-q/execution.md +39 -0
- docs/branches/crca-q/market-data.md +60 -0
- docs/branches/crca-q/overview.md +58 -0
- docs/branches/crca-q/philosophy.md +60 -0
- docs/branches/crca-q/portfolio-optimization.md +66 -0
- docs/branches/crca-q/risk-management.md +102 -0
- docs/branches/crca-q/setup.md +65 -0
- docs/branches/crca-q/signal-generation.md +61 -0
- docs/branches/crca-q/signal-validation.md +43 -0
- docs/branches/crca-sd/core.md +84 -0
- docs/branches/crca-sd/governance.md +53 -0
- docs/branches/crca-sd/mpc-solver.md +65 -0
- docs/branches/crca-sd/overview.md +59 -0
- docs/branches/crca-sd/realtime.md +28 -0
- docs/branches/crca-sd/tui.md +20 -0
- docs/branches/general-agent/overview.md +37 -0
- docs/branches/general-agent/personality.md +36 -0
- docs/branches/general-agent/prompt-builder.md +30 -0
- docs/changelog/index.md +79 -0
- docs/contributing/code-style.md +69 -0
- docs/contributing/documentation.md +43 -0
- docs/contributing/overview.md +29 -0
- docs/contributing/testing.md +29 -0
- docs/core/crcagent/async-operations.md +65 -0
- docs/core/crcagent/automatic-extraction.md +107 -0
- docs/core/crcagent/batch-prediction.md +80 -0
- docs/core/crcagent/bayesian-inference.md +60 -0
- docs/core/crcagent/causal-graph.md +92 -0
- docs/core/crcagent/counterfactuals.md +96 -0
- docs/core/crcagent/deterministic-simulation.md +78 -0
- docs/core/crcagent/dual-mode-operation.md +82 -0
- docs/core/crcagent/initialization.md +88 -0
- docs/core/crcagent/optimization.md +65 -0
- docs/core/crcagent/overview.md +63 -0
- docs/core/crcagent/time-series.md +57 -0
- docs/core/schemas/annotation.md +30 -0
- docs/core/schemas/core-schemas.md +82 -0
- docs/core/schemas/overview.md +30 -0
- docs/core/schemas/policy.md +41 -0
- docs/core/templates/base-agent.md +31 -0
- docs/core/templates/feature-mixins.md +31 -0
- docs/core/templates/overview.md +29 -0
- docs/core/templates/templates-guide.md +75 -0
- docs/core/tools/mcp-client.md +34 -0
- docs/core/tools/overview.md +24 -0
- docs/core/utils/conversation.md +27 -0
- docs/core/utils/graph-reasoner.md +29 -0
- docs/core/utils/overview.md +27 -0
- docs/core/utils/router.md +27 -0
- docs/core/utils/utilities.md +97 -0
- docs/css/custom.css +84 -0
- docs/examples/basic-usage.md +57 -0
- docs/examples/general-agent/general-agent-examples.md +50 -0
- docs/examples/hybrid-agent/hybrid-agent-examples.md +56 -0
- docs/examples/image-annotation/image-annotation-examples.md +54 -0
- docs/examples/integration/integration-examples.md +58 -0
- docs/examples/overview.md +37 -0
- docs/examples/trading/trading-examples.md +46 -0
- docs/features/causal-reasoning/advanced-topics.md +101 -0
- docs/features/causal-reasoning/counterfactuals.md +43 -0
- docs/features/causal-reasoning/do-calculus.md +50 -0
- docs/features/causal-reasoning/overview.md +47 -0
- docs/features/causal-reasoning/structural-models.md +52 -0
- docs/features/hybrid-agent/advanced-components.md +55 -0
- docs/features/hybrid-agent/core-components.md +64 -0
- docs/features/hybrid-agent/overview.md +34 -0
- docs/features/image-annotation/engine.md +82 -0
- docs/features/image-annotation/features.md +113 -0
- docs/features/image-annotation/integration.md +75 -0
- docs/features/image-annotation/overview.md +53 -0
- docs/features/image-annotation/quickstart.md +73 -0
- docs/features/policy-engine/doctrine-ledger.md +105 -0
- docs/features/policy-engine/monitoring.md +44 -0
- docs/features/policy-engine/mpc-control.md +89 -0
- docs/features/policy-engine/overview.md +46 -0
- docs/getting-started/configuration.md +225 -0
- docs/getting-started/first-agent.md +164 -0
- docs/getting-started/installation.md +144 -0
- docs/getting-started/quickstart.md +137 -0
- docs/index.md +118 -0
- docs/js/mathjax.js +13 -0
- docs/lrm/discovery_proof_notes.md +25 -0
- docs/lrm/finetune_full.md +83 -0
- docs/lrm/math_appendix.md +120 -0
- docs/lrm/overview.md +32 -0
- docs/mkdocs.yml +238 -0
- docs/stylesheets/extra.css +21 -0
- docs_generated/crca_core/CounterfactualResult.md +12 -0
- docs_generated/crca_core/DiscoveryHypothesisResult.md +13 -0
- docs_generated/crca_core/DraftSpec.md +13 -0
- docs_generated/crca_core/EstimateResult.md +13 -0
- docs_generated/crca_core/IdentificationResult.md +17 -0
- docs_generated/crca_core/InterventionDesignResult.md +12 -0
- docs_generated/crca_core/LockedSpec.md +15 -0
- docs_generated/crca_core/RefusalResult.md +12 -0
- docs_generated/crca_core/ValidationReport.md +9 -0
- docs_generated/crca_core/index.md +13 -0
- examples/general_agent_example.py +277 -0
- examples/general_agent_quickstart.py +202 -0
- examples/general_agent_simple.py +92 -0
- examples/hybrid_agent_auto_extraction.py +84 -0
- examples/hybrid_agent_dictionary_demo.py +104 -0
- examples/hybrid_agent_enhanced.py +179 -0
- examples/hybrid_agent_general_knowledge.py +107 -0
- examples/image_annotation_quickstart.py +328 -0
- examples/test_hybrid_fixes.py +77 -0
- image_annotation/__init__.py +27 -0
- image_annotation/annotation_engine.py +2593 -0
- install_cuda_wsl2.sh +59 -0
- install_deepspeed.sh +56 -0
- install_deepspeed_simple.sh +87 -0
- mkdocs.yml +252 -0
- ollama/Modelfile +8 -0
- prompts/__init__.py +2 -1
- prompts/default_crca.py +9 -1
- prompts/general_agent.py +227 -0
- prompts/image_annotation.py +56 -0
- pyproject.toml +17 -2
- requirements-docs.txt +10 -0
- requirements.txt +21 -2
- schemas/__init__.py +26 -1
- schemas/annotation.py +222 -0
- schemas/conversation.py +193 -0
- schemas/hybrid.py +211 -0
- schemas/reasoning.py +276 -0
- schemas_export/crca_core/CounterfactualResult.schema.json +108 -0
- schemas_export/crca_core/DiscoveryHypothesisResult.schema.json +113 -0
- schemas_export/crca_core/DraftSpec.schema.json +635 -0
- schemas_export/crca_core/EstimateResult.schema.json +113 -0
- schemas_export/crca_core/IdentificationResult.schema.json +145 -0
- schemas_export/crca_core/InterventionDesignResult.schema.json +111 -0
- schemas_export/crca_core/LockedSpec.schema.json +646 -0
- schemas_export/crca_core/RefusalResult.schema.json +90 -0
- schemas_export/crca_core/ValidationReport.schema.json +62 -0
- scripts/build_lrm_dataset.py +80 -0
- scripts/export_crca_core_schemas.py +54 -0
- scripts/export_hf_lrm.py +37 -0
- scripts/export_ollama_gguf.py +45 -0
- scripts/generate_changelog.py +157 -0
- scripts/generate_crca_core_docs_from_schemas.py +86 -0
- scripts/run_crca_core_benchmarks.py +163 -0
- scripts/run_full_finetune.py +198 -0
- scripts/run_lrm_eval.py +31 -0
- templates/graph_management.py +29 -0
- tests/conftest.py +9 -0
- tests/test_core.py +2 -3
- tests/test_crca_core_discovery_tabular.py +15 -0
- tests/test_crca_core_estimate_dowhy.py +36 -0
- tests/test_crca_core_identify.py +18 -0
- tests/test_crca_core_intervention_design.py +36 -0
- tests/test_crca_core_linear_gaussian_scm.py +69 -0
- tests/test_crca_core_spec.py +25 -0
- tests/test_crca_core_timeseries_pcmci.py +15 -0
- tests/test_crca_llm_coauthor.py +12 -0
- tests/test_crca_llm_orchestrator.py +80 -0
- tests/test_hybrid_agent_llm_enhanced.py +556 -0
- tests/test_image_annotation_demo.py +376 -0
- tests/test_image_annotation_operational.py +408 -0
- tests/test_image_annotation_unit.py +551 -0
- tests/test_training_moe.py +13 -0
- training/__init__.py +42 -0
- training/datasets.py +140 -0
- training/deepspeed_zero2_0_5b.json +22 -0
- training/deepspeed_zero2_1_5b.json +22 -0
- training/deepspeed_zero3_0_5b.json +28 -0
- training/deepspeed_zero3_14b.json +28 -0
- training/deepspeed_zero3_h100_3gpu.json +20 -0
- training/deepspeed_zero3_offload.json +28 -0
- training/eval.py +92 -0
- training/finetune.py +516 -0
- training/public_datasets.py +89 -0
- training_data/react_train.jsonl +7473 -0
- utils/agent_discovery.py +311 -0
- utils/batch_processor.py +317 -0
- utils/conversation.py +78 -0
- utils/edit_distance.py +118 -0
- utils/formatter.py +33 -0
- utils/graph_reasoner.py +530 -0
- utils/rate_limiter.py +283 -0
- utils/router.py +2 -2
- utils/tool_discovery.py +307 -0
- webui/__init__.py +10 -0
- webui/app.py +229 -0
- webui/config.py +104 -0
- webui/static/css/style.css +332 -0
- webui/static/js/main.js +284 -0
- webui/templates/index.html +42 -0
- tests/test_crca_excel.py +0 -166
- tests/test_data_broker.py +0 -424
- tests/test_palantir.py +0 -349
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/WHEEL +0 -0
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# CRCAAgent Initialization
|
|
2
|
+
|
|
3
|
+
This guide covers initializing and configuring CRCAAgent instances.
|
|
4
|
+
|
|
5
|
+
## Basic Initialization
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from CRCA import CRCAAgent
|
|
9
|
+
|
|
10
|
+
agent = CRCAAgent(
|
|
11
|
+
model_name="gpt-4o-mini",
|
|
12
|
+
agent_name="my-agent"
|
|
13
|
+
)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Configuration Parameters
|
|
17
|
+
|
|
18
|
+
### Required Parameters
|
|
19
|
+
|
|
20
|
+
- `model_name`: LLM model identifier (e.g., "gpt-4o-mini", "gpt-4")
|
|
21
|
+
- `agent_name`: Unique identifier for the agent
|
|
22
|
+
|
|
23
|
+
### Optional Parameters
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
agent = CRCAAgent(
|
|
27
|
+
model_name="gpt-4o-mini",
|
|
28
|
+
agent_name="configured-agent",
|
|
29
|
+
|
|
30
|
+
# LLM Settings
|
|
31
|
+
max_loops=5,
|
|
32
|
+
temperature=0.7,
|
|
33
|
+
max_tokens=2000,
|
|
34
|
+
|
|
35
|
+
# Causal Reasoning
|
|
36
|
+
enable_automatic_extraction=True,
|
|
37
|
+
causal_graph_threshold=0.3,
|
|
38
|
+
|
|
39
|
+
# Simulation
|
|
40
|
+
simulation_steps=100,
|
|
41
|
+
simulation_dt=0.01,
|
|
42
|
+
|
|
43
|
+
# Tools
|
|
44
|
+
use_crca_tools=True,
|
|
45
|
+
use_image_annotation=False
|
|
46
|
+
)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Mathematical Configuration
|
|
50
|
+
|
|
51
|
+
The agent's causal reasoning is configured through structural equations. For a variable $Y$ with parents $Pa(Y)$:
|
|
52
|
+
|
|
53
|
+
$$Y = f(Pa(Y), U_Y)$$
|
|
54
|
+
|
|
55
|
+
Where $U_Y$ is an exogenous variable. The agent estimates these functions from data or uses LLM-based inference.
|
|
56
|
+
|
|
57
|
+
## Mode Selection
|
|
58
|
+
|
|
59
|
+
### LLM Mode (Default)
|
|
60
|
+
|
|
61
|
+
Uses LLM for causal reasoning:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
agent = CRCAAgent(
|
|
65
|
+
model_name="gpt-4o-mini",
|
|
66
|
+
mode="llm"
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Deterministic Mode
|
|
71
|
+
|
|
72
|
+
Uses mathematical simulation:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
agent = CRCAAgent(
|
|
76
|
+
model_name="gpt-4o-mini",
|
|
77
|
+
mode="deterministic"
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Advanced Configuration
|
|
82
|
+
|
|
83
|
+
See [Configuration Guide](../../getting-started/configuration.md) for detailed configuration options.
|
|
84
|
+
|
|
85
|
+
## Next Steps
|
|
86
|
+
|
|
87
|
+
- [Automatic Extraction](automatic-extraction.md) - Extract variables automatically
|
|
88
|
+
- [Dual-Mode Operation](dual-mode-operation.md) - Understand mode switching
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Optimization Methods
|
|
2
|
+
|
|
3
|
+
CRCAAgent includes optimization methods for finding optimal interventions.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Optimization methods find interventions that maximize or minimize target outcomes subject to constraints.
|
|
8
|
+
|
|
9
|
+
## Mathematical Foundation
|
|
10
|
+
|
|
11
|
+
### Optimization Problem
|
|
12
|
+
|
|
13
|
+
Find intervention $x^*$ that maximizes expected outcome:
|
|
14
|
+
|
|
15
|
+
$$x^* = \arg\max_x E[Y | do(X=x)]$$
|
|
16
|
+
|
|
17
|
+
Subject to constraints:
|
|
18
|
+
|
|
19
|
+
$$g_i(x) \leq 0, \quad i = 1, \ldots, m$$
|
|
20
|
+
$$h_j(x) = 0, \quad j = 1, \ldots, p$$
|
|
21
|
+
|
|
22
|
+
### Gradient-Based Optimization
|
|
23
|
+
|
|
24
|
+
For differentiable objectives:
|
|
25
|
+
|
|
26
|
+
$$\nabla_x E[Y | do(X=x)] = 0$$
|
|
27
|
+
|
|
28
|
+
Using gradient descent:
|
|
29
|
+
|
|
30
|
+
$$x_{t+1} = x_t - \alpha \nabla_x E[Y | do(X=x_t)]$$
|
|
31
|
+
|
|
32
|
+
Where $\alpha$ is the learning rate.
|
|
33
|
+
|
|
34
|
+
### Dynamic Programming
|
|
35
|
+
|
|
36
|
+
For sequential decision problems:
|
|
37
|
+
|
|
38
|
+
$$V_t(s) = \max_a \left\{ R(s,a) + \gamma \sum_{s'} P(s'|s,a) V_{t+1}(s') \right\}$$
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Gradient-Based
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
optimal = agent.optimize_intervention(
|
|
46
|
+
target="income",
|
|
47
|
+
method="gradient",
|
|
48
|
+
constraints={"education": (0, 20)}
|
|
49
|
+
)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Dynamic Programming
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
optimal = agent.optimize_intervention(
|
|
56
|
+
target="income",
|
|
57
|
+
method="bellman",
|
|
58
|
+
horizon=10
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Next Steps
|
|
63
|
+
|
|
64
|
+
- [Time-Series](time-series.md) - Time-series analysis
|
|
65
|
+
- [Bayesian Inference](bayesian-inference.md) - Bayesian methods
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CRCAAgent Overview
|
|
2
|
+
|
|
3
|
+
CRCAAgent is the core causal reasoning agent in the CR-CA framework. It combines structural causal models (SCMs) with large language model (LLM) integration to enable sophisticated causal inference and counterfactual analysis.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **Automatic Variable Extraction**: Extract variables and causal relationships from natural language
|
|
8
|
+
- **Dual-Mode Operation**: Switch between LLM-based analysis and deterministic simulation
|
|
9
|
+
- **Causal Graph Management**: Build and manage causal directed acyclic graphs (DAGs)
|
|
10
|
+
- **Deterministic Simulation**: Perform mathematical causal simulations
|
|
11
|
+
- **Counterfactual Generation**: Generate "what-if" scenarios
|
|
12
|
+
- **Batch Prediction**: Process multiple scenarios simultaneously
|
|
13
|
+
- **Async Operations**: Concurrent analysis with async/await support
|
|
14
|
+
|
|
15
|
+
## Mathematical Foundation
|
|
16
|
+
|
|
17
|
+
CRCAAgent implements Structural Causal Models (SCMs) as defined by Judea Pearl. An SCM is a triple:
|
|
18
|
+
|
|
19
|
+
$$(U, V, F)$$
|
|
20
|
+
|
|
21
|
+
Where:
|
|
22
|
+
- $U$: Exogenous (unobserved) variables
|
|
23
|
+
- $V$: Endogenous (observed) variables
|
|
24
|
+
- $F$: Structural equations defining causal relationships
|
|
25
|
+
|
|
26
|
+
Each structural equation has the form:
|
|
27
|
+
|
|
28
|
+
$$V_i = f_i(Pa(V_i), U_i)$$
|
|
29
|
+
|
|
30
|
+
Where $Pa(V_i)$ are the parents of $V_i$ in the causal graph.
|
|
31
|
+
|
|
32
|
+
## Basic Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from CRCA import CRCAAgent
|
|
36
|
+
|
|
37
|
+
agent = CRCAAgent(
|
|
38
|
+
model_name="gpt-4o-mini",
|
|
39
|
+
agent_name="my-agent"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
result = agent.run("Analyze the causal relationship between X and Y")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Core Components
|
|
46
|
+
|
|
47
|
+
- **[Initialization](initialization.md)**: Agent setup and configuration
|
|
48
|
+
- **[Automatic Extraction](automatic-extraction.md)**: Variable extraction from natural language
|
|
49
|
+
- **[Dual-Mode Operation](dual-mode-operation.md)**: LLM vs deterministic modes
|
|
50
|
+
- **[Causal Graph](causal-graph.md)**: Causal DAG construction and management
|
|
51
|
+
- **[Deterministic Simulation](deterministic-simulation.md)**: Mathematical simulation
|
|
52
|
+
- **[Counterfactuals](counterfactuals.md)**: Counterfactual scenario generation
|
|
53
|
+
- **[Batch Prediction](batch-prediction.md)**: Batch processing capabilities
|
|
54
|
+
- **[Async Operations](async-operations.md)**: Async/await support
|
|
55
|
+
- **[Optimization](optimization.md)**: Optimization methods
|
|
56
|
+
- **[Time-Series](time-series.md)**: Time-series analysis
|
|
57
|
+
- **[Bayesian Inference](bayesian-inference.md)**: Bayesian inference with credible intervals
|
|
58
|
+
|
|
59
|
+
## Next Steps
|
|
60
|
+
|
|
61
|
+
- [Initialization](initialization.md) - Configure your agent
|
|
62
|
+
- [Automatic Extraction](automatic-extraction.md) - Extract variables from text
|
|
63
|
+
- [Causal Graph](causal-graph.md) - Work with causal graphs
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Time-Series Analysis
|
|
2
|
+
|
|
3
|
+
CRCAAgent supports time-series causal analysis including Granger causality and VAR models.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Time-series analysis identifies causal relationships in temporal data, accounting for temporal dependencies.
|
|
8
|
+
|
|
9
|
+
## Mathematical Foundation
|
|
10
|
+
|
|
11
|
+
### Vector Autoregression (VAR)
|
|
12
|
+
|
|
13
|
+
A VAR($p$) model for $k$ variables:
|
|
14
|
+
|
|
15
|
+
$$\mathbf{y}_t = \mathbf{c} + \sum_{i=1}^p \mathbf{\Phi}_i \mathbf{y}_{t-i} + \boldsymbol{\epsilon}_t$$
|
|
16
|
+
|
|
17
|
+
Where:
|
|
18
|
+
- $\mathbf{y}_t$: Vector of variables at time $t$
|
|
19
|
+
- $\mathbf{\Phi}_i$: Coefficient matrices
|
|
20
|
+
- $\boldsymbol{\epsilon}_t$: Error terms
|
|
21
|
+
|
|
22
|
+
### Granger Causality
|
|
23
|
+
|
|
24
|
+
$X$ Granger-causes $Y$ if:
|
|
25
|
+
|
|
26
|
+
$$E[Y_t | \mathcal{I}_{t-1}] \neq E[Y_t | \mathcal{I}_{t-1} \setminus X_{t-1}]$$
|
|
27
|
+
|
|
28
|
+
Where $\mathcal{I}_{t-1}$ is the information set at time $t-1$.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### VAR Estimation
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# Estimate VAR model
|
|
36
|
+
var_model = agent.estimate_var(
|
|
37
|
+
data=dataframe,
|
|
38
|
+
variables=["X", "Y", "Z"],
|
|
39
|
+
lags=4
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Granger Causality Test
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
# Test if X Granger-causes Y
|
|
47
|
+
result = agent.granger_causality_test(
|
|
48
|
+
data=dataframe,
|
|
49
|
+
cause="X",
|
|
50
|
+
effect="Y",
|
|
51
|
+
max_lag=4
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Next Steps
|
|
56
|
+
|
|
57
|
+
- [Bayesian Inference](bayesian-inference.md) - Bayesian time-series methods
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Annotation Schemas
|
|
2
|
+
|
|
3
|
+
Schemas for image annotation system.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Annotation schemas define data structures for image annotation results, including entities, labels, and relations.
|
|
8
|
+
|
|
9
|
+
## Key Schemas
|
|
10
|
+
|
|
11
|
+
- `AnnotationResult`: Complete annotation result
|
|
12
|
+
- `PrimitiveEntity`: Geometric primitive entity
|
|
13
|
+
- `SemanticLabel`: Semantic label for entities
|
|
14
|
+
- `Relation`: Relationship between entities
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from schemas.annotation import AnnotationResult, PrimitiveEntity
|
|
20
|
+
|
|
21
|
+
result = AnnotationResult(
|
|
22
|
+
entities=[PrimitiveEntity(...)],
|
|
23
|
+
labels=[],
|
|
24
|
+
relations=[]
|
|
25
|
+
)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Next Steps
|
|
29
|
+
|
|
30
|
+
- [Conversation](conversation.md) - Conversation schemas
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Core Schemas
|
|
2
|
+
|
|
3
|
+
Grouped documentation for core data schemas.
|
|
4
|
+
|
|
5
|
+
## Conversation Schemas
|
|
6
|
+
|
|
7
|
+
Schemas for conversation management.
|
|
8
|
+
|
|
9
|
+
### Classes
|
|
10
|
+
|
|
11
|
+
- `ConversationState`: Current conversation state
|
|
12
|
+
- `Message`: Individual message in conversation
|
|
13
|
+
- `Context`: Conversation context
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from schemas.conversation import ConversationState, Message
|
|
19
|
+
|
|
20
|
+
state = ConversationState(
|
|
21
|
+
messages=[Message(role="user", content="Hello")]
|
|
22
|
+
)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Hybrid Agent Schemas
|
|
26
|
+
|
|
27
|
+
Schemas for hybrid agent architecture.
|
|
28
|
+
|
|
29
|
+
### Classes
|
|
30
|
+
|
|
31
|
+
- `HybridAgentState`: Hybrid agent state
|
|
32
|
+
- `ReasoningStep`: Individual reasoning step
|
|
33
|
+
- `ConsistencyCheck`: Consistency check result
|
|
34
|
+
|
|
35
|
+
### Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from schemas.hybrid import HybridAgentState
|
|
39
|
+
|
|
40
|
+
state = HybridAgentState(
|
|
41
|
+
reasoning_steps=[],
|
|
42
|
+
consistency_checks=[]
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Reasoning Schemas
|
|
47
|
+
|
|
48
|
+
Schemas for causal reasoning operations and results.
|
|
49
|
+
|
|
50
|
+
### Classes
|
|
51
|
+
|
|
52
|
+
- `CausalInferenceResult`: Causal inference result
|
|
53
|
+
- `CounterfactualScenario`: Counterfactual scenario
|
|
54
|
+
- `CausalEffect`: Causal effect estimate
|
|
55
|
+
|
|
56
|
+
### Mathematical Foundation
|
|
57
|
+
|
|
58
|
+
Causal effect:
|
|
59
|
+
|
|
60
|
+
$$\tau = E[Y | do(X=1)] - E[Y | do(X=0)]$$
|
|
61
|
+
|
|
62
|
+
With confidence interval:
|
|
63
|
+
|
|
64
|
+
$$CI_{1-\alpha} = [\tau - z_{\alpha/2} \cdot SE, \tau + z_{\alpha/2} \cdot SE]$$
|
|
65
|
+
|
|
66
|
+
### Usage
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from schemas.reasoning import CausalInferenceResult
|
|
70
|
+
|
|
71
|
+
result = CausalInferenceResult(
|
|
72
|
+
treatment="X",
|
|
73
|
+
outcome="Y",
|
|
74
|
+
effect=0.5,
|
|
75
|
+
confidence=0.9
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Next Steps
|
|
80
|
+
|
|
81
|
+
- [Annotation](annotation.md) - Image annotation schemas
|
|
82
|
+
- [Policy](policy.md) - Policy engine schemas
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Schemas Overview
|
|
2
|
+
|
|
3
|
+
The `schemas/` module provides type definitions and data structures for CR-CA.
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- **[Annotation](annotation.md)**: Image annotation schemas
|
|
8
|
+
- **[Conversation](conversation.md)**: Conversation schemas
|
|
9
|
+
- **[Hybrid](hybrid.md)**: Hybrid agent schemas
|
|
10
|
+
- **[Reasoning](reasoning.md)**: Reasoning schemas
|
|
11
|
+
- **[Policy](policy.md)**: Policy engine schemas
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Schemas are Pydantic models that provide type safety and validation:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from schemas.annotation import AnnotationResult
|
|
19
|
+
|
|
20
|
+
result = AnnotationResult(
|
|
21
|
+
entities=[],
|
|
22
|
+
labels=[],
|
|
23
|
+
relations=[]
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Next Steps
|
|
28
|
+
|
|
29
|
+
- [Annotation](annotation.md) - Image annotation schemas
|
|
30
|
+
- [Policy](policy.md) - Policy engine schemas
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Policy Engine Schemas
|
|
2
|
+
|
|
3
|
+
Schemas for policy engine system.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Policy engine schemas define data structures for policy doctrines, ledgers, and policy execution.
|
|
8
|
+
|
|
9
|
+
## Key Schemas
|
|
10
|
+
|
|
11
|
+
- `DoctrineV1`: Policy doctrine definition
|
|
12
|
+
- `PolicyState`: Current policy state
|
|
13
|
+
- `PolicyAction`: Policy action
|
|
14
|
+
- `PolicyObservation`: Policy observation
|
|
15
|
+
|
|
16
|
+
## Mathematical Foundation
|
|
17
|
+
|
|
18
|
+
Policy doctrine defines objectives and constraints:
|
|
19
|
+
|
|
20
|
+
$$\min_{u} \sum_{t=0}^{T} \ell(x_t, u_t)$$
|
|
21
|
+
|
|
22
|
+
Subject to:
|
|
23
|
+
|
|
24
|
+
$$g(x_t, u_t) \leq 0$$
|
|
25
|
+
$$h(x_t, u_t) = 0$$
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from schemas.policy import DoctrineV1
|
|
31
|
+
|
|
32
|
+
doctrine = DoctrineV1(
|
|
33
|
+
version="1.0.0",
|
|
34
|
+
objectives=["maximize_efficiency"],
|
|
35
|
+
constraints=["budget_limit"]
|
|
36
|
+
)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Next Steps
|
|
40
|
+
|
|
41
|
+
- [Tools Overview](../tools/overview.md) - Tools and integrations
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Base Specialized Agent
|
|
2
|
+
|
|
3
|
+
The base specialized agent template provides a foundation for creating custom agents.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
BaseSpecializedAgent is an abstract base class that provides common functionality for specialized agents.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from templates.base_specialized_agent import BaseSpecializedAgent
|
|
13
|
+
|
|
14
|
+
class MyAgent(BaseSpecializedAgent):
|
|
15
|
+
def __init__(self):
|
|
16
|
+
super().__init__()
|
|
17
|
+
|
|
18
|
+
def process_task(self, task):
|
|
19
|
+
# Implement custom logic
|
|
20
|
+
pass
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- Common agent functionality
|
|
26
|
+
- Integration with CR-CA framework
|
|
27
|
+
- Extensible architecture
|
|
28
|
+
|
|
29
|
+
## Next Steps
|
|
30
|
+
|
|
31
|
+
- [Feature Mixins](feature-mixins.md) - Add features via mixins
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Feature Mixins
|
|
2
|
+
|
|
3
|
+
Feature mixins provide reusable functionality that can be mixed into agent classes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Mixins allow adding features to agents without multiple inheritance complexity.
|
|
8
|
+
|
|
9
|
+
## Available Mixins
|
|
10
|
+
|
|
11
|
+
- Policy loop functionality
|
|
12
|
+
- Graph management
|
|
13
|
+
- LLM integration
|
|
14
|
+
- Statistical methods
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from templates.base_specialized_agent import BaseSpecializedAgent
|
|
20
|
+
from templates.feature_mixins import PolicyLoopMixin
|
|
21
|
+
|
|
22
|
+
class MyAgent(BaseSpecializedAgent, PolicyLoopMixin):
|
|
23
|
+
def __init__(self):
|
|
24
|
+
super().__init__()
|
|
25
|
+
# Mixin functionality is now available
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Next Steps
|
|
29
|
+
|
|
30
|
+
- [Policy Loop](policy-loop.md) - Policy loop mixin
|
|
31
|
+
- [Graph Management](graph-management.md) - Graph management mixin
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Templates Overview
|
|
2
|
+
|
|
3
|
+
The `templates/` module provides a framework for creating specialized agents.
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- **[Base Agent](base-agent.md)**: Base specialized agent template
|
|
8
|
+
- **[Feature Mixins](feature-mixins.md)**: Reusable feature mixins
|
|
9
|
+
- **[Policy Loop](policy-loop.md)**: Policy loop mixin
|
|
10
|
+
- **[Graph Management](graph-management.md)**: Graph management mixin
|
|
11
|
+
- **[LLM Integration](llm-integration.md)**: LLM integration mixin
|
|
12
|
+
|
|
13
|
+
## Creating Custom Agents
|
|
14
|
+
|
|
15
|
+
Use templates to create specialized agents:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from templates.base_specialized_agent import BaseSpecializedAgent
|
|
19
|
+
|
|
20
|
+
class MyAgent(BaseSpecializedAgent):
|
|
21
|
+
def __init__(self):
|
|
22
|
+
super().__init__()
|
|
23
|
+
# Add custom functionality
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Next Steps
|
|
27
|
+
|
|
28
|
+
- [Base Agent](base-agent.md) - Base template
|
|
29
|
+
- [Feature Mixins](feature-mixins.md) - Reusable features
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Templates Guide
|
|
2
|
+
|
|
3
|
+
Comprehensive guide to using templates for creating specialized agents.
|
|
4
|
+
|
|
5
|
+
## Policy Loop Mixin
|
|
6
|
+
|
|
7
|
+
Policy loop mixin provides policy engine functionality for agents.
|
|
8
|
+
|
|
9
|
+
### Mathematical Foundation
|
|
10
|
+
|
|
11
|
+
Policy loop implements Model Predictive Control (MPC):
|
|
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})$$
|
|
18
|
+
$$\mathbf{g}(\mathbf{x}_{t+k}, \mathbf{u}_{t+k}) \leq 0$$
|
|
19
|
+
|
|
20
|
+
### Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from templates.base_specialized_agent import BaseSpecializedAgent
|
|
24
|
+
from templates.policy_loop import PolicyLoopMixin
|
|
25
|
+
|
|
26
|
+
class PolicyAgent(BaseSpecializedAgent, PolicyLoopMixin):
|
|
27
|
+
def __init__(self):
|
|
28
|
+
super().__init__()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Graph Management Mixin
|
|
32
|
+
|
|
33
|
+
Graph management mixin provides causal graph management functionality.
|
|
34
|
+
|
|
35
|
+
### Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from templates.graph_management import GraphManagementMixin
|
|
39
|
+
|
|
40
|
+
class GraphAgent(BaseSpecializedAgent, GraphManagementMixin):
|
|
41
|
+
def __init__(self):
|
|
42
|
+
super().__init__()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## LLM Integration Mixin
|
|
46
|
+
|
|
47
|
+
LLM integration mixin provides LLM-based reasoning capabilities.
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from templates.llm_integration import LLMIntegrationMixin
|
|
53
|
+
|
|
54
|
+
class LLMAgent(BaseSpecializedAgent, LLMIntegrationMixin):
|
|
55
|
+
def __init__(self):
|
|
56
|
+
super().__init__()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Module Registry
|
|
60
|
+
|
|
61
|
+
Module registry for managing and discovering modules.
|
|
62
|
+
|
|
63
|
+
### Usage
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from templates.module_registry import ModuleRegistry
|
|
67
|
+
|
|
68
|
+
registry = ModuleRegistry()
|
|
69
|
+
registry.register(module)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Next Steps
|
|
73
|
+
|
|
74
|
+
- [Base Agent](base-agent.md) - Base template
|
|
75
|
+
- [Feature Mixins](feature-mixins.md) - Reusable features
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# MCP Client
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) client utilities for CR-CA.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MCP client enables CR-CA agents to interact with MCP servers for extended tool capabilities.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from tools.mcp_client import MCPClient
|
|
13
|
+
|
|
14
|
+
client = MCPClient(
|
|
15
|
+
server_url="http://localhost:8000",
|
|
16
|
+
api_key="your-api-key"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# Call MCP tool
|
|
20
|
+
result = client.call_tool(
|
|
21
|
+
tool_name="causal_analysis",
|
|
22
|
+
params={"variables": ["X", "Y"]}
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- Tool discovery
|
|
29
|
+
- Tool execution
|
|
30
|
+
- Protocol handling
|
|
31
|
+
|
|
32
|
+
## Next Steps
|
|
33
|
+
|
|
34
|
+
- [Branches](../branches/crca-q/overview.md) - Specialized branches
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Tools Overview
|
|
2
|
+
|
|
3
|
+
The `tools/` module provides external tool integration for CR-CA.
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- **[MCP Client](mcp-client.md)**: Model Context Protocol client utilities
|
|
8
|
+
|
|
9
|
+
## MCP Integration
|
|
10
|
+
|
|
11
|
+
CR-CA integrates with MCP (Model Context Protocol) servers for extended functionality.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from tools.mcp_client import MCPClient
|
|
17
|
+
|
|
18
|
+
client = MCPClient(server_url="http://localhost:8000")
|
|
19
|
+
result = client.call_tool("tool_name", params={})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Next Steps
|
|
23
|
+
|
|
24
|
+
- [MCP Client](mcp-client.md) - MCP client utilities
|