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,277 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example usage of GeneralAgent.
|
|
3
|
+
|
|
4
|
+
Demonstrates:
|
|
5
|
+
- Basic conversation
|
|
6
|
+
- Tool usage
|
|
7
|
+
- Agent routing (auto-discovered)
|
|
8
|
+
- Code execution
|
|
9
|
+
- Multimodal inputs
|
|
10
|
+
- Async operations
|
|
11
|
+
- Batch processing
|
|
12
|
+
- Custom personality configuration
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
from loguru import logger
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from branches.general_agent import GeneralAgent, get_personality, create_custom_personality
|
|
20
|
+
GENERAL_AGENT_AVAILABLE = True
|
|
21
|
+
except ImportError:
|
|
22
|
+
logger.error("GeneralAgent not available. Please ensure all dependencies are installed.")
|
|
23
|
+
GENERAL_AGENT_AVAILABLE = False
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def example_basic_conversation():
|
|
27
|
+
"""Example: Basic conversation with GeneralAgent."""
|
|
28
|
+
print("\n=== Example 1: Basic Conversation ===\n")
|
|
29
|
+
|
|
30
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
31
|
+
print("GeneralAgent not available")
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
# Create agent with default settings
|
|
35
|
+
agent = GeneralAgent(
|
|
36
|
+
agent_name="example-agent",
|
|
37
|
+
model_name="gpt-4o-mini",
|
|
38
|
+
personality="neutral",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Simple conversation
|
|
42
|
+
response = agent.run("Hello! Can you explain what you can do?")
|
|
43
|
+
print(f"Agent: {response}\n")
|
|
44
|
+
|
|
45
|
+
# Continue conversation
|
|
46
|
+
response = agent.run("What's the weather like?")
|
|
47
|
+
print(f"Agent: {response}\n")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def example_custom_personality():
|
|
51
|
+
"""Example: Using custom personality."""
|
|
52
|
+
print("\n=== Example 2: Custom Personality ===\n")
|
|
53
|
+
|
|
54
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
55
|
+
print("GeneralAgent not available")
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
# Create agent with friendly personality
|
|
59
|
+
agent = GeneralAgent(
|
|
60
|
+
agent_name="friendly-agent",
|
|
61
|
+
personality="friendly",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
response = agent.run("Tell me a joke!")
|
|
65
|
+
print(f"Friendly Agent: {response}\n")
|
|
66
|
+
|
|
67
|
+
# Create agent with technical personality
|
|
68
|
+
agent = GeneralAgent(
|
|
69
|
+
agent_name="technical-agent",
|
|
70
|
+
personality="technical",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
response = agent.run("Explain how neural networks work")
|
|
74
|
+
print(f"Technical Agent: {response}\n")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def example_async_operations():
|
|
78
|
+
"""Example: Async operations."""
|
|
79
|
+
print("\n=== Example 3: Async Operations ===\n")
|
|
80
|
+
|
|
81
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
82
|
+
print("GeneralAgent not available")
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
async def run_async_example():
|
|
86
|
+
agent = GeneralAgent(
|
|
87
|
+
agent_name="async-agent",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Run async
|
|
91
|
+
response = await agent.run_async("What is 2+2?")
|
|
92
|
+
print(f"Async Response: {response}\n")
|
|
93
|
+
|
|
94
|
+
# Run multiple async tasks
|
|
95
|
+
tasks = [
|
|
96
|
+
"What is Python?",
|
|
97
|
+
"What is machine learning?",
|
|
98
|
+
"What is AI?",
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
responses = await asyncio.gather(*[agent.run_async(task) for task in tasks])
|
|
102
|
+
for task, response in zip(tasks, responses):
|
|
103
|
+
print(f"Task: {task}")
|
|
104
|
+
print(f"Response: {response}\n")
|
|
105
|
+
|
|
106
|
+
asyncio.run(run_async_example())
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def example_batch_processing():
|
|
110
|
+
"""Example: Batch processing."""
|
|
111
|
+
print("\n=== Example 4: Batch Processing ===\n")
|
|
112
|
+
|
|
113
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
114
|
+
print("GeneralAgent not available")
|
|
115
|
+
return
|
|
116
|
+
|
|
117
|
+
agent = GeneralAgent(
|
|
118
|
+
agent_name="batch-agent",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# Process batch of tasks
|
|
122
|
+
tasks = [
|
|
123
|
+
"Explain quantum computing",
|
|
124
|
+
"What is blockchain?",
|
|
125
|
+
"Describe machine learning",
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
results, stats = agent.run_batch(tasks)
|
|
129
|
+
|
|
130
|
+
print(f"Processed {len(results)} tasks")
|
|
131
|
+
if stats:
|
|
132
|
+
print(f"Stats: {stats}")
|
|
133
|
+
|
|
134
|
+
for i, (task, result) in enumerate(zip(tasks, results)):
|
|
135
|
+
print(f"\nTask {i+1}: {task}")
|
|
136
|
+
print(f"Result: {result}\n")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
async def example_async_batch():
|
|
140
|
+
"""Example: Async batch processing."""
|
|
141
|
+
print("\n=== Example 5: Async Batch Processing ===\n")
|
|
142
|
+
|
|
143
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
144
|
+
print("GeneralAgent not available")
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
agent = GeneralAgent(
|
|
148
|
+
agent_name="async-batch-agent",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
tasks = [
|
|
152
|
+
"What is Python?",
|
|
153
|
+
"What is JavaScript?",
|
|
154
|
+
"What is Rust?",
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
results, stats = await agent.run_batch_async(tasks)
|
|
158
|
+
|
|
159
|
+
print(f"Processed {len(results)} tasks asynchronously")
|
|
160
|
+
if stats:
|
|
161
|
+
print(f"Stats: {stats}")
|
|
162
|
+
|
|
163
|
+
for i, (task, result) in enumerate(zip(tasks, results)):
|
|
164
|
+
print(f"\nTask {i+1}: {task}")
|
|
165
|
+
print(f"Result: {result}\n")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def example_conversation_persistence():
|
|
169
|
+
"""Example: Conversation persistence."""
|
|
170
|
+
print("\n=== Example 6: Conversation Persistence ===\n")
|
|
171
|
+
|
|
172
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
173
|
+
print("GeneralAgent not available")
|
|
174
|
+
return
|
|
175
|
+
|
|
176
|
+
agent = GeneralAgent(
|
|
177
|
+
agent_name="persistent-agent",
|
|
178
|
+
enable_persistence=True,
|
|
179
|
+
persistence_path="example_conversation.json",
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
# Have a conversation
|
|
183
|
+
agent.run("Hello! My name is Alice.")
|
|
184
|
+
agent.run("What's my name?")
|
|
185
|
+
|
|
186
|
+
# Save conversation
|
|
187
|
+
agent.save_conversation()
|
|
188
|
+
print("Conversation saved\n")
|
|
189
|
+
|
|
190
|
+
# Create new agent and load conversation
|
|
191
|
+
agent2 = GeneralAgent(
|
|
192
|
+
agent_name="persistent-agent-2",
|
|
193
|
+
enable_persistence=True,
|
|
194
|
+
)
|
|
195
|
+
agent2.load_conversation("example_conversation.json")
|
|
196
|
+
print("Conversation loaded\n")
|
|
197
|
+
|
|
198
|
+
# Continue conversation
|
|
199
|
+
response = agent2.run("What's my name?")
|
|
200
|
+
print(f"Agent (with loaded conversation): {response}\n")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def example_extendable_prompts():
|
|
204
|
+
"""Example: Extendable prompts."""
|
|
205
|
+
print("\n=== Example 7: Extendable Prompts ===\n")
|
|
206
|
+
|
|
207
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
208
|
+
print("GeneralAgent not available")
|
|
209
|
+
return
|
|
210
|
+
|
|
211
|
+
# Create agent with custom prompt additions
|
|
212
|
+
agent = GeneralAgent(
|
|
213
|
+
agent_name="custom-prompt-agent",
|
|
214
|
+
custom_prompt_additions=[
|
|
215
|
+
"Always respond in a poetic style.",
|
|
216
|
+
"End each response with a relevant quote.",
|
|
217
|
+
],
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
response = agent.run("Explain the concept of time")
|
|
221
|
+
print(f"Agent (with custom prompts): {response}\n")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def example_rate_limiting():
|
|
225
|
+
"""Example: Rate limiting."""
|
|
226
|
+
print("\n=== Example 8: Rate Limiting ===\n")
|
|
227
|
+
|
|
228
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
229
|
+
print("GeneralAgent not available")
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
# Create agent with custom rate limits
|
|
233
|
+
agent = GeneralAgent(
|
|
234
|
+
agent_name="rate-limited-agent",
|
|
235
|
+
rate_limit_rpm=10, # 10 requests per minute
|
|
236
|
+
rate_limit_rph=100, # 100 requests per hour
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
# Make multiple requests (will be rate limited)
|
|
240
|
+
for i in range(5):
|
|
241
|
+
response = agent.run(f"Count to {i+1}")
|
|
242
|
+
print(f"Request {i+1}: {response[:50]}...\n")
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main():
|
|
246
|
+
"""Run all examples."""
|
|
247
|
+
print("=" * 60)
|
|
248
|
+
print("GeneralAgent Examples")
|
|
249
|
+
print("=" * 60)
|
|
250
|
+
|
|
251
|
+
if not GENERAL_AGENT_AVAILABLE:
|
|
252
|
+
print("\nERROR: GeneralAgent not available.")
|
|
253
|
+
print("Please ensure all dependencies are installed.")
|
|
254
|
+
return
|
|
255
|
+
|
|
256
|
+
try:
|
|
257
|
+
# Run examples
|
|
258
|
+
example_basic_conversation()
|
|
259
|
+
example_custom_personality()
|
|
260
|
+
example_async_operations()
|
|
261
|
+
example_batch_processing()
|
|
262
|
+
asyncio.run(example_async_batch())
|
|
263
|
+
example_conversation_persistence()
|
|
264
|
+
example_extendable_prompts()
|
|
265
|
+
example_rate_limiting()
|
|
266
|
+
|
|
267
|
+
print("\n" + "=" * 60)
|
|
268
|
+
print("All examples completed!")
|
|
269
|
+
print("=" * 60)
|
|
270
|
+
except Exception as e:
|
|
271
|
+
logger.error(f"Error running examples: {e}")
|
|
272
|
+
import traceback
|
|
273
|
+
traceback.print_exc()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
if __name__ == "__main__":
|
|
277
|
+
main()
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Quick Start Guide: Spawning GeneralAgent for Immediate Use
|
|
3
|
+
|
|
4
|
+
This file demonstrates the simplest ways to create and use the GeneralAgent.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from branches.general_agent import GeneralAgent
|
|
8
|
+
|
|
9
|
+
# ============================================================================
|
|
10
|
+
# METHOD 1: Simplest - Default Settings
|
|
11
|
+
# ============================================================================
|
|
12
|
+
|
|
13
|
+
def quick_start_minimal():
|
|
14
|
+
"""Minimal setup - just create and use."""
|
|
15
|
+
agent = GeneralAgent()
|
|
16
|
+
response = agent.run("Hello! What can you do?")
|
|
17
|
+
print(response)
|
|
18
|
+
return agent
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ============================================================================
|
|
22
|
+
# METHOD 2: With Custom Model
|
|
23
|
+
# ============================================================================
|
|
24
|
+
|
|
25
|
+
def quick_start_custom_model():
|
|
26
|
+
"""Create with custom model."""
|
|
27
|
+
agent = GeneralAgent(
|
|
28
|
+
model_name="gpt-4o", # or "gpt-4o-mini", "claude-3-5-sonnet", etc.
|
|
29
|
+
)
|
|
30
|
+
response = agent.run("Analyze the causal factors affecting product pricing.")
|
|
31
|
+
print(response)
|
|
32
|
+
return agent
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# ============================================================================
|
|
36
|
+
# METHOD 3: With Personality
|
|
37
|
+
# ============================================================================
|
|
38
|
+
|
|
39
|
+
def quick_start_with_personality():
|
|
40
|
+
"""Create with personality."""
|
|
41
|
+
agent = GeneralAgent(
|
|
42
|
+
personality="friendly", # or "neutral", "technical"
|
|
43
|
+
)
|
|
44
|
+
response = agent.run("Explain quantum computing in simple terms.")
|
|
45
|
+
print(response)
|
|
46
|
+
return agent
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# ============================================================================
|
|
50
|
+
# METHOD 4: Production-Ready Setup
|
|
51
|
+
# ============================================================================
|
|
52
|
+
|
|
53
|
+
def quick_start_production():
|
|
54
|
+
"""Production-ready setup with all features enabled."""
|
|
55
|
+
agent = GeneralAgent(
|
|
56
|
+
agent_name="production-agent",
|
|
57
|
+
model_name="gpt-4o-mini",
|
|
58
|
+
temperature=0.4,
|
|
59
|
+
personality="neutral",
|
|
60
|
+
enable_agent_routing="auto",
|
|
61
|
+
enable_code_execution=True,
|
|
62
|
+
enable_multimodal=True,
|
|
63
|
+
enable_streaming=True,
|
|
64
|
+
enable_persistence=True,
|
|
65
|
+
enable_causal_reasoning=True,
|
|
66
|
+
enable_file_operations=True,
|
|
67
|
+
persistence_path="./conversations/",
|
|
68
|
+
rate_limit_rpm=60,
|
|
69
|
+
rate_limit_rph=1000,
|
|
70
|
+
)
|
|
71
|
+
response = agent.run("Help me understand the causal relationships in my business model.")
|
|
72
|
+
print(response)
|
|
73
|
+
return agent
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ============================================================================
|
|
77
|
+
# METHOD 5: Using Helper Function
|
|
78
|
+
# ============================================================================
|
|
79
|
+
|
|
80
|
+
def quick_start_helper():
|
|
81
|
+
"""Using the get_general_agent helper function."""
|
|
82
|
+
from branches.general_agent import get_general_agent
|
|
83
|
+
|
|
84
|
+
agent = get_general_agent(
|
|
85
|
+
model_name="gpt-4o-mini",
|
|
86
|
+
personality="neutral",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if agent:
|
|
90
|
+
response = agent.run("What is causal reasoning?")
|
|
91
|
+
print(response)
|
|
92
|
+
return agent
|
|
93
|
+
else:
|
|
94
|
+
print("Failed to create agent")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ============================================================================
|
|
98
|
+
# METHOD 6: Async Usage
|
|
99
|
+
# ============================================================================
|
|
100
|
+
|
|
101
|
+
async def quick_start_async():
|
|
102
|
+
"""Async usage for concurrent operations."""
|
|
103
|
+
agent = GeneralAgent()
|
|
104
|
+
|
|
105
|
+
# Run async
|
|
106
|
+
response = await agent.run_async("Analyze this task using causal reasoning.")
|
|
107
|
+
print(response)
|
|
108
|
+
|
|
109
|
+
# Batch processing
|
|
110
|
+
tasks = [
|
|
111
|
+
"What factors affect sales?",
|
|
112
|
+
"Explain supply and demand relationships.",
|
|
113
|
+
"How does marketing impact revenue?",
|
|
114
|
+
]
|
|
115
|
+
results = await agent.run_batch_async(tasks)
|
|
116
|
+
for task, result in zip(tasks, results):
|
|
117
|
+
print(f"\nTask: {task}\nResult: {result}\n")
|
|
118
|
+
|
|
119
|
+
return agent
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ============================================================================
|
|
123
|
+
# METHOD 7: With Causal Reasoning Focus
|
|
124
|
+
# ============================================================================
|
|
125
|
+
|
|
126
|
+
def quick_start_causal_focus():
|
|
127
|
+
"""Create agent focused on causal reasoning tasks."""
|
|
128
|
+
agent = GeneralAgent(
|
|
129
|
+
model_name="gpt-4o",
|
|
130
|
+
personality="technical",
|
|
131
|
+
enable_causal_reasoning=True,
|
|
132
|
+
enable_agent_routing="auto", # Will route to CRCAAgent if needed
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# The agent will automatically use causal reasoning tools
|
|
136
|
+
response = agent.run(
|
|
137
|
+
"I want to understand what factors influence customer satisfaction. "
|
|
138
|
+
"Extract the causal variables and relationships."
|
|
139
|
+
)
|
|
140
|
+
print(response)
|
|
141
|
+
return agent
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ============================================================================
|
|
145
|
+
# METHOD 8: Minimal with Environment Variables
|
|
146
|
+
# ============================================================================
|
|
147
|
+
|
|
148
|
+
def quick_start_env_vars():
|
|
149
|
+
"""Create agent using environment variables for API keys."""
|
|
150
|
+
import os
|
|
151
|
+
|
|
152
|
+
# Set your API keys in environment (or use .env file)
|
|
153
|
+
# os.environ["OPENAI_API_KEY"] = "your-key-here"
|
|
154
|
+
# os.environ["ANTHROPIC_API_KEY"] = "your-key-here"
|
|
155
|
+
|
|
156
|
+
agent = GeneralAgent(
|
|
157
|
+
model_name="gpt-4o-mini",
|
|
158
|
+
)
|
|
159
|
+
response = agent.run("Hello!")
|
|
160
|
+
print(response)
|
|
161
|
+
return agent
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# ============================================================================
|
|
165
|
+
# MAIN: Run Examples
|
|
166
|
+
# ============================================================================
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
print("=" * 70)
|
|
170
|
+
print("GeneralAgent Quick Start Examples")
|
|
171
|
+
print("=" * 70)
|
|
172
|
+
|
|
173
|
+
# Uncomment the example you want to run:
|
|
174
|
+
|
|
175
|
+
# Example 1: Minimal
|
|
176
|
+
# quick_start_minimal()
|
|
177
|
+
|
|
178
|
+
# Example 2: Custom Model
|
|
179
|
+
# quick_start_custom_model()
|
|
180
|
+
|
|
181
|
+
# Example 3: With Personality
|
|
182
|
+
# quick_start_with_personality()
|
|
183
|
+
|
|
184
|
+
# Example 4: Production Setup
|
|
185
|
+
# quick_start_production()
|
|
186
|
+
|
|
187
|
+
# Example 5: Helper Function
|
|
188
|
+
# quick_start_helper()
|
|
189
|
+
|
|
190
|
+
# Example 6: Async (requires asyncio.run())
|
|
191
|
+
# import asyncio
|
|
192
|
+
# asyncio.run(quick_start_async())
|
|
193
|
+
|
|
194
|
+
# Example 7: Causal Reasoning Focus
|
|
195
|
+
# quick_start_causal_focus()
|
|
196
|
+
|
|
197
|
+
# Example 8: Environment Variables
|
|
198
|
+
# quick_start_env_vars()
|
|
199
|
+
|
|
200
|
+
print("\n" + "=" * 70)
|
|
201
|
+
print("Choose an example and uncomment it to run!")
|
|
202
|
+
print("=" * 70)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ultra-Simple GeneralAgent Usage Examples
|
|
3
|
+
|
|
4
|
+
All examples are under 10 lines of code (LOC).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# ============================================================================
|
|
8
|
+
# EXAMPLE 1: Simplest Possible (1 LOC)
|
|
9
|
+
# ============================================================================
|
|
10
|
+
|
|
11
|
+
from branches.general_agent import GeneralAgent
|
|
12
|
+
agent = GeneralAgent()
|
|
13
|
+
response = agent.run("Hello!")
|
|
14
|
+
print(response)
|
|
15
|
+
|
|
16
|
+
# ============================================================================
|
|
17
|
+
# EXAMPLE 2: With Model (2 LOC)
|
|
18
|
+
# ============================================================================
|
|
19
|
+
|
|
20
|
+
agent = GeneralAgent(model_name="gpt-4o")
|
|
21
|
+
response = agent.run("Explain causal reasoning.")
|
|
22
|
+
print(response)
|
|
23
|
+
|
|
24
|
+
# ============================================================================
|
|
25
|
+
# EXAMPLE 3: With Personality (2 LOC)
|
|
26
|
+
# ============================================================================
|
|
27
|
+
|
|
28
|
+
agent = GeneralAgent(personality="friendly")
|
|
29
|
+
response = agent.run("Tell me a joke.")
|
|
30
|
+
print(response)
|
|
31
|
+
|
|
32
|
+
# ============================================================================
|
|
33
|
+
# EXAMPLE 4: Using Factory Function (2 LOC)
|
|
34
|
+
# ============================================================================
|
|
35
|
+
|
|
36
|
+
from branches.general_agent import create_agent
|
|
37
|
+
agent = create_agent()
|
|
38
|
+
response = agent.run("What can you do?")
|
|
39
|
+
print(response)
|
|
40
|
+
|
|
41
|
+
# ============================================================================
|
|
42
|
+
# EXAMPLE 5: Using Class Method (2 LOC)
|
|
43
|
+
# ============================================================================
|
|
44
|
+
|
|
45
|
+
agent = GeneralAgent.create(model_name="gpt-4o", personality="technical")
|
|
46
|
+
response = agent.run("Analyze this business problem.")
|
|
47
|
+
print(response)
|
|
48
|
+
|
|
49
|
+
# ============================================================================
|
|
50
|
+
# EXAMPLE 6: Full Conversation (5 LOC)
|
|
51
|
+
# ============================================================================
|
|
52
|
+
|
|
53
|
+
agent = GeneralAgent()
|
|
54
|
+
agent.run("My name is Alice.")
|
|
55
|
+
response = agent.run("What's my name?")
|
|
56
|
+
print(response)
|
|
57
|
+
|
|
58
|
+
# ============================================================================
|
|
59
|
+
# EXAMPLE 7: Causal Reasoning Task (3 LOC)
|
|
60
|
+
# ============================================================================
|
|
61
|
+
|
|
62
|
+
agent = GeneralAgent()
|
|
63
|
+
response = agent.run("Extract causal variables for: product price depends on demand and supply")
|
|
64
|
+
print(response)
|
|
65
|
+
|
|
66
|
+
# ============================================================================
|
|
67
|
+
# EXAMPLE 8: Async Usage (4 LOC)
|
|
68
|
+
# ============================================================================
|
|
69
|
+
|
|
70
|
+
import asyncio
|
|
71
|
+
agent = GeneralAgent()
|
|
72
|
+
response = asyncio.run(agent.run_async("Hello!"))
|
|
73
|
+
print(response)
|
|
74
|
+
|
|
75
|
+
# ============================================================================
|
|
76
|
+
# EXAMPLE 9: Batch Processing (4 LOC)
|
|
77
|
+
# ============================================================================
|
|
78
|
+
|
|
79
|
+
agent = GeneralAgent()
|
|
80
|
+
tasks = ["What is AI?", "What is ML?", "What is causal reasoning?"]
|
|
81
|
+
results = agent.run_batch(tasks)
|
|
82
|
+
for r in results:
|
|
83
|
+
print(r)
|
|
84
|
+
|
|
85
|
+
# ============================================================================
|
|
86
|
+
# EXAMPLE 10: Complete Workflow (8 LOC)
|
|
87
|
+
# ============================================================================
|
|
88
|
+
|
|
89
|
+
agent = GeneralAgent(model_name="gpt-4o-mini", personality="neutral")
|
|
90
|
+
task = "Help me understand what factors influence customer satisfaction"
|
|
91
|
+
response = agent.run(task)
|
|
92
|
+
print(f"Task: {task}\nResponse: {response}")
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example demonstrating automatic variable and edge extraction from natural language.
|
|
3
|
+
|
|
4
|
+
The HybridAgent can automatically extract causal variables and relationships
|
|
5
|
+
from natural language text without any LLM dependency.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
import os
|
|
10
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
11
|
+
|
|
12
|
+
from architecture.hybrid.hybrid_agent import HybridAgent
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
"""Demonstrate auto-extraction capabilities."""
|
|
17
|
+
|
|
18
|
+
# Create agent
|
|
19
|
+
agent = HybridAgent()
|
|
20
|
+
|
|
21
|
+
print("=" * 70)
|
|
22
|
+
print("Hybrid Agent - Automatic Variable and Edge Extraction")
|
|
23
|
+
print("=" * 70)
|
|
24
|
+
print()
|
|
25
|
+
|
|
26
|
+
# Example 1: Simple causal relationship
|
|
27
|
+
print("Example 1: Simple causal relationship")
|
|
28
|
+
print("-" * 70)
|
|
29
|
+
task1 = "product price depends on demand and supply"
|
|
30
|
+
result1 = agent.extract_causal_variables(task1)
|
|
31
|
+
print(f"Input: {task1}")
|
|
32
|
+
print(f"Variables extracted: {result1['variables']}")
|
|
33
|
+
print(f"Edges extracted: {result1['edges']}")
|
|
34
|
+
print(f"Relationships found: {result1['metadata']['total_relationships']}")
|
|
35
|
+
print()
|
|
36
|
+
|
|
37
|
+
# Example 2: Multiple relationships
|
|
38
|
+
print("Example 2: Multiple causal relationships")
|
|
39
|
+
print("-" * 70)
|
|
40
|
+
task2 = "customer satisfaction is influenced by product quality, and product quality depends on manufacturing process"
|
|
41
|
+
result2 = agent.extract_causal_variables(task2)
|
|
42
|
+
print(f"Input: {task2}")
|
|
43
|
+
print(f"Variables extracted: {result2['variables']}")
|
|
44
|
+
print(f"Edges extracted: {result2['edges']}")
|
|
45
|
+
print(f"Relationships found: {result2['metadata']['total_relationships']}")
|
|
46
|
+
print()
|
|
47
|
+
|
|
48
|
+
# Example 3: Complex sentence
|
|
49
|
+
print("Example 3: Complex sentence with multiple relationships")
|
|
50
|
+
print("-" * 70)
|
|
51
|
+
task3 = "sales revenue increases when marketing spend rises, and marketing spend is controlled by budget allocation"
|
|
52
|
+
result3 = agent.extract_causal_variables(task3)
|
|
53
|
+
print(f"Input: {task3}")
|
|
54
|
+
print(f"Variables extracted: {result3['variables']}")
|
|
55
|
+
print(f"Edges extracted: {result3['edges']}")
|
|
56
|
+
print(f"Relationships found: {result3['metadata']['total_relationships']}")
|
|
57
|
+
print()
|
|
58
|
+
|
|
59
|
+
# Example 4: Full analysis
|
|
60
|
+
print("Example 4: Full causal analysis")
|
|
61
|
+
print("-" * 70)
|
|
62
|
+
task4 = "employee productivity affects company revenue, and employee productivity is determined by training quality and work environment"
|
|
63
|
+
result4 = agent.run(task4)
|
|
64
|
+
print(f"Input: {task4}")
|
|
65
|
+
print(f"\nAnalysis Result:\n{result4}")
|
|
66
|
+
print()
|
|
67
|
+
|
|
68
|
+
# Example 5: Arrow notation
|
|
69
|
+
print("Example 5: Arrow notation")
|
|
70
|
+
print("-" * 70)
|
|
71
|
+
task5 = "temperature -> pressure -> volume"
|
|
72
|
+
result5 = agent.extract_causal_variables(task5)
|
|
73
|
+
print(f"Input: {task5}")
|
|
74
|
+
print(f"Variables extracted: {result5['variables']}")
|
|
75
|
+
print(f"Edges extracted: {result5['edges']}")
|
|
76
|
+
print()
|
|
77
|
+
|
|
78
|
+
print("=" * 70)
|
|
79
|
+
print("Auto-extraction complete!")
|
|
80
|
+
print("=" * 70)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|