dspy-go
DSPy Go implementation
Links
README
From the repo.
DSPy-Go
What is DSPy-Go?
DSPy-Go is a native Go implementation of the DSPy framework, bringing systematic prompt engineering and automated reasoning capabilities to Go applications. Build reliable LLM applications through composable modules and workflows.
Full Documentation | API Reference | Examples
Key Features
| Feature | Description |
|---|---|
| Modular Architecture | Compose simple, reusable components into complex applications |
| Multiple LLM Providers | Anthropic, OpenAI, Google Gemini, Ollama, LlamaCPP, and more |
| Advanced Modules | Predict, ChainOfThought, ReAct, RLM, Refine, Parallel |
| Intelligent Agents | ReAct patterns, ACE framework for self-improving agents |
| A2A Protocol | Multi-agent orchestration with hierarchical composition |
| Smart Tool Management | Bayesian selection, chaining, composition, MCP integration |
| Quality Optimizers | GEPA, MIPRO, SIMBA, BootstrapFewShot, COPRO |
| Structured Output | JSON structured output and XML adapters with security controls |
Installation
go get github.com/XiaoConstantine/dspy-go
Quick Start
CLI (Zero Code)
cd cmd/dspy-cli && go build -o dspy-cli
export GEMINI_API_KEY="your-api-key"
./dspy-cli list # See all optimizers
./dspy-cli try mipro --dataset gsm8k # Test optimizer instantly
./dspy-cli view session.jsonl --stats # View RLM session logs
Programming
package main
import (
"context"
"fmt"
"github.com/XiaoConstantine/dspy-go/pkg/core"
"github.com/XiaoConstantine/dspy-go/pkg/llms"
"github.com/XiaoConstantine/dspy-go/pkg/modules"
)
func main() {
// Configure LLM
llm, err := llms.NewGeminiLLM("", core.ModelGoogleGeminiPro)
if err != nil {
panic(err)
}
core.SetDefaultLLM(llm)
// Create signature and module
signature := core.NewSignature(
[]core.InputField{{Field: core.NewField("question")}},
[]core.OutputField{{Field: core.NewField("answer")}},
)
cot := modules.NewChainOfThought(signature)
// Execute
result, _ := cot.Process(context.Background(), map[string]interface{}{
"question": "What is the capital of France?",
})
fmt.Println(result["answer"])
}
Prefer helper functions such as core.SetDefaultLLM, core.SetTeacherLLM, and core.GetConcurrencyLevel over mutating core.GlobalConfig directly.
Modules resolve their model at execution time in this order: module-local via SetLLM, request-local via core.WithRuntime, then the package default configured with core.SetDefaultLLM.
Core Concepts
Signatures
Define input/output contracts for modules:
signature := core.NewSignature(
[]core.InputField{{Field: core.NewField("question", core.WithDescription("Question to answer"))}},
[]core.OutputField{{Field: core.NewField("answer", core.WithDescription("Detailed answer"))}},
).WithInstruction("Answer accurately and concisely.")
Modules
| Module | Description |
|---|---|
Predict | Direct prediction |
ChainOfThought | Step-by-step reasoning |
ReAct | Reasoning + tool use |
RLM | Large context exploration via REPL |
Refine | Quality improvement through iteration |
Parallel | Concurrent batch processing |
Structured Output
// JSON structured output
cot := modules.NewChainOfThought(signature).WithStructuredOutput()
// XML adapter (alternative)
interceptors.ApplyXMLInterceptors(predict, interceptors.DefaultXMLConfig())
Documentation
| Guide | Description |
|---|---|
| Getting Started | Installation and first program |
| Core Concepts | Signatures, Modules, Programs |
| Building Agents | ReAct, ACE framework, memory |
| A2A Protocol | Multi-agent orchestration |
| RLM Module | Large context exploration |
| XML Adapters | Structured output parsing |
| Tool Management | Smart registry, chaining, MCP |
| Optimizers | GEPA, MIPRO, SIMBA, Bootstrap |
Examples
Agent Frameworks
- ace_basic - Self-improving agents with ACE
- a2a_composition - Multi-agent deep research
- agents - ReAct patterns and orchestration
Modules
- rlm - Large context exploration
- rlm_context_policy - Compare
full,checkpointed, andadaptivereplay - rlm_subrlm_budgets - Deterministic sub-RLM direct/total budget demo
- xml_adapter - XML structured output
- parallel - Batch processing
- refine - Quality improvement
- typesafe_decide - Experimental TypeSafe decision gate composed with ChainOfThought; includes offline replay
- typesafe_threshold_tuning - Two-sided calibration policy with a held-out replay split
- typesafe_cascade - Jev-first decisions with selective Predict escalation
- typesafe_vs_predict - Head-to-head Decide and Predict comparison harness
Optimization
- rlm_oolong_gepa - Optimize an adaptive RLM agent, save the optimized program, restore it, and replay it
Tools
- smart_tool_registry - Intelligent tool selection
- tool_chaining - Pipeline building
- tool_composition - Composite tools
Optimizers
LLM Providers
// Anthropic Claude
llm, _ := llms.NewLLM("api-key", core.ModelAnthropicSonnet)
// Google Gemini
llm, _ := llms.NewLLM("api-key", core.ModelGoogleGeminiFlash)
// OpenAI
llm, _ := llms.NewLLM("api-key", core.ModelOpenAIGPT4o)
// Ollama (local)
llm, _ := llms.NewLLM("", core.ModelOllamaLlama3_8B)
// OpenAI-compatible (LiteLLM, LocalAI, etc.)
llm, _ := llms.NewOpenAICompatible("litellm", core.ModelOpenAIGPT4,
"http://localhost:4000",
llms.WithAPIKey("api-key"),
)
pkg/llms originally implemented provider protocols because OpenAI,
Anthropic, and Google did not yet offer mature Go SDKs. Maintaining those
rapidly changing protocols is not DSPy's core responsibility now that the Go
ecosystem has caught up, so provider wire protocols and model metadata are
supplied by llm-go.
pkg/llms remains as the compatibility adapter for dspy-go's core.LLM
interface. llm-go owns generation, streaming, structured output, and tool
calls. Because embeddings remain part of core.LLM, dspy-go retains its
Gemini and OpenAI-compatible embedding clients. Ollama and llama.cpp must
expose an OpenAI-compatible endpoint.
OpenAI Codex subscription generation is also available through llm-go via
llms.NewOpenAICodexLLM. The application owns OAuth login, token refresh, and
credential storage; dspy-go does not provide an interactive auth subsystem.
Community
- Documentation: xiaocui.me/dspy-go
- API Reference: pkg.go.dev
- Example App: Maestro - Code review agent
License
DSPy-Go is released under the MIT License. See the LICENSE file for details.
Collected info
- ★ 197 stars
- ⎇ 18 forks
- Language: Go
- Source updated: 9/23/2026