BRAID (Bounded Reasoning for Autonomous Inference and Decisions) integration for DSPy framework
Project description
BRAID-DSPy Integration
A Python library that integrates BRAID (Bounded Reasoning for Autonomous Inference and Decisions) architecture into the DSPy framework, enabling structured reasoning through Guided Reasoning Diagrams (GRD) in Mermaid format.
Overview
BRAID-DSPy brings structured reasoning capabilities to DSPy by requiring models to first generate a machine-readable flowchart (GRD) before executing the solution. This separation of planning and execution significantly improves reliability and reduces hallucinations.
Motivation
This project began when I first encountered the BRAID architecture during one of Armağan Amcalar's live streams. The two-phase reasoning approach — planning first, then execution — and the idea of representing this planning in a visualizable format (Mermaid diagrams) immediately captured my interest.
After the stream, I delved into OpenServ's articles and technical details about BRAID. The approach of having the model first generate a flowchart (Guided Reasoning Diagram - GRD) and then execute the solution step-by-step according to this schema seemed like a significant step forward for reliability and transparency in AI systems. I realized that integrating this architecture with the DSPy framework would need to work seamlessly with existing DSPy modules and optimizers, which led me to develop this library to make that integration a reality.
Much of the development process involved "vibe coding" — following intuition and iterating based on what felt right rather than strictly following a predefined plan. This organic approach allowed the library to evolve naturally as I explored the integration between BRAID and DSPy.
Key Features
- Guided Reasoning Diagrams (GRD): Generate Mermaid-format flowcharts that map solution steps
- Two-Phase Reasoning: Separate planning and execution phases for better reliability
- DSPy Integration: Seamlessly integrates with existing DSPy modules and optimizers
- Auditable Reasoning: Visualize and debug reasoning processes through GRD diagrams
- Optimization Support: BRAID-aware optimizers for improving GRD quality
Installation
pip install braid-dspy
Quick Start
import dspy
from braid import BraidReasoning
# Configure DSPy
lm = dspy.OpenAI(model="gpt-4")
dspy.configure(lm=lm)
# Create a BRAID reasoning module
braid = BraidReasoning()
# Use it in your pipeline
result = braid(problem="Solve: If a train travels 120 km in 2 hours, what is its speed?")
print(result.answer)
print(result.grd) # View the reasoning diagram
Documentation
📚 Full documentation is available on Read the Docs (coming soon)
Local documentation:
To build documentation locally:
pip install -e ".[docs]"
cd docs
make html
Examples
Check out the examples directory for:
- Basic usage examples
- GSM8K benchmark integration
- Optimization workflows
License
MIT License - see LICENSE file for details.
References
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file braid_dspy-0.1.2.tar.gz.
File metadata
- Download URL: braid_dspy-0.1.2.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1441b0bcfc12416b604bd431c03c83e5ec78fb8bec403f0bc5f3e2060a2cd11
|
|
| MD5 |
d8b2e3ad9f47da57b24c10be95d8a297
|
|
| BLAKE2b-256 |
2ee632011be41d8fdce1988571ba10440aa7953446b99e6626c339c29e073437
|
File details
Details for the file braid_dspy-0.1.2-py3-none-any.whl.
File metadata
- Download URL: braid_dspy-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a30eb3a5cdaaa8ecc7a3097e17a80bf467bfb69721f8765401a567583f661ea
|
|
| MD5 |
5bdf7a8a36d7ee5360bb2150d327cbe7
|
|
| BLAKE2b-256 |
e29d7ba447f52ebf86f79f37dcb2d576c57dc19fd9b7ac15621e16e903624e19
|