orchestrate

package
v0.4.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package orchestrate provides concurrent workflow primitives: Fan (parallel merge), Race (first wins), and Sequence (chained).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fan

func Fan(ctx context.Context, fns ...func(context.Context) (*niro.Stream, error)) *niro.Stream

Fan runs multiple providers or requests in parallel and merges results into a single stream. Each generation runs in its own goroutine. Frames are interleaved in arrival order.

Use cases:

  • Parallel tool calls
  • Multi-model ensembles
  • Concurrent sub-agent invocations
  • Scatter-gather patterns

All streams are consumed. If any generation fails, the error is propagated but remaining streams continue until done or the context is canceled.

func Race

func Race(ctx context.Context, fns ...func(context.Context) (*niro.Stream, error)) (string, niro.Usage, error)

Race runs multiple generations in parallel and returns the first complete text response. All other generations are canceled.

Use cases:

  • Latency hedging (send to multiple providers, take fastest)
  • Speculative execution

Returns the collected text from the winning stream and its usage.

func Sequence

func Sequence(ctx context.Context, fns ...func(ctx context.Context, input string) (*niro.Stream, error)) (*niro.Stream, error)

Sequence runs multiple generation functions sequentially, where each function receives the collected text output of the previous one. The final stream contains only the last generation's output.

This is a building block for chained LLM calls where each step transforms or refines the previous output.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL