SpoolisDocs

Spoolis docs

Accept purchased work

Check a purchased result before a workflow continues, retries, or spends again.

Nevermined can let a LangChain agent buy what it needs. Spoolis can decide whether the purchased result actually counted before the agent spends again or continues.

The flow

agent → buy service → result → LangSmith run → Spoolis acceptance → continue / retry / hold

Accept a purchased result

acceptPurchase sends the result as evidence. Optional provider, payment, tool, and trace context stays in evidence metadata. It does not add vendor fields to the canonical Outcome.

accept-purchased-result.mjs
import { acceptPurchase } from '@spoolis/accept'

const outcome = await acceptPurchase({
  criteria: [{
    description: 'The research result includes a source URL',
    check: { checker: 'url_format', field: 'source' },
  }],
  purchase: {
    provider: 'provider-a',
    amount_cents: 25,
    currency: 'USD',
    payment_reference: 'payment-123',
    tool: 'research',
    trace_id: 'trace-123',
  },
  result: { answer: '...', source: 'https://example.com/source' },
}, { baseUrl: 'https://spoolis.com', apiKey: process.env.SPOOLIS_API_KEY })

if (outcome.nextAction.action === 'continue') continueWorkflow(outcome)
if (outcome.nextAction.action === 'retry') retryWithAnotherProvider(outcome)
if (outcome.nextAction.action === 'hold') holdForReview(outcome)

Wire a LangGraph node

evidenceFromLangSmithRun accepts the plain run object and performs no fetch. The node is a plain async state-in, state-out function, so it needs no LangGraph or LangSmith dependency.

graph.mjs
import {
  evidenceFromLangSmithRun,
  spoolisAcceptanceNode,
} from '@spoolis/accept'

const acceptPurchasedResult = spoolisAcceptanceNode({
  criteria: 'The result includes a cited source',
  options: { baseUrl: 'https://spoolis.com', apiKey: process.env.SPOOLIS_API_KEY },
  result: state => evidenceFromLangSmithRun(state.langsmithRun).result,
  purchase: state => evidenceFromLangSmithRun(state.langsmithRun).purchase,
})

graph.addNode('accept-purchased-result', acceptPurchasedResult)
// Route on state.spoolis.nextAction.action in your conditional edge.

A rejected result returns state.spoolis.status and state.spoolis.nextAction. Rejection does not throw or kill the graph.

Boundary

Spoolis returns the acceptance result. Your runtime decides whether to continue, retry, hold, or spend again. Spending authority and spend caps remain the payment rail's responsibility.

Accept purchased work · Spoolis