New Tool Radar

AI Concepts

How to Log Agent Tool Calls as an Audit Trail

Log every agent tool call with its arguments, result and timing so any action can be traced back afterwards.

Schematic illustration of log agent tool calls as an audit trail: step one log the call, step two log the result, step three keep the log.

An agent that acts needs an audit trail: a log of every tool call, its arguments, its result and when it happened. Without it, a wrong action cannot be traced, a disputed result cannot be checked, and a repeated task cannot be compared with the last run. Log in your code, where the calls are executed, not in the model, which cannot be trusted to report its own calls.

Prerequisites

  • An agent loop that executes tool calls in your code.
  • A log store: a file or a database table.
  • A rule for how long logs are kept.

Steps

Step 1: Log the call

Before running a tool, log the time, the tool name, the arguments and the task id. This is the record of what the agent asked to do.

Step 2: Log the result

After the tool returns, log the result or the error, and how long the call took. A call without a result in the log is a call that cannot be audited.

Step 3: Keep the log

Keep the log where the team can read it, and keep it for the period your work needs: a month for routine tasks, longer for anything involving money or personal data. Do not log secrets such as API keys or passwords.

Worked example: Cedar Street Library renewal agent

The fictional Cedar Street Library’s agent renews a reader’s card. The log records 3 calls.

Call Tool Duration Result
1 get_reader 1.2 seconds Reader found
2 check_fines 0.8 seconds No fines
3 renew_card 2.4 seconds Renewed to 2027-06-30

The 3 calls are logged with durations totalling 4.4 seconds, and the renewal to 2027-06-30 can be traced to call 3.

Expected result. Every tool call has a log entry with its arguments, result and timing, and the log is kept where it can be read. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • Logs can contain personal data; treat them with the same care as the data itself.
  • Never log credentials, tokens or passwords, even in an error message.
  • This guide does not cover alerting on suspicious calls.

Sources

See all