Skip to main content

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

braid_dspy-0.1.3.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

braid_dspy-0.1.3-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file braid_dspy-0.1.3.tar.gz.

File metadata

  • Download URL: braid_dspy-0.1.3.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for braid_dspy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cef88a27f5441687a67ccd0af4ea76cb34ccdcc1ec7500841d95b2e277453d90
MD5 59ffbc7c9f6b09e17b1eacb4a6139a7d
BLAKE2b-256 858d54f3f7719f155299ea36b23c0b3c7850eb0a531971ba795671e945e1069a

See more details on using hashes here.

File details

Details for the file braid_dspy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: braid_dspy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for braid_dspy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 db6a7d444361595c56cd945575f6f6ffef97fbd56a500c54592773961cab16c5
MD5 75cc45c1aa5bdc193e6947d287013322
BLAKE2b-256 b35a7365152af69794be21036aedbdb2199d740df9b8157f20883a19f3892843

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page