100+ Operators · Retrieval · Repair · Factories

Operator Library

Sparsi provides a comprehensive toolkit for building efficient, reliable agentic tools. This catalog of deterministic and AI operators is designed to minimize model dependencies—maximizing pre-written logic to reduce cost and eliminate hallucinations in your production workflows.

operators are deterministic; the AI operators are the small, scoped set you reach for only where genuine judgment is required.

Every operator available, organized by category. Deterministic ops run as pure Go functions, testable without a model. AI ops call Claude or Gemini and support structured retries. The library also ships a retrieval layer (Retriever + RetrieveOp + citation validation), a repair wrapper (WithRepair) for AI-assisted recovery of deterministic ops, and pluggable factories for AI / embedding credentials.

AI Operators

12 ops AI-Powered

These operators call Claude and return structured outputs with retries. Each accepts a natural-language operation or predicate param and produces a typed Result. Model reasoning is captured via WithReasoningLog when needed.

Math Operators

24 ops Deterministic

Float Arithmetic

Int Arithmetic

Aggregate, Clamp & Utility

String Operators

10 ops Deterministic

String Operations

Type→String Conversion

Predicate Operators

19 ops Deterministic

Float Predicates

Integer Predicates

String Predicates

Empty Predicates

Select Operators

8 ops Deterministic

Slice Operators

8 ops Deterministic

Boolean Operators

3 ops Deterministic

I/O Operators

3 ops Deterministic

MCP Operators

2 ops Integration

These operators turn Model Context Protocol servers into first-class workflow steps. They speak the standard MCP wire protocol over either stdio (a local subprocess like npx @playwright/mcp or uvx-launched servers) or streamable http (a remote endpoint such as https://docs.mcp.cloudflare.com/mcp) — so any MCP-compliant server, local or remote, public or private, drops into a Sparsi graph without custom glue code.

Because these ops use the protocol's own tools/list and tools/call verbs, any reference material that documents an existing MCP server and its tools is directly usable when wiring Sparsi. Hand the server's tool catalog (names, JSON-Schema arg shapes, return types) to your editor or to Claude alongside the Sparsi graph and it has everything needed to bind a tool call to a vertex — no SDK adapter to write, no per-server client to vendor.

A built-in warm-replenish session pool (pool_size, stdio only in v1) keeps cold-start off the critical path when many vertices share the same server spec. Pair with library.ShutdownMCPPool from main() so pre-started subprocesses drain at exit.

Retrieval & Citations

3 ops RAG layer

Two operators wire a registered library.Retriever into a graph; one filters LLM-emitted citations against an allow-list. The Retriever interface itself is backend-agnostic — implement it once over BM25, a vector store, or a hosted search service, then any of these ops works. Vertices that embed (vector-store retrievers) call library.ResolveEmbeddingClient instead of reading env vars directly, so a registered EmbeddingClientFactory controls where the credential actually comes from.

See the retrieval concept guide for the full data flow, security guidance, and citation-validation pattern.

Repair Wrapper

1 wrapper Hybrid

library.WithRepair turns a deterministic op into an LLM-assisted-recovery op. When the inner op returns *library.ErrRepairable carrying a self-contained prompt, the wrapper forwards the prompt to an LLM, parses the response back into the named input field's element type via UnmarshalRepair, writes it back, and re-runs the inner op. Bounded by max_attempts; non-repairable errors propagate unchanged.

See the repair concept guide for the inner-op contract, when (and when not) to use it, and the canonical wiring pattern.

library.RegisterWithRepair[Inner] Registration

Generic constructor. Pass the registered name, a factory that returns a fresh inner op, and a RepairConfig (InputField, MaxAttempts, PromptPrefix, PromptSuffix, Provider, Model, MaxTokens).

Vertex-level params override: max_attempts, provider, model, max_tokens, credential_ref, client_factory_id.

*library.ErrRepairable Inner contract

Typed error inner ops return to opt in to repair. Carries a Prompt string (the self-contained instruction for the LLM) and an underlying Cause error for logging and errors.Unwrap.

The input type implements library.RepairableInput: UnmarshalRepair(string) error.

Client Factories

2 interfaces Credential routing

Every AI op resolves its provider SDK client through an AIClientFactory; every vector-store retriever resolves its embedding client through an EmbeddingClientFactory. Both interfaces let you source credentials from Vault, AWS Secrets Manager, workload identity, an egress proxy, or per-tenant vaults without changing graph code.

See the credential-routing guide for wiring patterns (process default vs registered-by-id vs per-vertex ref) and security guidance.

Input Injection

ContextValFactory Deterministic

builtin.ContextValFactory[T](key) creates a typed operator factory that reads a value of type T from context.Context at graph execution time. This is the standard pattern for injecting per-run inputs — ticket text, API responses, weights — into a workflow without baking values into the graph at build time.

builtin.ContextValFactory[T](key)

Generic factory. Register once under a name in init(); inject the value via context.WithValue before each run. Supports any type: string, float64, int, bool, []string.

registration + wiring
type ticketBodyKey struct{}

// Register in init()
operator.RegisterOpFactory("body_const",
    builtin.ContextValFactory[string](ticketBodyKey{}))

// Wire into graph — no Params needed
Vertex("body_const").Op("body_const").
    Output("Result", "ticket_body")

// Inject value at run time
ctx := context.WithValue(ctx, ticketBodyKey{}, ticketBody)

When to use it

  • Per-run inputs — ticket text, recipe JSON, city name, query string
  • Configuration constants — scoring weights, thresholds, JSONPath selectors
  • Conditional paths — combine with .Condition() to gate a ContextVal vertex so only the matching branch emits its value
  • Any typestring, float64, int, bool, []string

The graph stays immutable and reusable across calls. Different inputs are injected each run via context — the compiled graph is never rebuilt.

JSON & Time Operators

2 ops Deterministic

Ready to build?

Combine these operators using the Go fluent builder API. The runtime handles wiring, skip logic, and retry — you just describe what to compute.

Get Started View Examples