Get started
In this tutorial, you’ll use Patterns to find costly behavior in sample support conversations, test whether a cheaper model can handle those requests, then have Loop propose a code change for your coding agent to review. You’ll need:- A Braintrust account with an API key
- A GitHub account
- Python 3.12 or later and
uv - A coding agent connected to Braintrust
Set up the project
You’ll work with 600 simulated support conversations, spread over the last two weeks, in which customers ask an agent to change flights, return orders, or fix phone service. Each conversation is a trace with the agent’s model and tool calls, a task success score, and metadata about the customer, model, agent version, and cost.1
Import the sample conversations
Download the sample importer and the sample data (about 130 MB), then import the conversations into a new project called Sample - Support agent - tutorial:Replace
<your-org> with your organization name. The import should report 600 traces and 20,239 spans.2
Check the imported traces
3
Set the user and session ID fields
Ask Loop or your coding agent to set the project’s user and session ID fields, so Patterns counts affected users and sessions instead of individual traces:Run in Loop
4
Connect the agent's code
Loop needs a copy of the agent’s code so it can cite the code in findings and open a pull request with a fix. Connect it before you enable Patterns, so discovery can include code evidence.
- Create a fork of the sample support-agent repository.
- Connect GitHub and give Loop access to your fork.
- Connect the fork to your project, and allow Loop to create pull requests.

5
Enable Patterns
Enable Patterns. Optionally connect Slack and select a channel for alerts.

Wait for the first discovery run to finish, which can take 30 minutes or more.


Find a problem
Patterns uses Loop to investigate your traces on a schedule and report recurring problems. Each finding, called a pattern, has a severity, a count of the users or sessions it affects, and the traces that show it. With a connected repository, a pattern can also cite the code involved. In this section, you’ll review a pattern, then focus the discovery rule on cost to find a model that’s more expensive than it needs to be. Findings and their titles vary between runs. See Review and act on patterns for everything a pattern includes.1
Scan the Patterns list
Open Patterns. Each row is a recurring problem with its severity, summary, categories, and when it was first and last seen.Because you set the user ID field, the counts show how many distinct customers each pattern affects instead of how many traces. A problem that appears in 300 traces might come from a single customer. Compare severity and affected users to decide which pattern to open first.

2
Examine a pattern
Open a pattern and read its summary. Below its name, check how widespread it is: the share of traffic it affects and when it was measured. A 
~ marks an estimate from a sample.Open a supporting trace and inspect the highlighted evidence. If the pattern includes code evidence, use the Code tab to review the cited implementation. Check that the evidence supports the pattern.
3
Add a cost concern
To focus on cost, open Pattern discovery from the rules menu. Under Watch for, add:Under Custom instructions, enter:Click Save and then Run now.

4
Find a cost pattern
The run can take a while. To follow its progress, open the rules menu in the page header and click next to Pattern discovery. Loop’s thread for the run opens in a new tab, where you can watch the searches it runs and the traces it reads.When the run finishes, look for a new pattern in the Cost category. A cost pattern describes money spent without a better result, such as one model accounting for a large share of spend on a small share of conversations.Open the pattern and check its evidence:
- Summary: Names the expensive model, the agent version, the requests involved, and the cost difference, measured from
metadata.cost_usd. - Models: If the breakdown is available, compare each model’s share of matches with its share of all traffic. If an expensive model’s share of matches is much higher than its share of traffic, that model is driving the cost.
- Evidence: Open a few supporting traces and confirm the model, agent version, cost, and
task_successscore in each. - Failed calls: Failed or retried model calls raise a conversation’s cost, so a cost gap can reflect errors rather than model pricing.

Compare models
The cost pattern gives you a hypothesis: a cheaper model could handle the same requests. An eval tests that hypothesis on a fixed set of cases.1
Build a baseline eval
With the cost pattern open, click Loop agent at the bottom right. Loop attaches the pattern automatically. Paste this prompt to build a baseline:
2
Run the baseline
In the conversation, review the cases and scoring criteria Loop proposes. To see every case, open the Model cost comparison dataset in Datasets, and compare a few cases with their source traces. When they look right, ask Loop to run the baseline:When the run finishes, Loop summarizes the results in the conversation. To inspect individual cases and their scores, open the experiment from the link Loop provides.

3
Compare a cheaper model
In the same conversation, ask Loop to compare a cheaper model:
4
Review the comparison
Read Loop’s comparison in the conversation, which lists the cases where the models differ. To check a disagreement, open the case in the experiment and read the scorer’s explanation.
If the cheaper model’s quality is close to the baseline’s at a lower cost per successful case, continue to Make and verify the change, where Loop updates the agent to send these requests to the cheaper model. If quality drops more than you can accept, investigate the failing cases before changing the agent.

Make and verify the change
Loop turns the eval result into a pull request in your fork that sends those requests to the cheaper model. Before you merge, your coding agent reviews it against the original traces.1
Open a pull request with Loop
Continue in the same Loop conversation:
2
Review the pull request with your coding agent
Clone your fork and check out the pull request’s branch:In the pattern’s header, select Investigate > Copy as prompt. Paste the brief into your coding agent in your local clone, along with the PR and experiment links. Ask it to review:
3
Test before merging
Address the blocking issues from the review and run the changed agent on representative conversations before merging. Check task outcomes, the model recorded in new traces, and total cost, including fallbacks.The new traces should show which requests used the cheaper model and whether they succeeded. If they still use the original model, inspect the routing and fallback behavior before claiming savings.
Close the loop
Your rating and notes on the pattern tell Loop and your teammates what you did about it.1
Rate the pattern
Under Is this pattern useful?, click Yes or No, add a reason, and click Submit. Yes lets Loop reopen the pattern if the behavior returns after it closes. No closes the pattern and tells Loop not to reopen or recreate a matching pattern while your reason still applies.
2
Link the pull request
In the pattern’s Activity, add a comment with the PR link so teammates can follow the work. Mention a teammate to notify them.
Next steps
Apply the workflow to your own agent: add tracing, use Patterns to identify a problem, and build an eval to test a change.Explore more capabilities
Build on the tutorial with Loop, playgrounds, human review, and evals in CI.

