State Management Schema
The graph’s central state is managed via a TypedDict BODMASGraphState. It tracks the entire reduction process from start to finish.
Schema Definition
class BODMASGraphState(TypedDict):
original_expression: str
current_expression: str
next_target_op: Optional[Dict[str, Any]]
step_result: Optional[str]
agent_history: List[str]
error_context: Optional[Dict[str, Any]]
final_value: Optional[float]
Flow Transitions
- Init: User submits
10+2.original_expressionandcurrent_expressionbecome"10+2". - Planner: Identifies addition. Sets
next_target_opto{"op": "add", "args": [10, 2], "original_match": "10+2"}. Appends"planner"toagent_history. - Adder: Executes math. Sets
step_resultto"12.0". Updatescurrent_expressionto"12.0". Appends"adder"toagent_history. - Router: Sees
current_expressionis a float. Setsfinal_valueto12.0. Ends execution.
At any point, if an error occurs, error_context is populated, triggering an immediate routing to the END node.