dspy.ts  by ruvnet

TypeScript framework for declarative AI systems

Created 1 year ago
254 stars

Top 99.0% on SourcePulse

GitHubView on GitHub
Project Summary

DSPy.ts brings Stanford's DSPy framework to TypeScript, enabling developers to program AI systems declaratively rather than solely relying on manual prompt engineering. It targets developers building complex AI applications who need robust, optimizable, and type-safe language model interactions. The primary benefit is automating the tuning of prompts and demonstrations, leading to more efficient and effective AI systems, with all memory and caching operations powered by the AgentDB backend.

How It Works

DSPy.ts operates on a principle of declarative programming for AI. Users define signatures which are typed input-output specifications for LM calls. These signatures are then composed into modules (e.g., PredictModule, ChainOfThought, ReAct, RetrieveModule) and pipelines. Optimizers like BootstrapFewShot, MIPROv2, and GEPA take a metric and a training set to automatically tune the underlying prompts and demonstrations, producing an OptimizedModule. Crucially, DSPy.ts is built "AgentDB-first," meaning vector indexing, memory, and caching leverage AgentDB's capabilities, including HNSW search, RaBitQ quantization, and hierarchical storage, allowing learned experiences to persist across compilation runs.

Quick Start & Requirements

  • Install: npm install dspy.ts
  • Prerequisites: Node.js, TypeScript (version 5.7+). LM providers like OpenAI, Anthropic, ONNX, or torch can be configured.
  • Demos: Runnable examples are available in the examples/ directory, executable via npx ts-node examples/ /index.ts.
  • API Docs: Generated via npm run docs.

Highlighted Details

  • Composable, typed modules (Predict, ChainOfThought, ReAct, Retrieve, Pipeline) ensure end-to-end type safety.
  • Self-optimizing capabilities via BootstrapFewShot, MIPROv2, and GEPA reduce manual prompt engineering.
  • GEPA offers genetic-Pareto prompt evolution with reflection and mutation for prompt candidates.
  • Experience replay in MIPROv2 allows subsequent compilations to warm-start from previous learning.
  • Input-conditioned few-shot learning selects relevant demos at runtime via vector search.
  • Built-in Retrieval-Augmented Generation (RAG) using RetrieveModule over AgentDB.
  • ReAct modules support reflexion for episodic memory and skill promotion.
  • AgentDB backend provides HNSW vector search, RaBitQ quantization (~32x smaller), hierarchical tiers, and ReasoningBank.
  • CachingLM offers a fuzzy cache for LM responses based on vector similarity.
  • Observability features include CompilationTracer for detailed run tracking and optional MLflow integration.
  • Supports multiple LM providers including OpenAI, Anthropic, ONNX, and js-pytorch.

Maintenance & Community

The project is built by rUv. Community links such as Discord or Slack are not explicitly mentioned in the README. The issue tracker on GitHub serves as the primary point for roadmap and known limitations: github.com/ruvnet/dspy.ts/issues.

Licensing & Compatibility

The project is released under the MIT license. This license is permissive and generally allows for commercial use, modification, and distribution, including within closed-source applications.

Limitations & Caveats

Current limitations include the need for a dedicated tokenizer and autoregressive decode loop for ONNX generate() output. AgentDB's HNSW search is currently a JavaScript cosine scan rather than a WASM-backed KNN implementation. Direct delegation to certain AgentDB memory classes requires a sql.js db handle not yet exposed by AgentDBClient. Further development is planned for Bayesian surrogates in optimizers and broader test coverage. The linting setup requires migration to ESLint 9 flat-config.

Health Check
Last Commit

4 days ago

Responsiveness

Inactive

Pull Requests (30d)
8
Issues (30d)
3
Star History
12 stars in the last 30 days

Explore Similar Projects

Starred by Zhiqiang Xie Zhiqiang Xie(Coauthor of SGLang), Eric Zhu Eric Zhu(Coauthor of AutoGen; Research Scientist at Microsoft Research), and
3 more.

Trace by microsoft

0.4%
738
AutoDiff-like tool for end-to-end AI agent training with general feedback
Created 1 year ago
Updated 5 months ago
Feedback? Help us improve.