advanced_flow/
advanced_flow.rs1use rust_logic_graph::{Graph, GraphIO, Executor, RuleNode, DBNode, AINode};
2use tracing_subscriber;
3use serde_json::json;
4
5#[tokio::main]
6async fn main() -> anyhow::Result<()> {
7 tracing_subscriber::fmt()
9 .with_max_level(tracing::Level::DEBUG)
10 .init();
11
12 println!("=== Rust Logic Graph - Advanced Flow Example ===");
13 println!("Scenario: User Analytics Report Generation with Permission Checks\n");
14
15 let def = GraphIO::load_from_file("examples/advanced_flow.json")?;
17
18 let mut executor = Executor::new();
20
21 executor.register_node(Box::new(RuleNode::new(
23 "validate_input",
24 "user_id > 0"
25 )));
26
27 executor.register_node(Box::new(DBNode::new(
28 "fetch_user_data",
29 "SELECT * FROM users WHERE id = ?"
30 )));
31
32 executor.register_node(Box::new(RuleNode::new(
33 "check_permissions",
34 "user_role == \"admin\""
35 )));
36
37 executor.register_node(Box::new(DBNode::new(
38 "query_analytics",
39 "SELECT * FROM analytics WHERE user_id = ?"
40 )));
41
42 executor.register_node(Box::new(AINode::new(
43 "generate_report",
44 "Generate comprehensive analytics report from data"
45 )));
46
47 executor.register_node(Box::new(AINode::new(
48 "send_notification",
49 "Send notification to user about report status"
50 )));
51
52 let mut graph = Graph::new(def);
54
55 graph.context.data.insert("user_id".to_string(), json!(1001));
57 graph.context.data.insert("user_role".to_string(), json!("admin"));
58
59 println!("Initial Context:");
60 println!(" - user_id: 1001");
61 println!(" - user_role: admin\n");
62
63 println!("Starting advanced flow execution...\n");
65 executor.execute(&mut graph).await?;
66
67 println!("\n=== Execution Results ===");
69 println!("\nContext Data:");
70 for (key, value) in &graph.context.data {
71 if key.ends_with("_result") {
72 println!(" {}: {}", key, serde_json::to_string_pretty(&value)?);
73 }
74 }
75
76 println!("\n=== Flow Complete ===");
77 Ok(())
78}