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
CRCA.py
CHANGED
|
@@ -72,6 +72,20 @@ except ImportError:
|
|
|
72
72
|
# Fallback if prompt file doesn't exist
|
|
73
73
|
DEFAULT_CRCA_SYSTEM_PROMPT = None
|
|
74
74
|
|
|
75
|
+
# Image annotation imports (optional - graceful fallback if not available)
|
|
76
|
+
try:
|
|
77
|
+
from image_annotation.annotation_engine import ImageAnnotationEngine
|
|
78
|
+
IMAGE_ANNOTATION_AVAILABLE = True
|
|
79
|
+
except ImportError:
|
|
80
|
+
IMAGE_ANNOTATION_AVAILABLE = False
|
|
81
|
+
logger.debug("Image annotation engine not available")
|
|
82
|
+
except Exception as e:
|
|
83
|
+
IMAGE_ANNOTATION_AVAILABLE = False
|
|
84
|
+
logger.warning(f"Image annotation engine import failed: {e}")
|
|
85
|
+
|
|
86
|
+
# Global singleton for image annotation engine (lazy-loaded)
|
|
87
|
+
_image_annotation_engine: Optional[Any] = None
|
|
88
|
+
|
|
75
89
|
# Policy engine imports (optional - only if policy_mode is enabled)
|
|
76
90
|
try:
|
|
77
91
|
from schemas.policy import DoctrineV1
|
|
@@ -771,9 +785,20 @@ class CRCAAgent(Agent):
|
|
|
771
785
|
**kwargs: Additional arguments passed to parent Agent class
|
|
772
786
|
"""
|
|
773
787
|
|
|
788
|
+
env_model = os.getenv("CRCA_MOE_MODEL") or os.getenv("CRCA_LLM_MODEL")
|
|
789
|
+
if env_model and model_name == "gpt-4o":
|
|
790
|
+
model_name = env_model
|
|
791
|
+
|
|
774
792
|
cr_ca_schema = CRCAAgent._get_cr_ca_schema()
|
|
775
793
|
extract_variables_schema = CRCAAgent._get_extract_variables_schema()
|
|
776
794
|
|
|
795
|
+
# Get image annotation schemas if available
|
|
796
|
+
image_annotation_schema = None
|
|
797
|
+
image_query_schema = None
|
|
798
|
+
if IMAGE_ANNOTATION_AVAILABLE:
|
|
799
|
+
image_annotation_schema = CRCAAgent._get_image_annotation_schema()
|
|
800
|
+
image_query_schema = CRCAAgent._get_image_query_schema()
|
|
801
|
+
|
|
777
802
|
# Backwards-compatible alias for description
|
|
778
803
|
agent_description = description or agent_description
|
|
779
804
|
|
|
@@ -788,15 +813,18 @@ class CRCAAgent(Agent):
|
|
|
788
813
|
# Merge tools_list_dictionary from kwargs with CRCA schema
|
|
789
814
|
# Only add CRCA schema if user hasn't explicitly disabled it
|
|
790
815
|
use_crca_tools = kwargs.pop("use_crca_tools", True) # Default to True for backwards compatibility
|
|
816
|
+
use_image_annotation = kwargs.pop("use_image_annotation", True) # Default to True if available
|
|
791
817
|
existing_tools = kwargs.pop("tools_list_dictionary", [])
|
|
792
818
|
if not isinstance(existing_tools, list):
|
|
793
819
|
existing_tools = [existing_tools] if existing_tools else []
|
|
794
820
|
|
|
795
|
-
#
|
|
821
|
+
# Build tools list
|
|
822
|
+
tools_list = []
|
|
796
823
|
if use_crca_tools:
|
|
797
|
-
tools_list
|
|
798
|
-
|
|
799
|
-
tools_list
|
|
824
|
+
tools_list.extend([cr_ca_schema, extract_variables_schema])
|
|
825
|
+
if use_image_annotation and IMAGE_ANNOTATION_AVAILABLE and image_annotation_schema and image_query_schema:
|
|
826
|
+
tools_list.extend([image_annotation_schema, image_query_schema])
|
|
827
|
+
tools_list.extend(existing_tools)
|
|
800
828
|
|
|
801
829
|
# Get existing callable tools (functions) from kwargs
|
|
802
830
|
existing_callable_tools = kwargs.pop("tools", [])
|
|
@@ -844,6 +872,9 @@ class CRCAAgent(Agent):
|
|
|
844
872
|
super().__init__(**agent_kwargs)
|
|
845
873
|
|
|
846
874
|
# Now that self exists, create and add the CRCA tool handlers if tools are enabled
|
|
875
|
+
# Store use_image_annotation for later use
|
|
876
|
+
self._use_image_annotation = use_image_annotation if IMAGE_ANNOTATION_AVAILABLE else False
|
|
877
|
+
|
|
847
878
|
if use_crca_tools:
|
|
848
879
|
# Create a wrapper function with the correct name that matches the schema
|
|
849
880
|
def generate_causal_analysis(
|
|
@@ -886,17 +917,77 @@ class CRCAAgent(Agent):
|
|
|
886
917
|
self.add_tool(generate_causal_analysis)
|
|
887
918
|
self.add_tool(extract_causal_variables)
|
|
888
919
|
|
|
920
|
+
# Add image annotation tools if available
|
|
921
|
+
if self._use_image_annotation and IMAGE_ANNOTATION_AVAILABLE:
|
|
922
|
+
def annotate_image(
|
|
923
|
+
image_path: str,
|
|
924
|
+
output_format: str = "all",
|
|
925
|
+
frame_id: Optional[int] = None
|
|
926
|
+
) -> Dict[str, Any]:
|
|
927
|
+
"""Tool handler for annotate_image."""
|
|
928
|
+
engine = CRCAAgent._get_image_annotation_engine()
|
|
929
|
+
if engine is None:
|
|
930
|
+
return {"error": "Image annotation engine not available"}
|
|
931
|
+
try:
|
|
932
|
+
result = engine.annotate(image_path, frame_id=frame_id, output=output_format)
|
|
933
|
+
if output_format == "overlay":
|
|
934
|
+
return {"overlay_image": "numpy array returned", "shape": str(result.shape) if hasattr(result, 'shape') else "unknown"}
|
|
935
|
+
elif output_format == "json":
|
|
936
|
+
return result
|
|
937
|
+
elif output_format == "report":
|
|
938
|
+
return {"report": result}
|
|
939
|
+
else: # all
|
|
940
|
+
return {
|
|
941
|
+
"entities": len(result.annotation_graph.entities),
|
|
942
|
+
"labels": len(result.annotation_graph.labels),
|
|
943
|
+
"contradictions": len(result.annotation_graph.contradictions),
|
|
944
|
+
"processing_time": result.processing_time,
|
|
945
|
+
"formal_report": result.formal_report[:500] + "..." if len(result.formal_report) > 500 else result.formal_report,
|
|
946
|
+
"json_summary": {k: str(v)[:200] for k, v in list(result.json_output.items())[:5]}
|
|
947
|
+
}
|
|
948
|
+
except Exception as e:
|
|
949
|
+
logger.error(f"Error in annotate_image tool: {e}")
|
|
950
|
+
return {"error": str(e)}
|
|
951
|
+
|
|
952
|
+
def query_image(
|
|
953
|
+
image_path: str,
|
|
954
|
+
query: str,
|
|
955
|
+
frame_id: Optional[int] = None
|
|
956
|
+
) -> Dict[str, Any]:
|
|
957
|
+
"""Tool handler for query_image."""
|
|
958
|
+
engine = CRCAAgent._get_image_annotation_engine()
|
|
959
|
+
if engine is None:
|
|
960
|
+
return {"error": "Image annotation engine not available"}
|
|
961
|
+
try:
|
|
962
|
+
result = engine.query(image_path, query, frame_id=frame_id)
|
|
963
|
+
return {
|
|
964
|
+
"answer": result["answer"],
|
|
965
|
+
"entities_found": len(result["entities"]),
|
|
966
|
+
"measurements": result["measurements"],
|
|
967
|
+
"confidence": result["confidence"],
|
|
968
|
+
"reasoning": result["reasoning"][:500] + "..." if len(result["reasoning"]) > 500 else result["reasoning"]
|
|
969
|
+
}
|
|
970
|
+
except Exception as e:
|
|
971
|
+
logger.error(f"Error in query_image tool: {e}")
|
|
972
|
+
return {"error": str(e)}
|
|
973
|
+
|
|
974
|
+
self.add_tool(annotate_image)
|
|
975
|
+
self.add_tool(query_image)
|
|
976
|
+
|
|
889
977
|
# CRITICAL: Re-initialize tool_struct after adding tools
|
|
890
978
|
# This ensures the BaseTool instance has the updated tools and function_map
|
|
891
979
|
if hasattr(self, 'setup_tools'):
|
|
892
980
|
self.tool_struct = self.setup_tools()
|
|
893
981
|
|
|
894
982
|
# Ensure tools_list_dictionary is set with our manual schemas
|
|
983
|
+
our_tool_names = {"generate_causal_analysis", "extract_causal_variables"}
|
|
984
|
+
if self._use_image_annotation and IMAGE_ANNOTATION_AVAILABLE:
|
|
985
|
+
our_tool_names.update({"annotate_image", "query_image"})
|
|
986
|
+
|
|
895
987
|
if not self.tools_list_dictionary or len(self.tools_list_dictionary) == 0:
|
|
896
|
-
self.tools_list_dictionary =
|
|
988
|
+
self.tools_list_dictionary = tools_list
|
|
897
989
|
else:
|
|
898
990
|
# Replace any auto-generated schemas with our manual ones
|
|
899
|
-
our_tool_names = {"generate_causal_analysis", "extract_causal_variables"}
|
|
900
991
|
filtered = []
|
|
901
992
|
for schema in self.tools_list_dictionary:
|
|
902
993
|
if isinstance(schema, dict):
|
|
@@ -905,7 +996,7 @@ class CRCAAgent(Agent):
|
|
|
905
996
|
continue # Skip auto-generated, we'll add manual
|
|
906
997
|
filtered.append(schema)
|
|
907
998
|
# Add our manual schemas first, then existing tools
|
|
908
|
-
self.tools_list_dictionary =
|
|
999
|
+
self.tools_list_dictionary = tools_list + filtered
|
|
909
1000
|
|
|
910
1001
|
self.causal_max_loops = max_loops
|
|
911
1002
|
self.causal_graph: Dict[str, Dict[str, float]] = {}
|
|
@@ -1073,6 +1164,80 @@ class CRCAAgent(Agent):
|
|
|
1073
1164
|
}
|
|
1074
1165
|
}
|
|
1075
1166
|
|
|
1167
|
+
@staticmethod
|
|
1168
|
+
def _get_image_annotation_schema() -> Dict[str, Any]:
|
|
1169
|
+
"""Get schema for annotate_image tool."""
|
|
1170
|
+
return {
|
|
1171
|
+
"type": "function",
|
|
1172
|
+
"function": {
|
|
1173
|
+
"name": "annotate_image",
|
|
1174
|
+
"description": "Annotate an image with geometric primitives, semantic labels, and measurements. Automatically detects image type, tunes parameters, and extracts primitives (lines, circles, contours). Returns overlay image, formal report, and JSON data.",
|
|
1175
|
+
"parameters": {
|
|
1176
|
+
"type": "object",
|
|
1177
|
+
"properties": {
|
|
1178
|
+
"image_path": {
|
|
1179
|
+
"type": "string",
|
|
1180
|
+
"description": "Path to image file, URL, or description of image location"
|
|
1181
|
+
},
|
|
1182
|
+
"output_format": {
|
|
1183
|
+
"type": "string",
|
|
1184
|
+
"enum": ["overlay", "json", "report", "all"],
|
|
1185
|
+
"default": "all",
|
|
1186
|
+
"description": "Output format: 'overlay' (numpy array), 'json' (structured data), 'report' (text), 'all' (AnnotationResult)"
|
|
1187
|
+
},
|
|
1188
|
+
"frame_id": {
|
|
1189
|
+
"type": "integer",
|
|
1190
|
+
"description": "Optional frame ID for temporal tracking in video sequences"
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
"required": ["image_path"]
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
@staticmethod
|
|
1199
|
+
def _get_image_query_schema() -> Dict[str, Any]:
|
|
1200
|
+
"""Get schema for query_image tool."""
|
|
1201
|
+
return {
|
|
1202
|
+
"type": "function",
|
|
1203
|
+
"function": {
|
|
1204
|
+
"name": "query_image",
|
|
1205
|
+
"description": "Answer a specific query about an image using natural language. Performs annotation first, then analyzes the results to answer questions like 'find the largest building', 'measure dimensions', 'count objects', etc.",
|
|
1206
|
+
"parameters": {
|
|
1207
|
+
"type": "object",
|
|
1208
|
+
"properties": {
|
|
1209
|
+
"image_path": {
|
|
1210
|
+
"type": "string",
|
|
1211
|
+
"description": "Path to image file, URL, or description of image location"
|
|
1212
|
+
},
|
|
1213
|
+
"query": {
|
|
1214
|
+
"type": "string",
|
|
1215
|
+
"description": "Natural language query about the image (e.g., 'find the largest building and measure its dimensions', 'count how many circles are in the image', 'identify all lines and measure their lengths')"
|
|
1216
|
+
},
|
|
1217
|
+
"frame_id": {
|
|
1218
|
+
"type": "integer",
|
|
1219
|
+
"description": "Optional frame ID for temporal tracking"
|
|
1220
|
+
}
|
|
1221
|
+
},
|
|
1222
|
+
"required": ["image_path", "query"]
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
@staticmethod
|
|
1228
|
+
def _get_image_annotation_engine() -> Optional[Any]:
|
|
1229
|
+
"""Get or create singleton image annotation engine instance."""
|
|
1230
|
+
global _image_annotation_engine
|
|
1231
|
+
if not IMAGE_ANNOTATION_AVAILABLE:
|
|
1232
|
+
return None
|
|
1233
|
+
if _image_annotation_engine is None:
|
|
1234
|
+
try:
|
|
1235
|
+
_image_annotation_engine = ImageAnnotationEngine()
|
|
1236
|
+
except Exception as e:
|
|
1237
|
+
logger.error(f"Failed to initialize image annotation engine: {e}")
|
|
1238
|
+
return None
|
|
1239
|
+
return _image_annotation_engine
|
|
1240
|
+
|
|
1076
1241
|
@staticmethod
|
|
1077
1242
|
def _get_extract_variables_schema() -> Dict[str, Any]:
|
|
1078
1243
|
"""
|
MODEL_CARD.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: en
|
|
3
|
+
license: apache-2.0
|
|
4
|
+
tags:
|
|
5
|
+
- reasoning
|
|
6
|
+
- react
|
|
7
|
+
- causal-inference
|
|
8
|
+
- tool-use
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# CR-CA LRM (draft model card)
|
|
12
|
+
|
|
13
|
+
## Model summary
|
|
14
|
+
This release pairs a **ReAct + self‑critique reasoning kernel** with a full-finetuned model.
|
|
15
|
+
The system is designed to **orchestrate tools** and **enforce refusal‑first causal outputs**.
|
|
16
|
+
|
|
17
|
+
**Base model:** Qwen2.5-7B-Instruct
|
|
18
|
+
**Finetune type:** full finetune (no LoRA adapters)
|
|
19
|
+
**Context length:** 8k
|
|
20
|
+
|
|
21
|
+
## Intended use
|
|
22
|
+
- Planning and reasoning over structured causal tasks.
|
|
23
|
+
- Tool‑augmented reasoning with strict gating.
|
|
24
|
+
|
|
25
|
+
## Limitations
|
|
26
|
+
- Numeric causal outputs are refused unless validated by `crca_core`.
|
|
27
|
+
- Reasoning traces are **non‑scientific** metadata and must not be treated as proofs.
|
|
28
|
+
|
|
29
|
+
## Training data
|
|
30
|
+
Hybrid dataset:
|
|
31
|
+
- Internal ReAct traces (reason/act/observe/critique) with refusal labels.
|
|
32
|
+
- Public reasoning datasets (see dataset builder config).
|
|
33
|
+
|
|
34
|
+
## Evaluation
|
|
35
|
+
Mixed evaluation:
|
|
36
|
+
- Refusal accuracy.
|
|
37
|
+
- ReAct cycle convergence.
|
|
38
|
+
- Causal identification correctness on synthetic SCMs.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
```python
|
|
42
|
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
43
|
+
|
|
44
|
+
model_id = "YOUR_HF_REPO"
|
|
45
|
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
46
|
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
|
47
|
+
|
|
48
|
+
prompt = "Reason step-by-step and propose a tool call."
|
|
49
|
+
inputs = tokenizer(prompt, return_tensors="pt")
|
|
50
|
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
|
51
|
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
52
|
+
```
|
|
53
|
+
|
PKG-INFO
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crca
|
|
3
|
-
Version: 1.
|
|
4
|
-
Summary: CR-CA
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: CR-CA Wrapper for CR-CA LRM on HF (Depricated)
|
|
5
5
|
Project-URL: Homepage, https://github.com/IlumCI/CR-CA
|
|
6
6
|
Project-URL: Repository, https://github.com/IlumCI/CR-CA
|
|
7
7
|
Project-URL: Documentation, https://github.com/IlumCI/CR-CA/blob/main/README.md
|
|
@@ -24,7 +24,10 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
24
24
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
26
|
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: accelerate>=0.26.0
|
|
28
|
+
Requires-Dist: causal-learn>=0.1.3.9
|
|
27
29
|
Requires-Dist: ccxt>=4.0
|
|
30
|
+
Requires-Dist: datasets>=2.16.0
|
|
28
31
|
Requires-Dist: dowhy>=0.8
|
|
29
32
|
Requires-Dist: geoip2>=4.7.0
|
|
30
33
|
Requires-Dist: lightgbm>=4.0
|
|
@@ -38,6 +41,7 @@ Requires-Dist: numpy>=1.23
|
|
|
38
41
|
Requires-Dist: openai>=1.0.0
|
|
39
42
|
Requires-Dist: optuna>=3.0
|
|
40
43
|
Requires-Dist: pandas>=1.5
|
|
44
|
+
Requires-Dist: peft>=0.9.0
|
|
41
45
|
Requires-Dist: pillow>=10.0
|
|
42
46
|
Requires-Dist: praw>=7.0
|
|
43
47
|
Requires-Dist: psutil>=5.9.0
|
|
@@ -57,9 +61,11 @@ Requires-Dist: scipy>=1.10
|
|
|
57
61
|
Requires-Dist: seaborn>=0.11
|
|
58
62
|
Requires-Dist: shodan>=1.30.0
|
|
59
63
|
Requires-Dist: swarms
|
|
64
|
+
Requires-Dist: tigramite>=5.2.0
|
|
60
65
|
Requires-Dist: toml>=0.10.2
|
|
61
66
|
Requires-Dist: torch>=2.0.0
|
|
62
67
|
Requires-Dist: tqdm>=4.65.0
|
|
68
|
+
Requires-Dist: transformers>=4.39.0
|
|
63
69
|
Requires-Dist: web3>=6.0
|
|
64
70
|
Requires-Dist: websockets>=11.0
|
|
65
71
|
Requires-Dist: xgboost>=2.0
|
RELEASE_NOTES.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## v1.0 Release Notes (draft)
|
|
2
|
+
|
|
3
|
+
### Core Features
|
|
4
|
+
- In-house identification with proof objects and conservative scope labeling.
|
|
5
|
+
- Real discovery backends: causal-learn (tabular) and tigramite (time-series).
|
|
6
|
+
- Linear-Gaussian SCM counterfactuals with partial-abduction mode (optional).
|
|
7
|
+
- Estimation/refutation gated by identification results.
|
|
8
|
+
- Schema exports + generated documentation + benchmark harness outputs.
|
|
9
|
+
|
|
10
|
+
### Non-Authoritative LLM Layer
|
|
11
|
+
- DraftSpec generation only.
|
|
12
|
+
- Tool orchestration is gated by LockedSpec and refusal rules.
|
|
13
|
+
|
|
14
|
+
### Known Limitations
|
|
15
|
+
- ID algorithm is conservative for latent-confounded cases.
|
|
16
|
+
- Discovery outputs are hypotheses and require assumptions.
|
|
17
|
+
|
STABILITY.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## CR-CA v1.0 Stability Policy
|
|
2
|
+
|
|
3
|
+
This document defines what **stable** means for the v1.0 release.
|
|
4
|
+
|
|
5
|
+
### Stable Guarantees
|
|
6
|
+
- **Structured outputs only**: all core results are JSON/Pydantic structures.
|
|
7
|
+
- **Refusal-first**: numeric causal outputs are refused unless prerequisites are met.
|
|
8
|
+
- **SCM-required counterfactuals**: counterfactuals require explicit structural equations.
|
|
9
|
+
- **Identification gating**: estimation requires an `IdentificationResult`.
|
|
10
|
+
|
|
11
|
+
### Known Limits (by design)
|
|
12
|
+
- **Identification is conservative**: latent-confounded cases often return non-identifiable.
|
|
13
|
+
- **Discovery is hypothesis-only**: outputs are not causal truth, only hypotheses under assumptions.
|
|
14
|
+
- **LLM layer is non-authoritative**: drafts and orchestration only; no numeric causal claims.
|
|
15
|
+
|
|
16
|
+
### Compatibility
|
|
17
|
+
- Schema contracts are versioned via the exported JSON schemas in `schemas_export/crca_core`.
|
|
18
|
+
- Changes that alter semantics must increment schema versions before release.
|
|
19
|
+
|