Skip to content
OFFICIAL CA0xdafaa1ed0b9f5746a0cfa2be80371cf06a986977

Documentation

LangChain plugin

npm: @upoch/langchain@langchain/core 1.x

One callback for a LangChain or LangGraph agent: every swap, transfer or trade tool call is checkpointed before and after it runs, and the agent can roll back to the last good state.

What it does

  • Automatic checkpoints. Before and after every consequential tool call (swaps, transfers, bridges, staking, lending, trades, mints, launches and approvals), UpochCallbackHandler saves a verified checkpoint on Robinhood Chain, with the transaction hash when the tool returns one. LangChain waits for the pre-tool checkpoint to commit before the tool runs.
  • Rollback. With upochTools(), the model can restore its last checkpoint at the start of a task and roll back to the checkpoint right before the last swap or transfer, or to one you name, and continue from there.
  • Works with LangChain and LangGraph (JavaScript and TypeScript). Every checkpoint opens in the Time-Travel Debugger.

Setup

Once, in your own terminal (Node.js 24 or later):

terminal
npm install -g @upoch/guard
upoch setup                      # keys, funding, registration

upoch setup creates two keys on your machine: the owner, which registers the agent, and the executor, the agent's key, which can only submit checkpoints. It waits while you send the owner a little ETH on Robinhood Chain (0.001 ETH is plenty), then registers the agent and gives the executor gas for checkpoints. Then add the callback to your agent:

agent.ts
// npm install @upoch/langchain
import { UpochCallbackHandler, upochTools } from "@upoch/langchain";

const upoch = new UpochCallbackHandler();

// Automatic checkpoints around consequential tool calls:
await agent.invoke(input, { callbacks: [upoch] });

// Optional: let the model restore, checkpoint and roll back itself.
const tools = [...yourTools, ...upochTools({ handler: upoch })];

Tools for the model

Tool
upoch_restoreLatest checkpoint, verified against the chain, and which actions completed
upoch_checkpointSave the current state
upoch_rollbackGo back to an earlier checkpoint and continue; by default the one right before the last swap or transfer
upoch_historyRecent checkpoints
upoch_completeMark the task finished

A rollback restores the agent's state; it cannot reverse transactions that already happened on-chain. The tools list the actions that ran after the restored checkpoint so the agent can account for them.

Options

agent.ts
new UpochCallbackHandler({
  watch: ["swap_tokens", "send_eth"],   // exact tool names, or a RegExp (default: value-moving names)
  state: () => myAgentState,            // what each checkpoint holds (default: the log of watched tool calls)
  strict: true,                         // stop the tool when its pre-tool checkpoint fails (default false)
});

Safety

  • Each checkpoint is one transaction from the executor key, with a daily limit (100 by default, maxCheckpointsPerDay in ~/.upoch/config.json).
  • State that looks like private keys, seed phrases or API tokens is refused before anything is stored: checkpoints are permanent.
  • Keys stay on your machine in ~/.upoch/secrets.json, unencrypted (owner-only permissions on macOS and Linux). Back it up, and keep only small amounts on these keys.
  • The Upoch contracts have not been audited.