Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 3.08 KB

File metadata and controls

84 lines (63 loc) · 3.08 KB

DSPy

DSPy integration for the Agent SDK.

Note: This SDK is designed to work with the Autohand Code CLI. While the SDK can be used standalone, we recommend installing the CLI for the best experience. Bridge functions and AI program classes connecting the SDK to DSPy 3.x.

from autohand_agents.dspy import autohand_lm, AgentProgram, ChainOfThoughtProgram, ReActProgram

autohand_lm()

Creates a dspy.LM configured for an Autohand provider.

Param Type Default Description
provider str "openrouter" Provider name from SDK config
api_key str | None None API key
model str "your-modelcard-id-here" Model identifier
temperature float 0.7 Sampling temperature
max_tokens int 2000 Max tokens to generate

Returns dspy.LM.

Provider Mappings

Provider LiteLLM Model String API Base
openrouter openrouter/anthropic/{model} https://openrouter.ai/api/v1
openai openai/{model} https://api.openai.com/v1
ollama ollama_chat/{model} http://localhost:11434
azure azure/{model} Azure endpoint
llamacpp openai/{model} http://localhost:8080
llmgateway {model} (as-is) Configurable
mlx {model} (as-is) http://localhost:9898
import dspy
from autohand_agents.dspy import autohand_lm

lm = autohand_lm(
    provider="openai",
    api_key="sk-...",
    model="gpt-4o",
)
dspy.configure(lm=lm)

AgentProgram

Simple Q&A via dspy.Predict.

agent = AgentProgram(system_prompt="Answer technical questions.")
result = agent(question="What is a context manager?")
# result is the answer string

ChainOfThoughtProgram

Step-by-step reasoning via dspy.ChainOfThought.

cot = ChainOfThoughtProgram(system_prompt="Think carefully.")
result = cot(question="Design a rate limiter for 100 req/s")

ReActProgram

Tool-using agent via dspy.ReAct.

Param Type Default Description
system_prompt str "" Instructions
tools list | None None DSPy tools for reasoning
max_iters int 5 Max reasoning steps
program = ReActProgram(
    system_prompt="Analyze and fix bugs.",
    max_iters=10,
)
result = program(question="Find the bug in main.py")