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,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hybrid Agent Dictionary Integration Demo
|
|
3
|
+
|
|
4
|
+
Demonstrates the online dictionary integration (Free Dictionary API - no API key required).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from architecture.hybrid.hybrid_agent import HybridAgent
|
|
8
|
+
from architecture.hybrid.language_compiler import LexicalCompiler
|
|
9
|
+
|
|
10
|
+
# ============================================================================
|
|
11
|
+
# EXAMPLE 1: Dictionary Lookup
|
|
12
|
+
# ============================================================================
|
|
13
|
+
|
|
14
|
+
print("=== Example 1: Dictionary Lookup ===\n")
|
|
15
|
+
|
|
16
|
+
compiler = LexicalCompiler(enable_dictionary=True)
|
|
17
|
+
|
|
18
|
+
# Look up word information
|
|
19
|
+
word_info = compiler.get_word_info("price")
|
|
20
|
+
if word_info and word_info.get('found'):
|
|
21
|
+
print(f"Word: {word_info['word']}")
|
|
22
|
+
print(f"Part of Speech: {word_info['part_of_speech']}")
|
|
23
|
+
print(f"Synonyms: {list(word_info['synonyms'])[:5]}")
|
|
24
|
+
print()
|
|
25
|
+
|
|
26
|
+
# ============================================================================
|
|
27
|
+
# EXAMPLE 2: Validate Words
|
|
28
|
+
# ============================================================================
|
|
29
|
+
|
|
30
|
+
print("=== Example 2: Word Validation ===\n")
|
|
31
|
+
|
|
32
|
+
words_to_check = ["price", "demand", "xyzabc123", "identify", "policy"]
|
|
33
|
+
|
|
34
|
+
for word in words_to_check:
|
|
35
|
+
is_valid = compiler.is_valid_word(word)
|
|
36
|
+
pos = compiler.get_part_of_speech(word)
|
|
37
|
+
is_verb = compiler.is_action_verb(word)
|
|
38
|
+
is_noun = compiler.is_noun(word)
|
|
39
|
+
|
|
40
|
+
print(f"'{word}':")
|
|
41
|
+
print(f" Valid: {is_valid}")
|
|
42
|
+
print(f" Part of Speech: {pos}")
|
|
43
|
+
print(f" Is Verb: {is_verb}")
|
|
44
|
+
print(f" Is Noun: {is_noun}")
|
|
45
|
+
print()
|
|
46
|
+
|
|
47
|
+
# ============================================================================
|
|
48
|
+
# EXAMPLE 3: Get Synonyms
|
|
49
|
+
# ============================================================================
|
|
50
|
+
|
|
51
|
+
print("=== Example 3: Synonym Expansion ===\n")
|
|
52
|
+
|
|
53
|
+
word = "price"
|
|
54
|
+
synonyms = compiler.get_synonyms(word)
|
|
55
|
+
print(f"Synonyms for '{word}': {list(synonyms)[:10]}")
|
|
56
|
+
print()
|
|
57
|
+
|
|
58
|
+
# ============================================================================
|
|
59
|
+
# EXAMPLE 4: Dictionary-Enhanced Variable Filtering
|
|
60
|
+
# ============================================================================
|
|
61
|
+
|
|
62
|
+
print("=== Example 4: Dictionary-Enhanced Agent ===\n")
|
|
63
|
+
|
|
64
|
+
agent = HybridAgent(
|
|
65
|
+
enable_language_compilation=True, # Enables dictionary
|
|
66
|
+
enable_error_correction=True
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Test with a task that has some invalid words
|
|
70
|
+
task = "If product prce is 20000 and demnad is 61%, what is the expected price?"
|
|
71
|
+
|
|
72
|
+
response = agent.run(task, response_style='conversational')
|
|
73
|
+
print(f"Task: {task}")
|
|
74
|
+
print(f"\nResponse:\n{response[:500]}...")
|
|
75
|
+
print()
|
|
76
|
+
|
|
77
|
+
# ============================================================================
|
|
78
|
+
# EXAMPLE 5: Dictionary Cache
|
|
79
|
+
# ============================================================================
|
|
80
|
+
|
|
81
|
+
print("=== Example 5: Dictionary Caching ===\n")
|
|
82
|
+
|
|
83
|
+
# First lookup (will make API call)
|
|
84
|
+
import time
|
|
85
|
+
start = time.time()
|
|
86
|
+
info1 = compiler.get_word_info("demand")
|
|
87
|
+
time1 = time.time() - start
|
|
88
|
+
|
|
89
|
+
# Second lookup (will use cache)
|
|
90
|
+
start = time.time()
|
|
91
|
+
info2 = compiler.get_word_info("demand")
|
|
92
|
+
time2 = time.time() - start
|
|
93
|
+
|
|
94
|
+
print(f"First lookup: {time1:.3f}s")
|
|
95
|
+
print(f"Cached lookup: {time2:.3f}s")
|
|
96
|
+
print(f"Cache speedup: {time1/time2:.1f}x faster")
|
|
97
|
+
print()
|
|
98
|
+
|
|
99
|
+
print("Dictionary integration complete!")
|
|
100
|
+
print("The hybrid agent now uses online dictionary (no API key required) for:")
|
|
101
|
+
print("- Word validation")
|
|
102
|
+
print("- Part of speech detection")
|
|
103
|
+
print("- Synonym expansion")
|
|
104
|
+
print("- Better spelling correction")
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Enhanced Hybrid Agent Usage Examples
|
|
3
|
+
|
|
4
|
+
Demonstrates the enhanced hybrid agent that can replace LLMs entirely
|
|
5
|
+
for causal reasoning tasks with natural language interaction.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from architecture.hybrid.hybrid_agent import HybridAgent
|
|
9
|
+
|
|
10
|
+
# ============================================================================
|
|
11
|
+
# EXAMPLE 1: Basic Usage (Conversational Response)
|
|
12
|
+
# ============================================================================
|
|
13
|
+
|
|
14
|
+
agent = HybridAgent()
|
|
15
|
+
response = agent.run("If product price is 20000 and demand is 61%, what is the expected price in 7 days?")
|
|
16
|
+
print("=== Example 1: Basic Usage ===")
|
|
17
|
+
print(response)
|
|
18
|
+
print("\n")
|
|
19
|
+
|
|
20
|
+
# ============================================================================
|
|
21
|
+
# EXAMPLE 2: Different Response Styles
|
|
22
|
+
# ============================================================================
|
|
23
|
+
|
|
24
|
+
task = "Product quality affects customer satisfaction, which influences sales revenue"
|
|
25
|
+
|
|
26
|
+
# Conversational (default - natural, LLM-like)
|
|
27
|
+
response_conv = agent.run(task, response_style='conversational')
|
|
28
|
+
print("=== Example 2a: Conversational Style ===")
|
|
29
|
+
print(response_conv)
|
|
30
|
+
print("\n")
|
|
31
|
+
|
|
32
|
+
# Brief summary
|
|
33
|
+
response_brief = agent.run(task, response_style='brief')
|
|
34
|
+
print("=== Example 2b: Brief Style ===")
|
|
35
|
+
print(response_brief)
|
|
36
|
+
print("\n")
|
|
37
|
+
|
|
38
|
+
# Full analysis
|
|
39
|
+
response_full = agent.run(task, response_style='full')
|
|
40
|
+
print("=== Example 2c: Full Style ===")
|
|
41
|
+
print(response_full[:500] + "...") # Truncate for display
|
|
42
|
+
print("\n")
|
|
43
|
+
|
|
44
|
+
# ============================================================================
|
|
45
|
+
# EXAMPLE 3: Graph-First Query
|
|
46
|
+
# ============================================================================
|
|
47
|
+
|
|
48
|
+
# Build graph first
|
|
49
|
+
agent.run("Price depends on demand. Demand affects supply. Supply influences cost.")
|
|
50
|
+
|
|
51
|
+
# Query graph directly
|
|
52
|
+
graph_result = agent.query_graph("What is the relationship between price and cost?")
|
|
53
|
+
print("=== Example 3: Graph-First Query ===")
|
|
54
|
+
print(graph_result)
|
|
55
|
+
print("\n")
|
|
56
|
+
|
|
57
|
+
# ============================================================================
|
|
58
|
+
# EXAMPLE 4: Error Handling (Stability)
|
|
59
|
+
# ============================================================================
|
|
60
|
+
|
|
61
|
+
# Empty input
|
|
62
|
+
response = agent.run("")
|
|
63
|
+
print("=== Example 4a: Empty Input ===")
|
|
64
|
+
print(response)
|
|
65
|
+
print("\n")
|
|
66
|
+
|
|
67
|
+
# Invalid input
|
|
68
|
+
response = agent.run(None) # Will be caught and handled gracefully
|
|
69
|
+
print("=== Example 4b: Invalid Input ===")
|
|
70
|
+
print(response)
|
|
71
|
+
print("\n")
|
|
72
|
+
|
|
73
|
+
# ============================================================================
|
|
74
|
+
# EXAMPLE 5: Complex Causal Chain
|
|
75
|
+
# ============================================================================
|
|
76
|
+
|
|
77
|
+
complex_task = """
|
|
78
|
+
If marketing spend increases by 20%, brand awareness improves,
|
|
79
|
+
which leads to higher customer acquisition. Customer acquisition
|
|
80
|
+
affects revenue, and revenue influences profit margins.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
response = agent.run(complex_task, response_style='conversational')
|
|
84
|
+
print("=== Example 5: Complex Causal Chain ===")
|
|
85
|
+
print(response)
|
|
86
|
+
print("\n")
|
|
87
|
+
|
|
88
|
+
# ============================================================================
|
|
89
|
+
# EXAMPLE 6: Question Answering
|
|
90
|
+
# ============================================================================
|
|
91
|
+
|
|
92
|
+
agent.run("Temperature affects pressure. Pressure influences flow rate.")
|
|
93
|
+
|
|
94
|
+
question = "How does temperature affect flow rate?"
|
|
95
|
+
response = agent.run(question, response_style='conversational')
|
|
96
|
+
print("=== Example 6: Question Answering ===")
|
|
97
|
+
print(response)
|
|
98
|
+
print("\n")
|
|
99
|
+
|
|
100
|
+
# ============================================================================
|
|
101
|
+
# EXAMPLE 7: Counterfactual Analysis
|
|
102
|
+
# ============================================================================
|
|
103
|
+
|
|
104
|
+
counterfactual_task = """
|
|
105
|
+
If we increase employee training by 30%, productivity improves by 15%.
|
|
106
|
+
Productivity affects output quality, which influences customer satisfaction.
|
|
107
|
+
What if we increase training by 50% instead?
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
response = agent.run(counterfactual_task, response_style='conversational')
|
|
111
|
+
print("=== Example 7: Counterfactual Analysis ===")
|
|
112
|
+
print(response[:800] + "...") # Truncate for display
|
|
113
|
+
print("\n")
|
|
114
|
+
|
|
115
|
+
# ============================================================================
|
|
116
|
+
# EXAMPLE 8: Text Correction (Handles Typos)
|
|
117
|
+
# ============================================================================
|
|
118
|
+
|
|
119
|
+
typo_task = "Prce depnds on demnad and suply affects cost" # Intentional typos
|
|
120
|
+
response = agent.run(typo_task, response_style='conversational')
|
|
121
|
+
print("=== Example 8: Text Correction (Typos) ===")
|
|
122
|
+
print(response)
|
|
123
|
+
print("\n")
|
|
124
|
+
|
|
125
|
+
# ============================================================================
|
|
126
|
+
# EXAMPLE 9: Multi-Turn Conversation
|
|
127
|
+
# ============================================================================
|
|
128
|
+
|
|
129
|
+
print("=== Example 9: Multi-Turn Conversation ===")
|
|
130
|
+
|
|
131
|
+
# Turn 1: Establish context
|
|
132
|
+
agent.run("Customer satisfaction depends on product quality and service quality.")
|
|
133
|
+
|
|
134
|
+
# Turn 2: Ask question
|
|
135
|
+
response1 = agent.run("What affects customer satisfaction?", response_style='conversational')
|
|
136
|
+
print("Q: What affects customer satisfaction?")
|
|
137
|
+
print(f"A: {response1[:200]}...\n")
|
|
138
|
+
|
|
139
|
+
# Turn 3: Follow-up
|
|
140
|
+
response2 = agent.run("How does product quality affect it?", response_style='conversational')
|
|
141
|
+
print("Q: How does product quality affect it?")
|
|
142
|
+
print(f"A: {response2[:200]}...\n")
|
|
143
|
+
|
|
144
|
+
# ============================================================================
|
|
145
|
+
# EXAMPLE 10: Production-Ready Usage
|
|
146
|
+
# ============================================================================
|
|
147
|
+
|
|
148
|
+
def analyze_causal_relationship(description: str) -> str:
|
|
149
|
+
"""
|
|
150
|
+
Production-ready function for causal analysis.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
description: Natural language description of causal relationships
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
Analysis result as natural language
|
|
157
|
+
"""
|
|
158
|
+
agent = HybridAgent(
|
|
159
|
+
enable_graph_first=True,
|
|
160
|
+
enable_compression=True,
|
|
161
|
+
enable_language_compilation=True,
|
|
162
|
+
enable_error_correction=True
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
return agent.run(description, response_style='conversational')
|
|
167
|
+
except Exception as e:
|
|
168
|
+
return f"Analysis failed: {str(e)}"
|
|
169
|
+
|
|
170
|
+
# Usage
|
|
171
|
+
result = analyze_causal_relationship(
|
|
172
|
+
"Employee motivation drives productivity. Productivity affects company revenue."
|
|
173
|
+
)
|
|
174
|
+
print("=== Example 10: Production-Ready Function ===")
|
|
175
|
+
print(result)
|
|
176
|
+
print("\n")
|
|
177
|
+
|
|
178
|
+
print("All examples completed successfully!")
|
|
179
|
+
print("\nThe hybrid agent can now replace LLMs for causal reasoning tasks!")
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Enhanced Hybrid Agent - General Knowledge Examples
|
|
3
|
+
|
|
4
|
+
Demonstrates the hybrid agent's ability to handle general knowledge tasks,
|
|
5
|
+
not just causal reasoning. Shows taxonomic, spatial, temporal, and definitional relationships.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from architecture.hybrid.hybrid_agent import HybridAgent
|
|
9
|
+
|
|
10
|
+
# ============================================================================
|
|
11
|
+
# EXAMPLE 1: Taxonomic Relationships (Is-A)
|
|
12
|
+
# ============================================================================
|
|
13
|
+
|
|
14
|
+
agent = HybridAgent(graph_type="knowledge") # Use knowledge graph type
|
|
15
|
+
response = agent.run("A dog is a mammal. A mammal is an animal.")
|
|
16
|
+
print("=== Example 1: Taxonomic Relationships ===")
|
|
17
|
+
print(response)
|
|
18
|
+
print("\n")
|
|
19
|
+
|
|
20
|
+
# ============================================================================
|
|
21
|
+
# EXAMPLE 2: Spatial Relationships
|
|
22
|
+
# ============================================================================
|
|
23
|
+
|
|
24
|
+
response = agent.run("Paris is in France. France is in Europe.")
|
|
25
|
+
print("=== Example 2: Spatial Relationships ===")
|
|
26
|
+
print(response)
|
|
27
|
+
print("\n")
|
|
28
|
+
|
|
29
|
+
# ============================================================================
|
|
30
|
+
# EXAMPLE 3: Definitions
|
|
31
|
+
# ============================================================================
|
|
32
|
+
|
|
33
|
+
response = agent.run("What is a mammal?")
|
|
34
|
+
print("=== Example 3: Definition Query ===")
|
|
35
|
+
print(response)
|
|
36
|
+
print("\n")
|
|
37
|
+
|
|
38
|
+
# ============================================================================
|
|
39
|
+
# EXAMPLE 4: Mixed Causal and General Knowledge
|
|
40
|
+
# ============================================================================
|
|
41
|
+
|
|
42
|
+
agent_mixed = HybridAgent(graph_type="mixed") # Mixed graph type
|
|
43
|
+
response = agent_mixed.run("Price depends on demand. A product is a good. Demand affects sales.")
|
|
44
|
+
print("=== Example 4: Mixed Relationships ===")
|
|
45
|
+
print(response)
|
|
46
|
+
print("\n")
|
|
47
|
+
|
|
48
|
+
# ============================================================================
|
|
49
|
+
# EXAMPLE 5: Part-Whole Relationships
|
|
50
|
+
# ============================================================================
|
|
51
|
+
|
|
52
|
+
response = agent.run("A wheel is part of a car. A car has an engine.")
|
|
53
|
+
print("=== Example 5: Part-Whole Relationships ===")
|
|
54
|
+
print(response)
|
|
55
|
+
print("\n")
|
|
56
|
+
|
|
57
|
+
# ============================================================================
|
|
58
|
+
# EXAMPLE 6: Temporal Relationships
|
|
59
|
+
# ============================================================================
|
|
60
|
+
|
|
61
|
+
response = agent.run("Spring occurs before summer. Summer happens after spring.")
|
|
62
|
+
print("=== Example 6: Temporal Relationships ===")
|
|
63
|
+
print(response)
|
|
64
|
+
print("\n")
|
|
65
|
+
|
|
66
|
+
# ============================================================================
|
|
67
|
+
# EXAMPLE 7: Functional Relationships
|
|
68
|
+
# ============================================================================
|
|
69
|
+
|
|
70
|
+
response = agent.run("A hammer is used for hitting nails. A pen functions as a writing tool.")
|
|
71
|
+
print("=== Example 7: Functional Relationships ===")
|
|
72
|
+
print(response)
|
|
73
|
+
print("\n")
|
|
74
|
+
|
|
75
|
+
# ============================================================================
|
|
76
|
+
# EXAMPLE 8: Complex General Knowledge Query
|
|
77
|
+
# ============================================================================
|
|
78
|
+
|
|
79
|
+
response = agent.run("What is Paris? Where is it located?")
|
|
80
|
+
print("=== Example 8: Complex General Knowledge Query ===")
|
|
81
|
+
print(response)
|
|
82
|
+
print("\n")
|
|
83
|
+
|
|
84
|
+
# ============================================================================
|
|
85
|
+
# EXAMPLE 9: Conversational General Knowledge
|
|
86
|
+
# ============================================================================
|
|
87
|
+
|
|
88
|
+
# First message
|
|
89
|
+
response1 = agent.run("A cat is a mammal.")
|
|
90
|
+
print("=== Example 9a: First Message ===")
|
|
91
|
+
print(response1)
|
|
92
|
+
print("\n")
|
|
93
|
+
|
|
94
|
+
# Follow-up with reference
|
|
95
|
+
response2 = agent.run("What else is a mammal?")
|
|
96
|
+
print("=== Example 9b: Follow-up with Reference ===")
|
|
97
|
+
print(response2)
|
|
98
|
+
print("\n")
|
|
99
|
+
|
|
100
|
+
# ============================================================================
|
|
101
|
+
# EXAMPLE 10: Show Reasoning for General Knowledge
|
|
102
|
+
# ============================================================================
|
|
103
|
+
|
|
104
|
+
response = agent.run("A bird is an animal. An animal is a living thing.", show_reasoning=True)
|
|
105
|
+
print("=== Example 10: General Knowledge with Reasoning ===")
|
|
106
|
+
print(response)
|
|
107
|
+
print("\n")
|