SuperAPIAI Directory

call4agents

github.com · AI agents

Call4Agents is a safety guard library for Python AI agents, designed to prevent agents from re-executing already-approved actions (such as payments, sending emails, bookings, etc.) after a crash, retry, or recovery. By recording intents and results, binding approvals to exact parameters, and providing mechanisms such as undo and idempotency keys, it ensures that each approved action is executed at most once. The library has no dependencies, can be integrated with frameworks such as LangGraph, Pydantic AI, OpenAI Agents SDK, and MCP, and provides command-line tools for testing an agent's crash safety.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsAPI

About this tool

Call4Agents is an open-source Python library for solving the problem of AI agents re-executing already-approved actions after a crash, retry, or recovery. When an agent performs actions with side effects such as payments, bookings, refunds, or sending emails, a retry after a program crash may cause the same action to be executed twice, resulting in duplicate payments or duplicate sends. Call4Agents ensures that each approved action is executed at most once by recording the action intent and result.

Main capabilities include:

  • One-time actions: a crash, retry, or recovery will not cause the same action to be executed repeatedly.
  • Approvals bound to exact parameters: an approval for pay(10, alice) cannot be used to execute pay(9999, mallory), and subsequent denials are enforced.
  • Undo: a way to register undo actions; c4a.undo() can undo a run in newest-to-oldest order, and each undo action is itself one-time.
  • Idempotency keys: provide the same idempotency key to external APIs so that a payment API can discard duplicate requests.
  • Recording, replay, and diffing: replay recordings offline with zero model calls, and find the step at which two runs first diverge.

Usage:

  • Mark actions that need protection with the @c4a.effect decorator, and wrap the work in c4a.run(<id>).
  • For frameworks such as LangGraph, Pydantic AI, OpenAI Agents SDK, and MCP, adapters are provided that automatically handle context parameters and run IDs.
  • Command-line tools are provided, such as a quickstart demo, a selftest self-check, and crashtest for testing an agent's crash safety.

Applicable scenarios:

  • The agent performs actions such as sending emails, payments, ticketing, or database writes, and these may be executed repeatedly due to crashes, timeout retries, or checkpoint recovery.
  • After a human approves an action, the parameters may be changed before execution.
  • A human repeatedly clicks "approve", or two worker processes process the same approval task simultaneously.
  • Calling an API that supports Idempotency-Key, with the desire to retry safely after a crash.
  • When switching models or providers, wanting to see which tool calls have changed.

Limitations:

  • If the agent only reads data, or all actions already run in a durable workflow engine that provides these guarantees, this library may not be needed.
  • Actions must be executed inside c4a.run(...), otherwise a RuntimeError is raised.
  • Tools are identified by module name and function name; moving or renaming a function will cause it to be treated as a new tool when resuming a run.
  • Parameters need a stable textual form; objects that print memory addresses will raise a TypeError.
  • If a function throws an exception, the action may or may not have occurred, and the next call will raise EffectInDoubt, which must be handled via reconcile or idempotent_for.
  • The library is in an early stage (version below 1.0), and some features (such as retries, shared limits, and rules) are experimental.
  • It uses only the standard library with zero dependencies; sharing records across machines requires optional PostgreSQL.
  • The agent testing feature will reject real accounts and only supports environment checks for known payment providers.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools