grl_graph_flow/
grl_graph_flow.rs1use rust_logic_graph::{Graph, GraphIO, Executor, RuleNode, DBNode, AINode, RuleEngine};
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::INFO)
10 .init();
11
12 println!("=== Rust Logic Graph - GRL Integration Example ===");
13 println!("Scenario: Loan Application with Advanced GRL Rules\n");
14
15 let def = GraphIO::load_from_file("examples/grl_graph_flow.json")?;
17
18 let mut executor = Executor::new();
20
21 executor.register_node(Box::new(RuleNode::new(
23 "input_validation",
24 "loan_amount > 0 && loan_amount <= 1000000"
25 )));
26
27 executor.register_node(Box::new(DBNode::new(
29 "fetch_customer",
30 "SELECT * FROM customers WHERE id = ?"
31 )));
32
33 executor.register_node(Box::new(RuleNode::new(
35 "risk_assessment",
36 "credit_score >= 600 && income >= loan_amount * 3"
37 )));
38
39 executor.register_node(Box::new(AINode::new(
41 "fraud_detection",
42 "Analyze transaction patterns for fraud indicators"
43 )));
44
45 executor.register_node(Box::new(RuleNode::new(
47 "approval_decision",
48 "risk_score < 50 && fraud_score < 30"
49 )));
50
51 executor.register_node(Box::new(AINode::new(
53 "notification",
54 "Generate approval/rejection notification email"
55 )));
56
57 let mut graph = Graph::new(def);
59
60 graph.context.data.insert("loan_amount".to_string(), json!(50000));
62 graph.context.data.insert("credit_score".to_string(), json!(720));
63 graph.context.data.insert("income".to_string(), json!(180000));
64 graph.context.data.insert("customer_id".to_string(), json!(12345));
65
66 println!("Application Data:");
67 println!(" Loan Amount: $50,000");
68 println!(" Credit Score: 720");
69 println!(" Annual Income: $180,000");
70 println!(" Customer ID: 12345\n");
71
72 println!("Processing loan application through GRL-powered workflow...\n");
74 executor.execute(&mut graph).await?;
75
76 println!("\n=== Application Results ===\n");
78
79 if let Some(validation) = graph.context.data.get("input_validation_result") {
80 println!("✓ Input Validation: {}", validation);
81 }
82
83 if let Some(customer) = graph.context.data.get("fetch_customer_result") {
84 println!("✓ Customer Data Retrieved");
85 }
86
87 if let Some(risk) = graph.context.data.get("risk_assessment_result") {
88 println!("✓ Risk Assessment: {}", risk);
89 }
90
91 if let Some(fraud) = graph.context.data.get("fraud_detection_result") {
92 println!("✓ Fraud Detection Completed");
93 }
94
95 if let Some(decision) = graph.context.data.get("approval_decision_result") {
96 println!("✓ Approval Decision: {}", decision);
97 }
98
99 println!("\n=== GRL-Powered Workflow Complete ===");
100
101 println!("\n=== Bonus: Advanced GRL Rules ===\n");
103
104 let mut grl_engine = RuleEngine::new();
105
106 let advanced_rules = r#"
107rule "HighValueLoan" salience 100 {
108 when
109 loan_amount > 100000 && credit_score < 750
110 then
111 requires_manual_review = true;
112 approval_tier = "senior";
113}
114
115rule "StandardApproval" salience 50 {
116 when
117 loan_amount <= 100000 && credit_score >= 650
118 then
119 auto_approve = true;
120 approval_tier = "standard";
121}
122
123rule "RiskMitigation" salience 25 {
124 when
125 debt_to_income_ratio > 0.4
126 then
127 requires_collateral = true;
128 interest_rate_adjustment = 1.5;
129}
130"#;
131
132 grl_engine.add_grl_rule(advanced_rules)?;
133
134 println!("Advanced GRL rules loaded:");
135 println!(" - High Value Loan Review");
136 println!(" - Standard Approval Process");
137 println!(" - Risk Mitigation Measures");
138
139 println!("\n✅ All systems operational with rust-rule-engine integration!");
140
141 Ok(())
142}