-
-
Notifications
You must be signed in to change notification settings - Fork 694
[FEAT-AGENT][Added Lightweight CRCA Agent reasoning architecture] #1233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Refactor causal graph node initialization and edge addition. Removed advanced methods for confounder detection and adjustment set identification in Lite version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pyre found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Updated documentation for CRCAAgent to reflect new features and changes, including LLM integration and dual-mode operation.
| from swarms.agents.create_agents_from_yaml import ( | ||
| create_agents_from_yaml, | ||
| ) | ||
| from swarms.agents.cr_ca_agent import CRCAAgent |
Check failure
Code scanning / Pyre
Undefined import Error
| """ | ||
|
|
||
| from typing import Dict, Any, List, Tuple, Optional, Union | ||
| import numpy as np |
Check failure
Code scanning / Pyre
Undefined import Error
| except Exception: | ||
| return max(1, len(self.causal_graph)) | ||
|
|
||
| effective_steps = _resolve_max_steps(max_steps if max_steps != 1 or self.max_loops == 1 else self.max_loops) |
Check failure
Code scanning / Pyre
Incompatible parameter type Error
| effective_steps = _resolve_max_steps(max_steps if max_steps != 1 or self.max_loops == 1 else self.max_loops) | ||
| # If caller passed default 1 and instance set a different max_loops, prefer instance value | ||
| if max_steps == 1 and self.max_loops != 1: | ||
| effective_steps = _resolve_max_steps(self.max_loops) |
Check failure
Code scanning / Pyre
Incompatible parameter type Error
description
Introduces a lightweight causal reasoning Agent implementing the core ASTT/CR-CA primitives with LLM integration. This Agent provides both deterministic causal simulation and LLM-based causal analysis, enabling flexible causal reasoning workflows without requiring networkx, pandas, scipy, cvxpy, or other heavyweight libraries.
Background / Motivation
The existing
CRCAAgentinswarms/agents/cr_ca_agent.pyprovides full-featured causal reasoning with LLM integration, advanced optimization, and extensive statistical methods. However, many use cases require a deterministic, dependency-light agent that provides core causal simulation capabilities without external API calls.This PR introduces
CRCAAgent(Lite) as a lightweight Agent in the swarms framework that:run()method supporting both LLM-based and deterministic modesnumpyand swarms Agent base (no networkx, pandas, scipy, cvxpy)The Lite implementation maintains mathematical rigor while prioritizing simplicity and performance, making it a versatile Agent for causal reasoning that combines LLM capabilities with deterministic simulation.
Architecture Overview
graph TB A[Task/Initial State] --> B{Mode Selection} B -->|LLM Mode| C[Build Causal Prompt] B -->|Deterministic Mode| D[Standardize to z-space] C --> E[LLM Causal Analysis] E --> F[Multi-loop Reasoning] F --> G[Synthesize Analysis] G --> H[Generate Counterfactuals] D --> I[Topological Sort] I --> J[Linear SCM Propagation] J --> K[De-standardize] K --> L[Evolved State] L --> M[Counterfactual Generation] N[Causal Graph] --> I N --> O[Edge Strengths] O --> J N --> C style A fill:#e1f5ff style L fill:#c8e6c9 style M fill:#fff9c4 style G fill:#ffcccbCore Components
The implementation centers on four key capabilities:
LLM-Based Causal Analysis: Multi-loop reasoning with structured output
Evolution Operator E(x): Implements linear structural causal model (SCM) in standardized z-space
z_y = Σᵢ βᵢ·z_xiwhere βᵢ are edge strengthsCounterfactual Generation: Implements Pearl's do-operator and abduction-action-prediction
Causal Graph Operations: Pure-Python DAG implementation
sequenceDiagram participant User participant Agent participant LLM participant Graph participant SCM User->>Agent: run(task/initial_state) alt LLM Mode (task string) Agent->>Agent: _build_causal_prompt() loop max_loops Agent->>LLM: step(prompt) LLM-->>Agent: causal_analysis Agent->>Agent: update_memory_context() end Agent->>LLM: synthesize_analysis() LLM-->>Agent: final_analysis Agent->>Agent: generate_counterfactual_scenarios() else Deterministic Mode (initial_state dict) Agent->>Graph: topological_sort() Graph-->>Agent: ordered_nodes Agent->>SCM: _predict_outcomes(state, {}) SCM->>SCM: standardize(state) SCM->>SCM: propagate(parents → children) SCM->>SCM: de-standardize(predictions) SCM-->>Agent: evolved_state Agent->>Agent: generate_counterfactual_scenarios() end Agent-->>User: {analysis/evolved_state, counterfactuals, graph_info}What changed (files)
ceca_lite/crca-lite.py— Core Lite implementation (CRCAgent class)swarms/agents/cr_ca_agent.py— Integration point (CRCAAgent class reference)docs/swarms/agents/crca_agent.md— Documentation and usage examplesKey Design Decisions
Pure-Python Graph Representation
{node: {child: strength}}instead of networkxStandardized Linear SCM
Dual-Mode Operation
LLM Integration
Agent-First API
run()method accepts task string (LLM mode) or initial_state dict (deterministic mode)max_loopsparameter for multi-step LLM reasoning or evolutionValue Proposition
Performance Characteristics
Integration Benefits
Use Cases Enabled
Testing and validation
Security & Performance
Compatibility & Breaking Changes
CRCAAgentclass atswarms/agents/cr_ca_agent.pyCRCAAgent(full version) remains unchangedfrom swarms.agents.cr_ca_agent import CRCAAgentCRCAAgentcontinues to workDocumentation
docs/swarms/agents/crca_agent.mdChecklist (required before merge)
make testmake lint/make formatReviewer guidance
Critical areas for review:
_predict_outcomescorrectnessCounterfactual generation
Graph operations
is_dag()API design
run()method signature matches agent conventionsDependencies
LLM Integration
Notes for maintainers
CRCAAgent(Lite) is a full Agent in the swarms framework withrun()method supporting both LLM and deterministic modesCRCAAgentadds advanced optimization, statistical methods, and extensive features on topswarms/agents/__init__.pyfor canonical importsContacts / Authors
Optional: Link to issue(s)
📚 Documentation preview 📚: https://swarms--1233.org.readthedocs.build/en/1233/