agentskit.js
Agents

Speculate

Run N candidates in parallel. Pick the best by a user-defined scorer.

import { speculate } from '@agentskit/runtime'

const { best, candidates } = await speculate({
  candidates: [
    { name: 'gpt-4o', run: () => runtime1.run(task) },
    { name: 'claude', run: () => runtime2.run(task) },
    { name: 'gemini', run: () => runtime3.run(task) },
  ],
  pick: (results) => results.reduce((a, b) => (b.score > a.score ? b : a)),
})

When to use

  • Cross-model reliability on hard prompts.
  • Latency reduction (fire all, take first success).
  • Cost/quality trade-offs evaluated per run.
✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page