Skip to content

feat: DSTsx v2 — complete all planned features + MCP integration#3

Merged
Psyborgs-git merged 9 commits into
mainfrom
copilot/build-library-documentation
Mar 5, 2026
Merged

feat: DSTsx v2 — complete all planned features + MCP integration#3
Psyborgs-git merged 9 commits into
mainfrom
copilot/build-library-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

Implements the full v2 roadmap for DSTsx (TypeScript port of DSPy), adding all planned features from scratch. 218 tests pass across 46 test files (up from 160/29 in v1).

New Modules

  • TypedPredictor<T> / TypedChainOfThought<T> — JSON output with optional Zod schema validation, markdown fence stripping, configurable retry; returns TypedPrediction<T> with .typed
  • ParallelPromise.all fan-out; run()Prediction[], forward() → first result for Module compat
  • Refine — self-critique loop: inner module → built-in critic predictor → re-run with feedback
  • NativeReAct — OpenAI tools API / Anthropic tool_use based ReAct; parses tool_calls from raw response

New Primitives & Helpers

  • ImagefromURL / fromBase64 / fromFile; toOpenAIContentPart() / toAnthropicContentBlock() serializers for multi-modal LM calls
  • majority(field) — voting reducer across Prediction[]; drop-in reduceFunc for BestOfN / Ensemble
  • StreamChunk type + LM.stream() fallback + real streaming in OpenAI and Anthropic adapters + Predict.stream(inputs)

New Optimizers

  • BootstrapFewShotWithOptuna — pure-TS TPE (Tree-structured Parzen Estimator) Bayesian demo subset search
  • BootstrapFinetune — collects traces, exports JSONL in "openai" or "generic" format for fine-tuning
  • GRPO — Group Relative Policy Optimization; each step generates groupSize instruction variants, ranks by relative advantage (score − mean) / std
  • SIMBA — stochastic mini-batch ascent with Fisher-Yates sampling; accepts candidates that improve on random batches
  • AvatarOptimizer — per-predictor persona search; proposes numAvatars role descriptions via LM, keeps best-scoring

Experiment Tracking

Abstract Tracker + TrackerEvent; concrete ConsoleTracker and JsonFileTracker (async JSONL append). Custom trackers extend Tracker:

class MLflowTracker extends Tracker {
  log(event: TrackerEvent) { /* ship to MLflow/W&B */ }
  async flush() {}
}

Infrastructure

  • DiskCache — SHA-256 keyed JSON files, TTL + LRU eviction; LM accepts cacheDir for two-level caching
  • ProgramOfThought sandbox — new sandbox: "worker" | "function" | "none" option; "worker" uses node:worker_threads with true cancellation on timeout
  • MCPMCPToolAdapter (MCP server tools → DSTsx Tool for ReAct) + DSTsxMCPServer (DSTsx modules → MCP tool definitions)
  • GitHub Actionsci.yml (typecheck + test + build on push/PR) + publish.yml (npm publish on release)
  • typedoc.json — enables npm run docs

Usage snapshot

import { GRPO, SIMBA, AvatarOptimizer, NativeReAct, Image, StreamChunk } from "dstsx";

// Streaming
for await (const chunk of predict.stream({ question: "..." })) {
  process.stdout.write(chunk.delta);
}

// Native tool calling
const agent = new NativeReAct("question -> answer", tools);

// Multi-modal
const result = await captioner.forward({ image: Image.fromURL(url), question: "Describe." });

// Optimizers
const optimized = await new GRPO({ numSteps: 20, groupSize: 8 }).compile(program, trainset, metric);
Original prompt

Build this library as per the following specs upto v1.0, document usage for all apis of the library. Once complete also create a v2 roadmap extension based on what features from dspy are still missing in ours that need implementations.

The user has attached the following file paths as relevant context:

  • REQUIREMENTS.md

Created from VS Code.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Psyborgs-git <49641518+Psyborgs-git@users.noreply.github.com>
Copilot AI changed the title [WIP] Build library and document all APIs for v1.0 docs: v1.0 API documentation + V2 roadmap Mar 4, 2026
Copilot AI and others added 3 commits March 4, 2026 21:39
- TypedPredictor/TypedChainOfThought: JSON-parsing LM wrapper with optional schema validation and retry logic
- majority: reducer that picks the most-frequent Prediction field value
- Parallel: runs multiple modules concurrently with optional timeout
- Refine: iterative self-critique loop with a critic Predict module
- BootstrapFewShotWithOptuna: TPE-based demo subset optimizer extending BootstrapFewShot
- DiskCache: disk-persistent LM response cache (SHA-256 keyed, TTL, LRU eviction) integrated into LM as second-level cache
- MCP integration: MCPToolAdapter wraps MCP tools as DSTsx Tools; DSTsxMCPServer exposes modules as MCP tool definitions

Update all barrel index files and add MCP SDK ambient declarations to peer-deps.d.ts.
Add 26 new tests; total passes go from 160 to 185.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- TypedPredictor + TypedChainOfThought: structured JSON output with
  optional schema validation, markdown fence stripping, retry logic
- majority() helper: picks most-frequent Prediction by field value
- Parallel module: runs multiple modules in parallel via Promise.all
- Refine module: self-critique / iterative refinement loop
- BootstrapFewShotWithOptuna: Bayesian TPE optimizer (pure TS)
- DiskCache: disk-persistent JSON cache with TTL/LRU, integrated
  into LM as optional second-level cache via cacheDir option
- MCP integration: MCPToolAdapter + DSTsxMCPServer for Model
  Context Protocol interoperability

Tests: 185 pass (up from 160 baseline)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…a, DiskCache, MCP integration

Co-authored-by: Psyborgs-git <49641518+Psyborgs-git@users.noreply.github.com>
Copilot AI changed the title docs: v1.0 API documentation + V2 roadmap feat: DSTsx v2 — TypedPredictor, Parallel, Refine, majority, Optuna optimizer, DiskCache, MCP integration Mar 4, 2026
Copilot AI and others added 4 commits March 4, 2026 22:09
…izers, tracking, worker sandbox)

- Add StreamChunk interface and LM.stream() base method with fallback to single-chunk
- Add OpenAI.stream() and Anthropic.stream() with real provider streaming
- Add Predict.stream() for token-by-token streaming from modules
- Add NativeReAct module using provider-native tool/function calling
- Add Image primitive with fromURL/fromBase64/fromFile factories and OpenAI/Anthropic serialization
- Add BootstrapFinetune optimizer that exports JSONL fine-tuning data
- Add GRPO optimizer (Group Relative Policy Optimization)
- Add SIMBA optimizer (Stochastic Introspective Mini-Batch Ascent)
- Add AvatarOptimizer for persona/role prefix optimization
- Add experiment tracking module with Tracker, ConsoleTracker, JsonFileTracker
- Add sandbox='worker' option to ProgramOfThought for worker-thread execution
- Add GitHub Actions CI and publish workflows
- Add typedoc.json configuration
- Add 33 new tests covering all new features (218 total, up from 185)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Set contents: read on both CI and publish jobs to limit GITHUB_TOKEN scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… I/O in JsonFileTracker, Fisher-Yates shuffle in SIMBA

- NativeReAct: parse output field name from signature string instead of hardcoding 'answer'
- JsonFileTracker.flush(): use async appendFile from fs/promises instead of blocking appendFileSync
- SIMBA: replace sort-based shuffle with proper O(n) Fisher-Yates algorithm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ReAct, Image, GRPO, SIMBA, AvatarOptimizer, BootstrapFinetune, tracking, worker sandbox, CI/CD

Co-authored-by: Psyborgs-git <49641518+Psyborgs-git@users.noreply.github.com>
Copilot AI changed the title feat: DSTsx v2 — TypedPredictor, Parallel, Refine, majority, Optuna optimizer, DiskCache, MCP integration feat: DSTsx v2 — complete all planned features + MCP integration Mar 4, 2026
@Psyborgs-git Psyborgs-git marked this pull request as ready for review March 5, 2026 14:21
@Psyborgs-git Psyborgs-git merged commit 297612e into main Mar 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants