4 December 2026

AI and agents, every day. Straight to it.

ToolsQuick notes

The traccia-py library vets each AI agent call against policies before it runs

The @govern decorator blocks calls that exceed spending or loop limits before they run.

Bia Kanashiro

· 2 min read

Read in Portuguese

The traccia-py Python library, from the traccia-ai organization and licensed under Apache 2.0, checks every model or tool call an agent makes before it executes. The traccia-py repository on GitHub surfaced on Hacker News on November 9; that date reflects discovery, not the original release.

Prerequisite: runtime policies require a Traccia account.

  1. Install with pip install traccia openai.
  2. In the Traccia app, add a Loop Cap policy capped at 3 tool calls per run, switch it to Block mode and copy the API key.
  3. Decorate the agent function with @govern.
from traccia import init, observe, govern, AgentBlockedError

init(api_key="...", agent_id="research-agent") # API key from app.traccia.ai

@observe(name="web_search", as_type="tool")
def web_search(query: str) -> str:
    return f"results for {query}"

@govern(name="run_agent")
def run_agent(topic: str) -> None:
    while True: # a bug: the agent never decides it has enough
        web_search(topic)

try:
    run_agent("agent observability")
except AgentBlockedError as exc:
    # The 4th search is denied before it runs.
    print(exc.reasons, exc.decision_id)

Because the loop never exits, the fourth search is denied before it runs and raises AgentBlockedError. A Spend Cap policy works through the same decorator: it halts a model call that would exceed the USD budget, or sends it to a cheaper model.

When Traccia is unreachable, calls are blocked by default, and init(policy_fail_mode="open") lets them through. In Observe mode, a policy only logs what it would have stopped.

Bia Kanashiro

Guides & prompts.

Read articles by Bia KanashiroEditorial policy
Report an error

Use 10–1,000 characters; a reply email shares this space.

Next in your reading list