101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
"""LangGraph Workflow Demo.
|
|
|
|
Demonstrates the multi-agent trading workflow using LangGraph.
|
|
"""
|
|
|
|
import asyncio
|
|
from datetime import datetime
|
|
|
|
from openclaw.workflow.trading_workflow import TradingWorkflow
|
|
from openclaw.workflow.state import create_initial_state
|
|
|
|
|
|
async def run_workflow_demo():
|
|
"""Run the workflow demonstration."""
|
|
print("=" * 60)
|
|
print("OpenClaw Trading - LangGraph Workflow Demo")
|
|
print("=" * 60)
|
|
|
|
# 1. Create workflow
|
|
print("\n1. Creating trading workflow...")
|
|
workflow = TradingWorkflow(
|
|
symbol="AAPL",
|
|
initial_capital=1000.0,
|
|
enable_parallel=True
|
|
)
|
|
print(f" Symbol: {workflow.symbol}")
|
|
print(f" Initial Capital: ${workflow.initial_capital:,.2f}")
|
|
print(f" Parallel Execution: {workflow.enable_parallel}")
|
|
|
|
# 2. Show workflow graph
|
|
print("\n2. Workflow Graph:")
|
|
print("""
|
|
START
|
|
|
|
|
+---> MarketAnalysis --------+
|
|
| |
|
|
+---> SentimentAnalysis -----+
|
|
| |
|
|
+---> FundamentalAnalysis ---+
|
|
|
|
|
BullBearDebate
|
|
|
|
|
DecisionFusion
|
|
|
|
|
RiskAssessment
|
|
|
|
|
END
|
|
""")
|
|
|
|
# 3. Create initial state
|
|
print("\n3. Creating initial state...")
|
|
state = create_initial_state(
|
|
symbol="AAPL",
|
|
initial_capital=1000.0
|
|
)
|
|
print(f" Current Step: {state['current_step']}")
|
|
print(f" Symbol: {state['config']['symbol']}")
|
|
|
|
# 4. Run workflow (simulated - without actual LLM calls)
|
|
print("\n4. Running workflow...")
|
|
print(" Note: This demo shows the workflow structure.")
|
|
print(" In production, this would execute all 6 agents.")
|
|
|
|
# Show what would happen
|
|
steps = [
|
|
"START",
|
|
"MarketAnalysis (parallel)",
|
|
"SentimentAnalysis (parallel)",
|
|
"FundamentalAnalysis (parallel)",
|
|
"BullBearDebate",
|
|
"DecisionFusion",
|
|
"RiskAssessment",
|
|
"END"
|
|
]
|
|
|
|
for i, step in enumerate(steps, 1):
|
|
print(f" Step {i}: {step}")
|
|
|
|
# 5. Expected output
|
|
print("\n5. Expected Workflow Output:")
|
|
print(" {")
|
|
print(' "action": "buy", // or "sell", "hold"')
|
|
print(' "confidence": 0.75,')
|
|
print(' "position_size": 0.15,')
|
|
print(' "approved": true,')
|
|
print(' "risk_level": "medium"')
|
|
print(" }")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Workflow demo complete!")
|
|
print("=" * 60)
|
|
|
|
|
|
def main():
|
|
"""Main entry point."""
|
|
asyncio.run(run_workflow_demo())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|