Get Started with Datadog

The Monitor

Automate the agent improvement loop in Datadog Agent Observability

Published

Read time

8m

Automate the agent improvement loop in Datadog Agent Observability
Alex Barksdale

Alex Barksdale

Senior Software Engineer

Rashel Hoover

Rashel Hoover

Senior Product Manager

Will Potts

Will Potts

Senior Product Marketing Manager

Adam Wagner

Adam Wagner

Senior Product Solutions Architect

An AI agent can look healthy while failing its users. It may return a plausible answer without completing the task, retry a failing tool, or resend oversized context on every turn. These behaviors can leave customers without an answer while increasing latency and cost. To find and fix the underlying issues, teams must inspect traces, reproduce failures, write test cases, and verify changes. Repeating that manual work for each issue slows agent releases.

Datadog Agent Observability now runs that improvement loop with you. With Insights, now generally available, Datadog continuously analyzes production traces to find recurring issues, explain their cause and impact, and recommend fixes. Connected workflows hand that evidence to your coding agent or Bits Code to prepare changes and tests. Failing interactions become regression cases that guide evaluator preparation and comparisons offline and on live traffic. Your team reviews and approves at each step, while Datadog handles the investigation and preparation in between.

We’ll follow one customer support agent through a full improvement cycle to show how Datadog can:

Detect and diagnose a recurring failure

Your support agent uses a shipment-status tool to answer “Where’s my order?” questions. During peak hours, the shipping service starts returning rate-limit errors. The agent retries immediately, repeating the failing call across several model turns before telling the customer it cannot find the order. The application reports no error, and an individual trace may appear to be an isolated failure.

Insights surfaces the recurring pattern automatically. For applications already sending traces to Agent Observability, it analyzes calls and sessions and groups repeated failures into findings. In this example, the finding points to immediate retries and instructions that fail to distinguish temporary service unavailability from a missing shipment. Insights also identifies cost opportunities such as inefficient prompt caching and oversized tool results, along with reliability issues such as prompt rule violations.

A prompt-caching finding recommends separating reusable instructions from request-specific content and outlines validation.
A prompt-caching finding recommends separating reusable instructions from request-specific content and outlines validation.

Datadog connects agent telemetry with application and user-experience context to extend the investigation beyond the agent. Linked APM traces can connect the failing tool call to the shipping service when configured RUM correlation links agent interaction to the affected customer sessions. That evidence helps determine whether to change the agent’s retry logic, the tool, or its backing service. After rollout, evaluations and user-experience signals help assess whether the change improves the customer’s experience.

Prioritize by impact

Each Insights finding includes an impact assessment with affected calls or sessions and estimates cost or potential savings where available. Severity and impact help prioritize fixes. For example, a published prompt-caching finding traced poor cache reuse to task-specific content placed before reusable tool definitions. For September 5–11, it estimated 33,262 affected calls and $91.14 in potential daily savings. Impact figures describe the opportunity; experiments and production evaluations measure what a change achieves.

Prepare a fix from production evidence

For the shipment-status finding, Insights recommends respecting the service’s retry interval and limiting retry attempts. It also recommends updating the agent’s responses to distinguish temporary service unavailability from a missing shipment.

Bits Code pairs a prompt-caching finding with a proposed repository change and an option to create a pull request.
Bits Code pairs a prompt-caching finding with a proposed repository change and an option to create a pull request.

For code changes, Fix with Bits hands the finding, recommendation, and trace evidence into a Bits Code session. With repository access configured, Bits Code prepares the change and tests for review. Our published handoff example produced a pull request for compact search previews with tests for newly retrieved and cached results. If your team uses its own coding agent, the same findings can be pulled through the Datadog MCP Server. You can also schedule that agent to work through open findings by severity: implement and test fixes, prepare pull requests, and update each finding’s status. New issues then get picked up without anyone triaging them by hand. 

Verify the change offline and on live traffic

Before you ship the retry fix, you need to know whether it helps customers get shipment information and preserves behavior that already works. Datadog’s connected coding workflow helps prepare the test data, evaluators, and experiment code for review. Compare the original and revised agent offline, then use a controlled live test to check the change under production conditions.

Test the retry fix offline

Start with the requests behind the retry-loop finding. Add those interactions to an evaluation dataset alongside successful lookups and confirmed missing shipments. Simulate rate-limit responses to test retry behavior consistently, since replaying the same question alone may not reproduce the shipping service’s failure.

For code changes, Fix with Bits hands the finding, recommendation, and trace evidence into a Bits Code session. With repository access configured, Bits Code prepares the change and tests for review. Our published handoff example produced a pull request for compact search previews with tests for newly retrieved and cached results. If your team uses its own coding agent, the same findings can be pulled through the Datadog MCP Server. You can also schedule that agent to work through open findings by severity: implement and test fixes, prepare pull requests, and update each finding’s status. New issues then get picked up without anyone triaging them by hand.  Test changes against representative interactions Before you ship the retry fix, you need to know whether it helps customers get shipment information and preserves behavior that already works. Datadog’s connected coding workflow helps prepare the test data, evaluators, and experiment code for review. Compare the original and revised agent offline, then use a controlled live test to check the change under production conditions. Test the retry fix offline Start with the requests behind the retry-loop finding. Add those interactions to an evaluation dataset alongside successful lookups and confirmed missing shipments. Simulate rate-limit responses to test retry behavior consistently, since replaying the same question alone may not reproduce the shipping service’s failure.
For code changes, Fix with Bits hands the finding, recommendation, and trace evidence into a Bits Code session. With repository access configured, Bits Code prepares the change and tests for review. Our published handoff example produced a pull request for compact search previews with tests for newly retrieved and cached results. If your team uses its own coding agent, the same findings can be pulled through the Datadog MCP Server. You can also schedule that agent to work through open findings by severity: implement and test fixes, prepare pull requests, and update each finding’s status. New issues then get picked up without anyone triaging them by hand.  Test changes against representative interactions Before you ship the retry fix, you need to know whether it helps customers get shipment information and preserves behavior that already works. Datadog’s connected coding workflow helps prepare the test data, evaluators, and experiment code for review. Compare the original and revised agent offline, then use a controlled live test to check the change under production conditions. Test the retry fix offline Start with the requests behind the retry-loop finding. Add those interactions to an evaluation dataset alongside successful lookups and confirmed missing shipments. Simulate rate-limit responses to test retry behavior consistently, since replaying the same question alone may not reproduce the shipping service’s failure.

Define successful behavior

Next, define what the support agent should do in each case. Datadog’s coding-agent workflow can propose evaluators from the observed failure and prepare experiment code. Your team reviews the criteria and generated code before the experiment runs.

For the shipment-status fix, evaluate these outcomes separately:

  • Successful lookup: The agent retrieves the correct shipment status.

  • Missing shipment: The agent correctly reports that no shipment was found.

  • Temporary unavailability: The agent respects the retry policy and explains that the status cannot currently be retrieved.

Score task completion separately from appropriate error handling. An accurate unavailability response helps the customer understand the failure, but it does not mean the shipment status was retrieved.

Compare the original and revised agent

Datadog runs the original and revised support agent against the same dataset using offline experiments. The comparison measures task completion and correctness alongside token use and latency, and highlights cases where the revised version performs worse. Review those cases before deciding whether the fix is ready for a live test.

Validate the fix on live traffic

Customer phrasing, traffic peaks, and the shipping service’s behavior can expose problems an offline dataset misses. Before expanding the retry fix, compare it with the current agent on a limited share of live traffic. Datadog’s coding-agent workflow helps prepare the comparison, including the traffic split and outcome metrics. Your team reviews the setup and starts the experiment. Datadog assigns users or workflow runs to a version and evaluates both versions against the same criteria.

A synthetic experiment compares token use and answer-quality metrics for standard and cache-optimized prompts.
A synthetic experiment compares token use and answer-quality metrics for standard and cache-optimized prompts.

For the shipment-status fix, compare successful lookups and appropriate handling of missing shipments or temporary failures alongside response time and estimated cost. Waiting between retries may lengthen an interaction while reducing failed calls. The results help you decide whether to expand the rollout, revise the fix, or investigate further.

Monitor production and feed the next improvement cycle

Once the retry fix is running in production, you need to know whether customers continue receiving useful shipment updates and whether the failure returns. Datadog keeps analyzing production traces and running the evaluations you configure after the experiment ends.

Insights follows the original retry-loop finding as new traces arrive. Later analyses resolve it automatically when the behavior no longer appears. If the retry loop persists, the finding remains visible. If it returns after resolution, Insights surfaces it again.

Evaluators keep checking whether the agent retrieves the correct status or handles missing shipments and temporary failures appropriately. Review those scores alongside latency and estimated cost to assess the change’s overall impact.

Raise the baseline for the next release

Keep the rate-limit cases and other interactions that exposed the failure in your evaluation dataset. Once the revised agent meets your release criteria, use its results as the baseline for the next change. With offline experiments configured in CI, each pull request can rerun those cases and compare outcomes against that baseline.

A coding agent scheduled to review Insights can pick up new or recurring findings, prepare the next change, and add relevant production examples to the dataset. The next cycle tests against the latest verified baseline, so your team can check for improvements and regressions before deciding whether to ship.

Continuously improve your agents with Agent Observability

Datadog takes on recurring diagnosis, change preparation, test maintenance, and verification so teams can improve performance and quality, reduce avoidable cost, and release improvements faster. Insights connects production behavior to a change worth testing, while connected coding agents and evaluations carry the work through implementation and measurement. Production results guide the next iteration as agent behavior and usage evolve.

Applications already sending traces can access Insights without additional configuration. Connect the coding workflow and evaluation skills to carry findings into proposed changes and repeatable tests, or read how Datadog uses Insights to improve its own agent for a worked example. If you’re new to Datadog, . For startups, eligible teams can get a year of free Datadog credits. Apply to Datadog for Startups here.

Start monitoring your metrics in minutes