explaingit

sangaraju1988/latch

Analysis updated 2026-05-18

1PythonAudience · developerComplexity · 3/5LicenseSetup · easy

TLDR

A Python library adding idempotency, timeouts, circuit breaking, budget limits, and rollback sagas to AI agent tool calls.

Mindmap

mindmap
  root((latch))
    What it does
      Wraps agent tool calls
      Prevents duplicate effects
      Adds rollback support
    Primitives
      Idempotent decorator
      Circuit breaker
      Timeout and budget
      Saga compensation
    Use cases
      Payment safety
      Runaway loop protection
      Multi step rollback
    Audience
      Agent framework builders

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Prevent a payment tool from being charged twice when an agent retries after a timeout

USE CASE 2

Stop an agent from hammering a failing API using a circuit breaker

USE CASE 3

Automatically roll back a multi step booking flow if a later step fails

What is it built with?

Python

How does it compare?

sangaraju1988/latch0xustaz/streamgatea-bissell/unleash-lite
Stars111
LanguagePythonPythonPython
Setup difficultyeasyhardhard
Complexity3/54/54/5
Audiencedeveloperdeveloperresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Installs via pip with zero required dependencies in the core.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

latch is a Python library that adds reliability protections around the tool calls an AI agent makes, the kind of actions where an agent calls an external function to do something like charge a payment or send an email. When an agent's tool call times out, the agent often cannot tell whether the underlying action actually completed, so retrying is the natural response, but a retry can cause the same charge or email to happen twice if the tool is not designed to handle repeated calls safely. The library offers five small, independent building blocks that can be combined as needed. An idempotency decorator caches the result of a tool call under a unique key, so a repeated call with the same key returns the cached result instead of running the action again. A circuit breaker decorator stops calling a dependency after it fails several times in a row, rejecting further calls immediately until a recovery period has passed. A timeout decorator bounds how long a single tool call is allowed to block the agent, cancelling async calls cooperatively and unblocking sync calls from a background thread. A budget guardrail decorator limits how many calls or how much cost can occur within a time window, which helps prevent a runaway agent loop from spending too much money. A saga class handles multi step operations, such as charging a card, then booking a flight, then booking a hotel, automatically undoing already completed steps in reverse order if a later step fails. The library has no required dependencies in its core, works with both regular and async functions, and is meant to be dropped into any agent framework, including OpenAI style tool calling and LangChain, without forcing that framework to become a dependency of latch itself. It also includes an optional tracing feature for observing cache hits, circuit trips, timeouts, and rollbacks, plus a chaos testing feature that deliberately injects failures so you can confirm the protections actually work. It is installed with pip and licensed under MIT.

Copy-paste prompts

Prompt 1
Show me how to wrap my create_order function with the idempotent decorator
Prompt 2
Explain how the Saga class compensates already completed steps on failure
Prompt 3
Help me add a budget_guardrail to cap spend on my LLM calling function
Prompt 4
Walk me through using latch's OpenAI tool calling adapter

Frequently asked questions

What is latch?

A Python library adding idempotency, timeouts, circuit breaking, budget limits, and rollback sagas to AI agent tool calls.

What language is latch written in?

Mainly Python. The stack also includes Python.

What license does latch use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is latch to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is latch for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.