页面简介
Learn how to automate the repair loop for your AI agents using Opik, moving beyond manual debugging to a self-correcting development workflow.
正文摘录
India's Most Futuristic AI Conference Is Back – Bigger, Sharper, Bolder d : h : m : s Get Details Interview PrepCareerGenAIPrompt EnggChatGPTLLMLangchainRAGAI AgentsMachine LearningDeep LearningGenAI ToolsLLMOpsPythonNLPSQLAIML Projects Reading list Introduction to Generative AIWhat is Generative AI? Introduction to Generative AI applicationsOverview of generative AI applications and their impact No-code Generative AI app developmentIntroduction to No-code AI Development Code-focused Generative AI App DevelopmentIntroduction to LangChain, ChatGPT and Gemini Pro Introduction to Responsible AIIntroduction to Responsible AI LLMSWhat are Large Language Models?GPT modelsMistralLlamaGeminiHow to build diffferent LLM AppIications? Prompt EngineeringIntroduction to Prompt EngineeringBest Practices and Guidelines for Prompt EngineeringN shot promptingChain of ThoughtTree of ThoughtsSkeleton of ThoughtsChain of Emotion Finetuning LLMsIntroduction to Finetuning LLMsParameter-Efficient Finetuning (PEFT)LORAQLORAusing Unslothusing Huggingface Training LLMs from ScratchWhat do you mean by Training LLMs from Scratch? LangchainIntro to the LangChain EcosystemCore Components of LangChainApplications of LCEL ChainsRAG using LangChainLangGraphLangSmith RAGIntroduction to RAG systemsEvaluation of RAG systems LlamaIndexGetting Started with LlamaIndexComponents of LlamaIndexAdvanced approaches for powerful RAG system Stable DiffusionIntroduction to Stable DiffusionGenerating image using Stable diffusionDiffusion modelsPrompt Engineering Concepts for Stable DiffusionMidJourneyUnderstanding Dalle 3 Building Self-Correcting AI Agents with Opik Soumil Jain Last Updated : 27 Nov, 2026 10 min read Your agent might work perfectly in a demo, but real users bring unexpected challenges. It picks the wrong tool, ignores retrieved context, or generates unreliable answers. Observability tools show what happened, but rarely explain why or how to fix it, leaving developers scrolling through traces and debugging failures. With every model release introducing new failure modes, agent reliability becomes a moving target. In this blog, we’ll explore agent harnesses, why they still need human intervention, and how Opik helps close the loop. Table of contentsWhat is an Agent harness?How Opik turns the harness into a self-correcting loopOpik vs Langfuse vs LangSmithConclusionFrequently Asked Questions What is an Agent harness? A harness is all the code around the model. The LLM is the engine, the harness is the rest of the car. Recent research puts it simply, an agent is a model plus a harness, and the harness is the code that organizes prompts, calls tools, manages context, and controls execution. In practice, a harness usually has three parts: Instructions: The system prompt, prompt templates and few shot examples that tell the model how to behave. Tools: Function schemas, APIs and retrievers the agent can call, plus the code that runs them. Context and memory: What goes into the context window on each step, what gets summarized, and what is stored for later. Control loop: The logic that decides when to call the model again, when to call a tool, and when to stop for example ReAct, a LangGraph state machine, a planner and executor. Checks: Output parsers, guardrails, retries and validators that catch bad steps before they reach the user. The important point is that the harness, not just the model, decides how good your agent is. With the model held fixed, changing only the harness can produce large performance gains. That is also why the harness keeps growing. How a non self-correcting harness works Most harnesses in production today are static. You write them once, ship them, and they run the same way on every request until a human change the code. Here is the usual lifecycle: Build: An engineer writes the system prompt, wires up the tools and picks a control loop. Test: The agent is checked against a handful of examples, often by eyeballing outputs. Ship: The harness goes to production and starts handling real traffic. Log: An observability tool records every LLM call, tool call, latency and token count. Fail: Some requests go wrong, the agent calls the wrong tool, loops, hallucinates, or ignore the retrieved context. Wait: The failure sits in the logs until a user complains or a dashboard number moves. Notice what is missing. The feedback goes into a dashboard, not back into the harness. The agent may retry a failed tool call or re-parse a broken JSON output during a run. That is the difference this blog cares about. Retrying inside a run which is in run correction. Changing the harness so the failure does not come back is harness self-correction. Where Human intervention comes in In a static harness, a human does every step of repair. You get a clean trace of every call, but not why it broke, the change that fixes it, or any guarantee the failure won’t come back. Repair stepWhat the engineer does by handWhy it hurtsDetectReads user complaints or watches a dashboardSilent failures go unnoticed for daysDiagnoseScrolls the trace span by span and forms a theorySlow, and depends on who knows the codebaseFixEdits the prompt, tool description or control logicA fix for one case can break three othersVerifyReruns the failing input locally, maybe a few moreHard to reproduce the exact config that failedPreventRemembers to add the case to an eval setUsually skipped, so the bug returns Now multiply this by every new model you try. Each upgrade brings its own failure modes, and you run the while loop again from the top. The harness grows faster than a team can track it, and engineers becomes the bottleneck. How Opik turns the harness into a self-correcting loop Opik is an open-source Apache-2.0 licensed platform from comet for tracing, evaluating and optimizing LLM apps and agents. Ts pitch for agent is simple, the repair loop from the last section should be automated not staffed. It does this with 4 step process with each step been fed into the next one. Step 1: Tracing One decorator, @opik.track, logs every LLM call, tool call and retrieval step as a span tree. It works with LangGraph, CrewAI, the OpenAI Agents SDK and 50+ other framework. Each trace also records which agent configuration was active. So, you can rerun a failing input later against the exact setup that broke. Step 2: Ollie, the coding agent inside Opik Ollie is a coding assistant built into the Opik UI. Point it at a bad trace and ask something like “ why did the final answer ignored the retrieved context?” It walks the full span tee and explains the root cause. To use it run the command opik connect in your project folder and Ollie also get access to your code. It can then read the source, propose a diff, rerun the agent on the original failing input and add that trace to a test suite. Nothing changes on disk until you approve the diff. Step 3: Test Suites with plain English assertions Instead of building a labeled dataset and comparing float scores, you write rules like “The response must not claim Kubernetes is supported”. An LLM judge checks each rule and gives a clean pass or fail. You can also run each test item several times and set a pass threshold, which helps with non-deterministic outputs. Every bug you fix becomes a new test, so the suite grows from real production failures. Step 4: Agent Playground- The Sandbox Most playgrounds only rerun a single prompt. The Agent playground runs your whole agent end to end from the Opik UI while the code stays on your machine. You can edit prompts from the Prompt Library, run the agent, and see the full trace of what changed downstream Putting all the steps together The previous steps forms one loop. A failling trace goes to Ollie, Ollie proposes a fix, you approve it , Ollie reruns the original input, and the failure is locked in as a regression test. The next failure enters the same loop, and with every cycle the harness gets harder to break. Around that loop, Opik also has online evaluation rules that score production traces with LLM judges, so failures gets flagged without waiting for a user complaint. For prompt level tuining there is the Agent Optimizer, with algorithms like GEPA, MetaPrompt and an evolutionary optimizer. Note: Here self correcting does not mean unsupervised, you still approve every code change. The engineer moves from doing the repair to reviewing it. Hands-on with Opik Let’s build a tiny support agent, catch it making something up, and push that failure through the Opik loop. The code follows the pattern in the Test Suites docs and Agent Playground docs. You also need an OpenAI key for this Step 1: Install and start Opik Use Opik Cloud with opik configure, or self-host the full platform with Docker: Code: pip install opik openai # Option A: Opik Cloud (prompts for API key and workspace) opik configure # Option B: self-host locally, UI at http://localhost:5173 git clone https://github.com/comet-ml/opik cd opik && ./opik.sh Step 2: Trace the agent The agent has a toy retriever and one LLM call. The system prompt asks for detailed asnwers, which is exactly the kind of instruction that tempts a model to fill gaps with made-up facts. Code: import threading import opik from openai import OpenAI from opik.integrations.openai import track_openai # Initialize OpenAI client with Opik tracking llm = track_openai(OpenAI()) # Knowledge base DOCS = { "projects": ( "To create a new project, go to the Dashboard " "and click 'New Project'." ), "deploy": ( "We support Docker containers and serverless functions." ), } # System prompt SYSTEM_PROMPT = ( "You are a helpful assistant. Be as detailed as possible." ) # Retrieval function @opik.track(name="retrieve") def retrieve(question: str) -> str: if "project" in question.lower(): return DOCS["projects"] return DOCS["deploy"] # Main support agent @opik.track(entrypoint=True, project_name="support-agent") def support_agent(question: str) -> str: # Retrieve relevant context context = retrieve(