What to log and monitor when an AI agent runs in production
Why an agent needs more logging than ordinary software
A normal program follows code you can read, so an error points to a line. An agent decides its steps on each run, so the same task may take a different path tomorrow. Without a record of what it read, what it chose and what it changed, you cannot explain a bad result or prove that a control worked.
Logs answer three questions: what happened, why the agent chose it and what it cost. They also feed your weekly review and your test set, because every real failure you find should become a test case.
What to log for every task
Log enough to rebuild the task later, and no more. A useful record for each run includes the following.
- The request and the trigger that started it, such as a new enquiry or a scheduled run.
- The records and documents the agent read, by identifier, not by copying their full contents.
- Each tool call, with its inputs, its result and the time it took.
- The output the agent produced, such as a draft reply or a proposed update to a record.
- Every approval or rejection by a person, with the name of the approver and the time.
- The model name and version, the prompt version, and the number of input and output tokens.
- The cost of the task, calculated from those token counts at the provider's current published rates.
- The step count, the number of retries and the final status: completed, escalated or stopped.
Use traces to follow one task from start to finish
A trace links every step of one task under a single identifier, so you can open it and read the sequence in order. Many observability tools support this pattern for model calls, and some agent platforms show traces in their own dashboards. Check each tool's documentation for how it records traces and how long it keeps them.
A trace is the fastest way to answer why an agent did something, because it shows the model's decision next to the tool results it was given. Use the same identifier in your CRM, your helpdesk and the agent's logs, so a customer complaint can be traced back to the exact run that produced the draft.
Set alerts for loops, failures and unusual spend
Alerts turn logs into action. Three patterns usually signal trouble. A loop, where the same tool is called again and again with no change in the result, shows up as a high step count. A rise in failed tool calls often means a connected system changed a field or lost access. A sudden jump in cost per task can mean long documents are being sent unnecessarily or a retry storm has started.
Set the thresholds in advance, from your sample of real tasks, and agree who receives each alert:
- Stop the run when the step limit or a time limit is reached, and record it as stopped.
- Alert the owner when failures within one hour pass a level agreed in advance.
- Alert on cost per task at a level you chose from real data, not from a guess.
Review a sample of real tasks every week
Dashboards show averages, and averages hide the bad cases. Each week, pick a random sample of tasks, deliberately including escalated and rejected ones, and read them against the standard you wrote for testing. Note each failure and add it to the test set. Track whether the failure rate is falling over time and whether reviewers still agree with each other.
Sampling is also a control on people. If reviewers approve everything without reading, the logs look healthy while the agent drifts. Rotate who does the review, and record how long each review took, because that time is part of the real running cost.
Handling personal data in logs
Logs are data too, and they often hold more personal information than the original system. A log that copies a full customer email, a phone number or a payment detail creates a second copy that many people may read. Store references to records rather than their contents where you can, and mask fields such as names, phone numbers and card numbers before they are written.
Decide retention before launch: how long logs are kept, who can read them and how they are deleted. Check your privacy obligations with a qualified local adviser, and read the data terms of each logging provider, because your logs will be stored there.
How Hundred Seas helps
Hundred Seas is a product studio in Taipei that builds AI agents and AI CRM systems on Claude and on OpenAI models. We choose the model for each task on cost, speed, quality and where the client's data has to stay, and those choices shape what must be logged and where the logs can safely live.
Our work begins with a scope step of about one week at a fixed price. It ends in a written plan, a clickable prototype and a firm quote. The build then arrives in weekly releases of working software, and a monthly run plan keeps the software running and up to date.
Questions
- How long should I keep agent logs?
- Keep logs only as long as you need them for audits, disputes and improvement, and write that period into your privacy notice and internal policy. Shorter retention lowers risk. Ask a qualified adviser what your local privacy law requires, because obligations differ by country and by the kind of data involved.
- Can I log the full prompt and the model's reply?
- You can, but treat those records as sensitive. A prompt often contains a customer's message or record, so the log becomes a copy of personal data. Log a reference, a hash or a masked version where possible, and keep full text only for a short period and for named staff who need it.
- What is the difference between logging and tracing?
- Logs are individual records of events, such as a tool call or an approval. A trace ties all the events of one task together in order. You need logs to hold the facts and traces to read the sequence. Many tools provide both, and the same trace identifier should appear in every log line.
- What should trigger an immediate alert?
- Alert on anything that could cause harm quickly: a run that writes to many records at once, a loop that keeps calling a payment or messaging tool, a sudden spike in cost, or a connected system returning errors on every call. Lower-risk problems can wait for the weekly review.
- Who should be able to read the logs?
- Give access to the people who run the process and the people who review quality, and keep the list short. Engineers need logs to fix faults, and business owners need them to judge results. Anyone with access should know that logs can contain personal data and must be handled that way.