dspy-production-deployment
Skill124 starsChanged 11 months agoMITView on GitHub
Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skill-perfectionSkill
- skill-perfectionSkill
- dspy-adapters-multimodalSkill
- dspy-advanced-module-compositionSkill
- dspy-better-togetherSkill
- dspy-bootstrap-fewshotSkill
- dspy-custom-module-designSkill
- dspy-debugging-observabilitySkill
- dspy-embedding-retrievalSkill
- dspy-evaluation-suiteSkill
- dspy-finetune-bootstrapSkill
- dspy-gepa-reflectiveSkill
- dspy-haystack-integrationSkill
- dspy-mcp-tool-integrationSkill
- dspy-miprov2-optimizerSkill
- dspy-optimize-anythingSkill
- dspy-optimizer-selectionSkill
- dspy-output-refinement-constraintsSkill
- dspy-rag-pipelineSkill
- dspy-react-agent-builderSkill
- dspy-reasoning-modulesSkill
- dspy-signature-designerSkill
- dspy-simba-optimizerSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
Prefer state-only JSON for readable, safer artifacts:
- Distinctive: line 60
Use whole-program save only for trusted artifacts.
- Distinctive: line 67
Keep the DSPy major version compatible when loading saved programs.
- Distinctive: line 124
Use state-only JSON unless whole-program pickle is necessary and trusted.
- Distinctive: line 128
Use dspy-debugging-observability for MLflow and callbacks.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DSPy Production Deployment
Goal
Prepare a DSPy program for repeatable, observable, scalable, and safer production execution.
Cache Hardening
DSPy enables memory and disk caches by default. Disk cache deserialization uses pickle unless restricted. Enable the allowlist mode in production:
import dspy
dspy.configure_cache(restrict_pickle=True)Register trusted custom cache types only when needed:
dspy.configure_cache(
restrict_pickle=True,
safe_types=[MyResult, Metadata],
)Disable a cache layer explicitly when a deployment cannot persist data or requires fresh model responses:
dspy.configure_cache(
enable_disk_cache=False,
enable_memory_cache=True,
)Save and Load
Prefer state-only JSON for readable, safer artifacts:
compiled.save("./artifacts/program.json", save_program=False)
loaded = MyProgram()
loaded.load("./artifacts/program.json")Use whole-program save only for trusted artifacts. It uses cloudpickle:
compiled.save("./artifacts/program/", save_program=True)
loaded = dspy.load("./artifacts/program/")Keep the DSPy major version compatible when loading saved programs.
Usage Tracking
dspy.configure(
lm=dspy.LM("openai/gpt-4o-mini"),
track_usage=True,
)
prediction = program(question="What is DSPy?")
print(prediction.get_lm_usage())Cached calls return no new token usage.
Async Execution
Most built-in modules support acall():
import asyncio
async def main():
prediction = await program.acall(question="What is DSPy?")
print(prediction.answer)
asyncio.run(main())Implement aforward() for custom async modules. Use dspy.asyncify(program) only when adapting a synchronous callable is the right boundary.
Streaming
import asyncio
import dspy
stream_program = dspy.streamify(
dspy.Predict("question -> answer"),
stream_listeners=[
dspy.streaming.StreamListener(signature_field_name="answer"),
],
)
async def main():
async for chunk in stream_program(question="Explain DSPy briefly."):
print(chunk)
asyncio.run(main())For looped modules such as ReAct, set allow_reuse=True on listeners for repeated fields. Cache hits yield the final Prediction without replaying token chunks.
Production Checklist
- Pin the stable DSPy series.
- Use state-only JSON unless whole-program pickle is necessary and trusted.
- Enable
restrict_pickle=True. - Record usage, latency, errors, and traces.
- Load-test async and streaming paths separately.
- Use dspy-debugging-observability for MLflow and callbacks.
Official Documentation
- Production guide: https://dspy.ai/production/
- Cache tutorial: https://dspy.ai/tutorials/cache/
- Saving tutorial: https://dspy.ai/tutorials/saving/
- Async tutorial: https://dspy.ai/tutorials/async/
- Streaming tutorial: https://dspy.ai/tutorials/streaming/
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

