Skip to content

armoucar/dspy-react-machina

Repository files navigation

DSPy-ReAct-Machina

Alternative ReAct implementation for DSPy with full conversation history in a unified context.

Installation

pip install dspy-react-machina

Quick Start

import dspy
from dspy_react_machina import ReActMachina

# Configure your LM
lm = dspy.LM(model="openai/gpt-4o-mini")
dspy.configure(lm=lm)

# Define tools
def get_weather(city: str) -> str:
    """Get current weather for a city"""
    return f"Weather in {city}: 72°F, sunny"

# Create agent
agent = ReActMachina("history: dspy.History, question -> answer", tools=[get_weather])

# Chat with persistent history
history = dspy.History(messages=[])

while True:
    user_input = input("You: ").strip()
    if user_input.lower() in ["quit", "exit"]:
        break

    response = agent(question=user_input, history=history)
    print(f"Agent: {response.answer}\n")

    # Update history for next turn
    history = response.history

Documentation

Development

Setup

uv sync
uv run pre-commit install

Code Quality

uv run quality-check  # Run all checks: ruff + pyright

Testing

uv run tests                    # Run tests
uv run tests-coverage           # Run tests with coverage
uv run tests-coverage --web     # Run tests with coverage and open HTML report

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages