DEV Community

pmestre-Forge
pmestre-Forge

Posted on

Stop Flying Blind: Add Audit Logs to Your AI Agent in 5 Minutes

The Problem Nobody Talks About

You ship an AI agent. It runs in production. Something goes wrong.

Now what? You dig through stdout logs, reconstruct what the LLM "decided," and try to figure out why it did that at that moment. It's painful — and most teams solve it by building a custom observability stack before they've even validated the product.

I ran into this exact wall while building botwire.dev, an agent infrastructure API. So I added Agent Audit Logs as a free primitive: a simple POST /logs/{agent_id} endpoint that gives every agent an immutable, timestamped activity trail — no setup required.

Here's how to wire it into your agent in about 5 minutes.


Setup

No SDK to install. Just your HTTP client of choice. If your agent already has an identity registered (also free):

import httpx

BASE_URL = "https://botwire.dev"
AGENT_ID = "my-trading-agent-v1"
Enter fullscreen mode Exit fullscreen mode

Logging an Action

def log_action(action: str, reason: str, result: str = None, metadata: dict = None):
    payload = {
        "action": action,
        "reason": reason,
        "result": result,
        "metadata": metadata or {}
    }
    r = httpx.post(f"{BASE_URL}/logs/{AGENT_ID}", json=payload)
    return r.json()

# Example: log a trading decision
log_action(
    action="BUY NVDA",
    reason="RSI oversold + ADX trending + MACD crossover confirmed",
    result="order_placed",
    metadata={"confidence": 0.82, "price": 118.40, "signal_id": "sig_8x2k"}
)
Enter fullscreen mode Exit fullscreen mode

That's it. The entry is written, timestamped server-side, and immutable. You get 100 free writes per day per agent.


Reading It Back

def get_audit_trail(limit: int = 50):
    r = httpx.get(f"{BASE_URL}/logs/{AGENT_ID}", params={"limit": limit})
    for entry in r.json()["logs"]:
        print(f"[{entry['timestamp']}] {entry['action']}{entry['reason']}")

get_audit_trail()
Enter fullscreen mode Exit fullscreen mode
[2025-05-11T14:32:01Z] BUY NVDA — RSI oversold + ADX trending + MACD crossover confirmed
[2025-05-11T14:28:44Z] SKIP TSLA — confidence below threshold (0.51)
[2025-05-11T13:01:22Z] HOLD AAPL — no signal consensus
Enter fullscreen mode Exit fullscreen mode

When something breaks, you have a clean chain of custody: what the agent decided, why, and what happened.


Pair It With Other Primitives

The audit log works well alongside the rest of the platform:

  • Agent Memory — store state between runs ($0.001/read, $0.002/write)
  • Trading Signals — BUY/SELL/HOLD with RSI, MACD, ADX confidence scores
  • Agent Notifications — subscribe to market_open/market_close events, poll GET /notify/check/{agent_id}
  • Agent Config Store — 50 free key-value entries per agent for schedules, rules, flags

Micropayments on the paid endpoints run via x402 over USDC on Base L2 — sub-cent pricing, no subscription required.


Pricing

Operation Cost
Write log entry FREE (100/day)
Read audit trail FREE

No credit card. No rate-limit surprises for the free tier.


Why I Built This

Most agent infrastructure is either "roll your own" or "pay for a full observability platform." I wanted something in between — lightweight primitives you can compose without lock-in.

The whole stack is FastAPI + SQLite + Python, MIT licensed, and self-hostable if you'd rather own it.

GitHub: github.com/pmestre-Forge/signal-api

Top comments (0)