DSPy

Serve a DSPy program as an AgentOS agent.

DSPyAgent wraps any DSPy Module so it can be served through AgentOS or used standalone.

Save the following as dspy_agent.py. After the Install step, start it with python dspy_agent.py. Later snippets are alternatives or fragments using the same imports.

import dspy
from agno.agents.dspy import DSPyAgent
from agno.db.sqlite import SqliteDb
from agno.os import AgentOS

dspy.configure(lm=dspy.LM("openai/gpt-5.4"))

agent = DSPyAgent(
    name="DSPy Assistant",
    program=dspy.ChainOfThought("question -> answer"),
)

agent_os = AgentOS(
    agents=[agent],
    tracing=True,
    db=SqliteDb(db_file="tmp/agentos.db"),
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="dspy_agent:app", reload=True)

Install

uv pip install "agno[os]" dspy
export OPENAI_API_KEY=sk-...

Parameters

ParameterTypeDefaultDescription
namestrNoneDisplay name for the agent.
idstrNoneUnique identifier. Auto-generated from name if unset.
programdspy.ModuleNoneA DSPy module (Predict, ChainOfThought, ReAct, or custom).
input_fieldstr"question"Name of the input field in the DSPy signature.
output_fieldstr"answer"Name of the output field on the Prediction.
lmdspy.LMNoneOptional LM to scope this agent. Falls back to the global dspy.configure(lm=...).
program_kwargsDict[str, Any]{}Extra kwargs passed to the program on every call.
dbBaseDbNoneDatabase for session persistence.

Examples

Developer Resources