Skip to content

00Integration guide

CrewAI

An after_tool_call hook that records every tool any agent in a crew uses.

Walkthrough · recorded against a local Ovelin

CrewAI's @after_tool_call hook runs after every tool any agent in the process uses. One decorated function records the whole crew. Each event is filed under the agent's role, so every role shows up as its own agent in Ovelin.

Prerequisites

  • A model provider key for the LLM your agents use (the example uses OpenAI, OPENAI_API_KEY).
  • Python 3.10 to 3.13 and the Python Ovelin client from the Python guide.

1. Get an API key

  1. In Ovelin, open Settings → API keys.
  2. Under Ingest key, create a key and copy it. It is shown once; Ovelin keeps only a hash.
  3. Copy the Organization ID from the same page.

Put all three values in your environment, not in code:

sh
export OVELIN_URL="https://your-ovelin-host"   # http://localhost:3000 for a local instance
export OVELIN_ORG_ID="your-organization-id"
export OVELIN_API_KEY="agl_live_…"

An organization key can report for any agent. For production, give each agent its own key under Settings → API keys → Agent keys: a leaked agent key can then only write as that one agent, and you can revoke it alone.

2. Install

sh
pip install crewai requests

3. Minimal working example

examples/python/crewai_agent.py
"""A CrewAI crew whose every tool call is recorded in Ovelin.

CrewAI's after_tool_call hook runs for every tool any agent in the process
uses, after it returns. Returning None leaves the tool's result unchanged.
"""

from crewai import Agent, Crew, Task
from crewai.hooks import after_tool_call
from crewai.tools import tool

from ovelin import RUN_ID, log_event


@tool("lookup_invoice")
def lookup_invoice(invoice_id: str) -> str:
    """Look up an invoice by id."""
    return f"{invoice_id}: overdue, EUR 4,200, billing@example.com"


@tool("send_reminder")
def send_reminder(invoice_id: str, email: str) -> str:
    """Email a payment reminder for an invoice."""
    return f"Reminder for {invoice_id} sent to {email}"


@after_tool_call
def record_in_ovelin(context) -> None:
    log_event(
        context.agent.role if context.agent else "crewai-agent",
        context.tool_name,
        data_accessed=["financial_data"],
        metadata={"tool_input": context.tool_input},
    )
    return None


collector = Agent(
    role="collections-agent",
    goal="Get overdue invoices paid",
    backstory="You chase overdue invoices politely and keep a clean record.",
    tools=[lookup_invoice, send_reminder],
    llm="gpt-5.1",
)
task = Task(
    description="Invoice INV-1042 is overdue. Look it up, then send a reminder to its billing contact.",
    expected_output="One sentence saying what was done.",
    agent=collector,
)
print(Crew(agents=[collector], tasks=[task]).kickoff())
print(f"Recorded in Ovelin under run {RUN_ID}")

The hook returns None, which leaves the tool's result unchanged. To record only some tools, use @after_tool_call(tools=["send_reminder"]).

4. Run it

sh
cd examples/python
python crewai_agent.py

5. Check it in Ovelin

  1. Open Activity. The newest rows are the events you just sent, each with a sequence number and a seal.
  2. Click one. The detail panel shows the payload as received; Recompute seal checks its seal again.
  3. One event per tool call under the agent collections-agent. Open Agents: an agent name Ovelin had not seen before is registered automatically, without an owner. Give it one so someone is accountable for it.

To confirm nothing was altered later, open Integrity. It recomputes every seal and every link between records, and reports Trail intact.

Common errors

ResponseCauseFix
401 Invalid API keyThe key is wrong, revoked, or belongs to another organization.Create a key in Settings → API keys and check OVELIN_ORG_ID is the same organization's.
401 Missing API key (use Authorization: Bearer <key>)The Authorization header was not sent.Send Authorization: Bearer $OVELIN_API_KEY. The key never goes in the body.
422 Payload must include a 'source' fieldThe JSON has no source.Add "source": "custom" (or n8n, make_com, openai_api, zapier).
422 Invalid option: expected one of "success"|"failure"|"unknown"outcome has another value, such as warning.Use success, failure or unknown.
400 Invalid organization idOVELIN_ORG_ID is not the organization's UUID.Copy the Organization ID from Settings → API keys.
429 Rate limit exceededMore than 600 events a minute for one organization.Retry after the Retry-After header. To send many events, use the batch endpoint (up to 100 per request).
No eventsThe module with the hook was never imported.Hooks register on import; import it before kickoff().

How this guide is tested

Every code block above is copied from examples/python/crewai_agent.py by node scripts/sync-guide-snippets.mjs, and pnpm examples:test runs it against a local Ovelin and checks the events were sealed. The model is replaced by a local scripted stand-in (examples/_testing/scripted-model.mjs) that calls the tools in a fixed order, so the test needs no provider key; with a real key, unset ANTHROPIC_BASE_URL/OPENAI_BASE_URL and the same code talks to the provider.