DSPy-Go

April 22, 2026 ยท View on GitHub

Go Report Card codecov Go Reference

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

FeatureDescription
Modular ArchitectureCompose simple, reusable components into complex applications
Multiple LLM ProvidersAnthropic, OpenAI, Google Gemini, Ollama, LlamaCPP, and more
Advanced ModulesPredict, ChainOfThought, ReAct, RLM, Refine, Parallel
Intelligent AgentsReAct patterns, ACE framework for self-improving agents
A2A ProtocolMulti-agent orchestration with hierarchical composition
Smart Tool ManagementBayesian selection, chaining, composition, MCP integration
Quality OptimizersGEPA, MIPRO, SIMBA, BootstrapFewShot, COPRO
Structured OutputJSON 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

CLI Documentation

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

ModuleDescription
PredictDirect prediction
ChainOfThoughtStep-by-step reasoning
ReActReasoning + tool use
RLMLarge context exploration via REPL
RefineQuality improvement through iteration
ParallelConcurrent batch processing

Structured Output

// JSON structured output
cot := modules.NewChainOfThought(signature).WithStructuredOutput()

// XML adapter (alternative)
interceptors.ApplyXMLInterceptors(predict, interceptors.DefaultXMLConfig())

Core Concepts Guide

Documentation

GuideDescription
Getting StartedInstallation and first program
Core ConceptsSignatures, Modules, Programs
Building AgentsReAct, ACE framework, memory
A2A ProtocolMulti-agent orchestration
RLM ModuleLarge context exploration
XML AdaptersStructured output parsing
Tool ManagementSmart registry, chaining, MCP
OptimizersGEPA, MIPRO, SIMBA, Bootstrap

Examples

Agent Frameworks

Modules

Optimization

  • rlm_oolong_gepa - Optimize an adaptive RLM agent, save the optimized program, restore it, and replay it

Tools

Optimizers

  • mipro - TPE-based optimization
  • simba - Introspective learning
  • gepa - Evolutionary optimization

LLM Providers

// Anthropic Claude
llm, _ := llms.NewAnthropicLLM("api-key", core.ModelAnthropicSonnet)

// Google Gemini
llm, _ := llms.NewGeminiLLM("api-key", core.ModelGoogleGeminiPro)

// OpenAI
llm, _ := llms.NewOpenAI(core.ModelOpenAIGPT4, "api-key")

// Ollama (local)
llm, _ := llms.NewOllamaLLM(core.ModelOllamaLlama3_8B)

// OpenAI-compatible (LiteLLM, LocalAI, etc.)
llm, _ := llms.NewOpenAILLM(core.ModelOpenAIGPT4,
    llms.WithAPIKey("api-key"),
    llms.WithOpenAIBaseURL("http://localhost:4000"))

Providers Reference

Community

License

DSPy-Go is released under the MIT License. See the LICENSE file for details.