Stop trying to fix every agent failure with a better prompt

Ray45 Expert 1h ago 601 views 12 likes 2 min read

Why you can't trust the model alone

We rent our models via tokens and subscriptions, which means we're building on black boxes. You have zero control over the underlying weights or if a provider silently swaps a model version. If you rely solely on prompting, you're gambling on the model's mood.

A harness provides reliability by anchoring an unpredictable model to stable code. If a climber uses a harness, it doesn't do the climbing for them; it just catches them when they fall. In AI, guardrails and verification steps are that safety net, while the tool registry and agent loop act as the leash directing the movement.

Breaking down the agent harness

People often confuse the "agent loop" with the "harness," but the loop is just one component. To be clear, an evaluation harness (used for benchmarking datasets) is entirely different from an agent harness (the runtime layer).

A functional agent harness consists of six specific parts:

  • Tool Registry: The set of capabilities the model can actually trigger.
  • The Model: The LLM acting as the reasoning engine.
  • Context Management: Handling what the model sees and remembers.
  • Guardrails: Constraints that stop the model from going off the rails.
  • Agent Loop: The iterative cycle of calling the model, executing a tool, and feeding the result back.
  • Verify Step: The critical check to see if the model actually achieved the goal.

The core philosophy of harness engineering is this: when an agent misbehaves, you write code to fix it rather than "prompting harder."

Proving it with GPT-3.5 Turbo

I tested this by trying to get GPT-3.5 Turbo to upvote a story on Hacker News. Without a proper harness, the model hit a login page, did absolutely nothing, and then hallucinated that it had succeeded.

By keeping the prompt exactly the same and only iterating on the harness logic—adding verification and refining the loop—the agent actually completed the task in six iterations. The model didn't get smarter; the environment around it became more rigorous.

If you want to see the actual implementation, the code is available on GitHub at:

https://github.com/TejasQ/basically-ai-harness

How to implement a basic harness loop

For those who want to stop relying on "hope" as a strategy, you need a structure that doesn't just take the model's word for it. Instead of a simple request-response, your harness should look like this:

# Simplified logic for a harness loop
while not task_verified:
    # 1. Call the black-box model
    response = model.call(context, tools)
    
    # 2. Execute the tool (The Tool Registry part)
    result = execute_tool(response.tool_call)
    
    # 3. Feed result back into context (Context Management)
    context.append(result)
    
    # 4. The Verify Step (Crucial for reliability)
    task_verified = verify_success(result, expected_outcome)
    
    # 5. Guardrail check to prevent infinite loops
    if iteration_count > max_limit:
        break

The "Verify Step" is where most people fail. If the model says "I have upvoted the post," the harness should independently check the HTML or API of the page to confirm the vote count increased. If it didn't, the harness flags a failure and forces the loop to retry, regardless of what the model claims.

Prompt

All Replies (3)

R
Riley97 Advanced 1h ago

I'm so relieved someone said this. I spent three days tweaking prompts before just using Pydantic for validation instead. Maybe 40% of calls...

0 Reply
A
AlexTinkerer Advanced 1h ago

I'm curious if this works for 403 errors too. I've been using LangGraph for this, but maybe that's the wrong way?

0 Reply
P
PatFounder Advanced 1h ago

I'm exhausted from prompt-tuning. I wasted a week fighting hallucinated JSON before switching to LangGraph to force some actual logic...

0 Reply

Write a Reply

Markdown supported