Module: braid.module
Main BRAID reasoning module for DSPy.
- class braid.module.BraidResult(problem: str, grd: str, parsed_grd: GRDStructure | None, reasoning_steps: List[Dict[str, Any]], answer: str, execution_trace: List[Dict[str, Any]], valid: bool, error: str | None = None)[source]
Bases:
objectResult object returned by BraidReasoning module.
- parsed_grd: GRDStructure | None
- class braid.module.BraidReasoning(*args, **kwargs)[source]
Bases:
ModuleBRAID reasoning module for DSPy.
This module implements the BRAID (Bounded Reasoning for Autonomous Inference and Decisions) architecture: 1. Planning Phase: Generate a Guided Reasoning Diagram (GRD) in Mermaid format 2. Execution Phase: Execute the GRD step by step to solve the problem
Example
>>> import dspy >>> from braid import BraidReasoning >>> >>> lm = dspy.OpenAI(model="gpt-4") >>> dspy.configure(lm=lm) >>> >>> braid = BraidReasoning() >>> result = braid(problem="If a train travels 120 km in 2 hours, what is its speed?") >>> print(result.answer) >>> print(result.grd)
- __init__(use_generator: bool = True, max_execution_steps: int = 20, validate_grd: bool = True)[source]
Initialize the BRAID reasoning module.
- Parameters:
use_generator – Whether to use GRDGenerator for planning (True) or direct LLM call (False)
max_execution_steps – Maximum number of steps to execute
validate_grd – Whether to validate GRD syntax before execution
- forward(problem: str, grd: str | None = None, problem_type: str | None = None) BraidResult[source]
Execute BRAID reasoning on a problem.
- Parameters:
problem – The problem to solve
grd – Optional pre-generated GRD (if None, will be generated)
problem_type – Optional problem type hint for generation
- Returns:
BraidResult object containing GRD, reasoning steps, and answer
- __call__(problem: str, **kwargs) BraidResult[source]
Make the module callable.