
dspy.ts
github.com/ruvnet/dspy.ts- Category
- AI Tools
- Rank
- No. 1388Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- ruvnet
- GitHub
- 273 stars
- Date
About
Declarative self-learning JavaScript — TypeScript port of DSPy for programmatically optimizing LLM pipelines via examples instead of prompt tweaking.
What it does
You define typed inputs and outputs, assemble language-model steps, then judge results with a metric and examples. The system searches for better instructions and demonstrations, returning an improved program. Optional vector memory supports retrieval, caching, reflexion, tracing, and reuse of successful optimization results.
Why it's ranked here
The appeal is unusually broad integration: typed composition, three optimization strategies, retrieval, persistent learning, caching, and tracing share one library. The trade is architectural weight. AgentDB sits beneath many advanced features, and useful optimization still depends on representative examples plus a metric that reflects the real task.
What's good
Input and output types carry through composed modules. Optimization can bootstrap unlabeled examples, select demonstrations per input, or evolve candidates against per-example scores. Seeded searches support repeatability. Successful instructions and prompt frontiers can persist across runs. Retrieval includes diversity reranking, while tracing records causal links between optimizer trials.
Tradeoffs
This is more than a thin prompt abstraction. AgentDB, schema validation, dependency injection, logging, local model runtimes, and TypeScript tooling enlarge the dependency surface. Some memory integrations currently imitate the intended behavior atop the vector client because direct delegation needs an unavailable database handle. Provider use also requires configuring a language-model driver.
How to use it well
Choose it for TypeScript applications where prompts deserve tests, metrics, repeatable optimization, and typed composition. Start with a small labeled set and a metric aligned with production behavior, then add persistent memory or dynamic retrieval only when needed. It does not supply the task definition, trustworthy evaluation criteria, or a hosted application layer.
Technical notes+
package.json defines an npm library requiring Node 18 or newer, TypeScript 5 or newer as a peer, AgentDB as a dependency, and MLflow tracking as optional. src/index.ts owns a global LM registry and re-exports src/core/index.ts, src/lm/index.ts, src/memory/index.ts, src/modules/index.ts, src/optimize/index.ts, and src/observability/index.ts. src/lm/providers/index.ts exposes OpenAI, Anthropic, and OpenRouter drivers. src/agent/index.ts and src/utils/index.ts exist, but src/index.ts does not re-export them, so swarm orchestration and sanitization are not present in the shown root barrel. Notably, src/core/index.ts re-exports LM configuration from another module, which warrants checking registry identity during integration.
Observed
- License
- MIT
- Primary language
- TypeScript
- Packaging
- Published as the dspy.ts npm package; install with npm
- Interface
- Importable library with a root public API barrel
- Runtime support
- Node.js 18 or newer; README also states browser support
- Language-model providers
- OpenAI, Anthropic, OpenRouter, ONNX, js-pytorch, and a dummy driver are documented or exported
Read from README.md, package.json, src/index.ts, src/lm/index.ts, src/core/index.ts, src/agent/index.ts, src/utils/index.ts, src/memory/index.ts, src/modules/index.ts, src/optimize/index.ts, src/observability/index.ts, src/agent/swarm/index.ts, src/lm/providers/index.ts, src/memory/agentdb/index.ts, src/memory/reasoning-bank/index.ts.
What it can do
Optimize LLM pipeline performance using examples
LLM pipeline and training examples → Optimized pipeline configuration
Create declarative LLM workflows
TypeScript/JavaScript code defining pipeline structure → Executable LLM pipeline
Train pipeline components from examples
Input-output example pairs → Trained pipeline modules
Generate optimized prompts automatically
Task examples and desired outputs → Optimized prompt templates
Compose multi-step LLM reasoning chains
Individual reasoning components → Connected multi-step pipeline
Evaluate pipeline performance metrics
Pipeline and test dataset → Performance scores and metrics
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.