Skip to content
View original post on X: Taha Rafiq
Published
Pick

Taha Rafiq shares lessons on building useful agents and harnesses

AITaha Rafiq shares lessons from building agents at Meta, Google DeepMind, and on personal projects, including Meta’s internal AI data scientist. He recommends building verification into agent tools, reading traces to find failure modes, avoiding over-engineered harnesses, and designing feedback loops around users’ work.

AIWhy it matters.

Rafiq connects verification, trace review, simpler tool surfaces, and user feedback to practical ways of diagnosing and improving agent harnesses.

Taha RafiqVerified on X
@taha_rafiq
View on X

Finally got some time to write down some of my learnings from building useful agents and harnesses from the last couple of years :)

TL;DR:
* Build verification first
* Read agent traces
* Don't over-engineer it
* Build in-product feedback loops https://x.com/i/article/2119802990777556992

On Agents and Harnesses

Link to source post with interactive demos

These are a few of the things I’ve learned over the past couple of years building agents that actually work, at Meta (e.g. Meta’s internal AI data scientist), Google DeepMind, and for personal projects (e.g. JS Game Zero).

An agent is a model plus a harness: the prompts, tools, execution environment, and feedback loops around it. You rarely control the model, but you always control the harness.

Build verification first

The quality of an agent’s output drastically increases when you give it an easy way to verify its own work through tools. This sounds basic, but it’s the number one harness-level reason agents perform poorly on a task: the harness gives the agent no easy way to check what it just produced.

Take an agent built for data analysis. We want it to discover data sources, understand how tables relate to each other, explore the data by running queries, figure out the right query shape to get the answers you need, build visualizations, and present the findings. That is a lot of steps where things can quietly go wrong. How might we give this agent concrete ways to verify its work?

One shape verification can take for this agent is a set of three tools:

1. runQuery(sql): Run queries and inspect the results. This is essential for the agent to build its own understanding of the dataset (like checking row counts, nulls, and column values) and sanity-check that the final numbers look reasonable.

1. buildVisualization(code): Execute code (e.g. Python with matplotlib) to generate charts and return the rendered image so a model with vision capabilities can actually look at the chart and catch broken layouts or empty plots.

1. userResponse(citedAnswer): Respond to the user only after deterministically validating that the citations in the answer are real and backed by the queries the agent actually ran, returning an error to the agent if they aren’t.

This three-tool setup makes verification concrete, though it is not the only valid shape. In fact, having separate tools for queries and charts is already slightly over-engineered (we’ll refactor this into a better shape below, and you can play with the combined interactive demo on my site).

Read the traces

Okay, I lied earlier when I said missing verification is the number one reason agents perform poorly. Missing verification is the number one architectural bug, sure. But the actual number one reason your agent is failing is that nobody is sitting down and reading the raw agent trajectories (traces) to see where it gets stuck.

Actually reading the transcripts (or having an agent analyze them) teaches you a lot about the failure modes for the agent. By reading traces, you can immediately spot failure modes such as:

- Prompt overfitting: The agent forces a tool call because your prompt hammered a rule too hard (“I must call tool X since the prompt emphasized it five times”).

- Silent fallback when blocked: The agent hits a broken environment and bluffs its way through (“I need to write code, but the execution environment keeps throwing an error. Oh well, let me return it as is and make up something that sounds plausible”).

- Missing or painful verification: The agent flies blind (“I built this graph, but I have no way to see the image”) or takes lazy shortcuts because verification has too much friction (“I have to use the browser to verify this, so let me click around twice, take a screenshot, and call it a day”).

- Poisoned metadata and wrong turns: The agent gets derailed by bad upstream documentation (“Inspecting these tables... ah, this one has a description in all caps saying ALWAYS USE THIS FOR DOING XYZ”).

A trace that reported success. The agent couldn't look at its own chart, so it confidently described one that doesn't exist. Spot the failures yourself →

Or have an agent read all of them: last week's 1,200 traces, clustered by failure mode, each with a concrete fix. Run the analyzer →

Don’t overengineer it

There are many ways to overengineer a harness. Almost all of them make it harder for the agent to do its job, and harder for you to figure out how to fix it.

This might be surprising, but coding agents are actually not good at building harnesses yet. Left to their own devices, coding agents love to pile on defensive prompt rules and narrow wrapper tools. Good harness design still requires a lot of human judgment. Common pitfalls include:

Prescriptive prompts: Rather than giving the agent clarity on what a good outcome looks like, the prompt lays out a rigid step-by-step algorithm (“first call tool X, then call tool Y, then assemble the response using this exact template”). If you are doing this, you probably don’t need an agent: you need a deterministic workflow with a few LLM calls in the middle. For an actual agent, aim for the right prompt altitude by setting clear expectations on the process and the bar for the final response (“Explore the data incrementally to understand the relevant tables and column values. You may need to investigate several paths before formulating your response. Your final answer should be a well-cited artifact that references the queries you ran and explains your methodology clearly”).

More than one way to do something: Every tool needs a distinct purpose, and the agent shouldn’t have multiple overlapping tools competing to do the same job. While general-purpose runtimes like Bash and Python naturally overlap, your custom tool surface should give the model an obvious default path. When it looks to the LLM like there are three slightly different ways to do the same thing, you get unpredictable tool selection.

Narrow tools: Providing overly narrow tools leads to tool explosion and degraded quality. Earlier, I mentioned that our three-tool verification setup for the data analysis agent was slightly over-engineered. Can you spot why? We gave the agent two separate, narrow tools for running SQL and building charts (runQuery and buildVisualization), when what it really needs is a general-purpose, notebook-style code execution environment (paired with userResponse(citedAnswer) for citation checks):

1. createNotebook(): Creates a new stateful notebook session and returns its identifier.

1. editNotebook(notebookId, code): Updates the code in the notebook using a general-purpose language like Python, allowing the agent to write code to call APIs, run SQL queries, join dataframes, and generate visualizations in one place.

1. executeNotebook(notebookId): Runs the code and returns structured output, including console logs, error tracebacks, and file handles (such as rendered chart images for visual inspection).

Same agent, same model, two tool surfaces. buildVisualization can't see query results, so the narrow agent retypes 12 numbers and silently mistypes one. The notebook agent never copies a value. Race both agents →

This tool shape is much more capable. With a small set of general primitives, the agent can cover a huge range of data science workflows that narrow tools couldn’t touch (including writing code to train and test small models!).

Of course, this power doesn’t come for free: letting an agent run arbitrary code expands the risk surface considerably. That makes sandboxing non-negotiable so the agent can work autonomously inside safe boundaries without spamming the user with permission prompts.

Build in-product feedback loops

One of the most under-utilized levers in building agents is designing in-product feedback loops that users actually want to use. Most products rely on feedback mechanisms that are weakly aligned with user incentives, like thumbs up/down buttons or pop-up surveys that nobody has a reason to fill out.

The best feedback loops are wired directly into the user’s own incentives. A great example is an “artifacts” style surface where the agent produces tangible deliverables (documents, analyses, designs, or plans) that users care about getting right. Users naturally want to iterate on these artifacts or share them with teammates. Building inline commenting (like Google Docs comments on text or visual outputs) or a “send to a teammate for review” flow aligns the product with what the user is already trying to do. The user gets immediate improvements on their artifact, and you get high-signal traces that expose gaps in your harness (a missing tool, a misleading prompt) that you can close over time.

Comment on the analysis like you would in a doc, or send it to a teammate. The agent revises it, and every comment becomes a labeled trace. Leave a comment yourself →

What the team building the agent gets back: a thumbs-down tells you something was wrong, somewhere. A comment tells you where, what, and what to fix. Try it →

⁂

The interactive versions of these demos are in the original post.

Source details

Taha Rafiq · x.comPublished · added here

Original title: Finally got some time to write down some of my learnings from building useful agents and harnesses from the last couple of years :)