Harness Engineering: Build Your First AI Harness in 26 Lines A tutorial published with a five-minute video shows developers how to build a working AI "harness" in 26 lines of free, open-source Python using PraisonAI, the open-source agent framework from MervinPraison, to stop a model from returning stale dates. The guide documents that OpenAI's gpt-4o-mini, asked the date three times on 5 November 2026 with no harness, answered "October 5, 2023," "October 3, 2023" and "October 4, 2023." The harness adds four parts — an instruction never to guess a date, a `today` tool that reads the computer's clock, a check that the answer contains the current year, and a retry limit of up to 3 attempts that blocks a wrong answer before it reaches the user. Ask an AI model today’s date and it may answer with total confidence, and be years out. This guide shows the fix, called harness engineering, and lets you build one yourself: 26 lines of free, open-source Python with PraisonAI https://github.com/MervinPraison/PraisonAI , run in a fresh install, with every line explained for someone who has never written code. %%{init: {"theme": "base", "themeVariables": {"background": "transparent", "lineColor": " 000000"}}}%% graph TD Q Your question -- A Agent: the AI model + its instructions A -- |needs the date| T Tool: today reads the computer's clock T -- A A -- C{Check: is this year in the answer?} C -- |yes| Y You get the answer C -- |no, up to 3 tries| A C -- |still wrong| X Blocked: a wrong answer never reaches you classDef agent fill: 8B0000,color: fff classDef hook fill: 189AB4,color: fff classDef decision fill: 444,color: fff class Q,A,Y,X agent class T hook class C decision Prefer to watch? The whole build is in a five-minute video: Harness Engineering Made EASY: Fix an AI Stuck in 2023 https://youtu.be/d0gQsyPi4-g . PraisonAI is free and open source: github.com/MervinPraison/PraisonAI https://github.com/MervinPraison/PraisonAI . If this guide helps you, please give the repo a star on GitHub. It helps more people find it. What is harness engineering? Harness is an old word. It is the set of straps that lets a horse pull a cart. A horse is strong, but on its own it goes where it wants. The harness the reins, the bit, the collar, the traces turns that strength into a cart you can steer and stop. AI works the same way. The AI model is the brain inside apps like ChatGPT. It is the horse: clever and strong, but it cannot see a clock, it cannot check its own work, and it does not know when to stop. The harness is everything you build around the model so you can steer it. Harness engineering is the job of building and improving that harness. | | The model the horse | The harness the straps and reins | |---|---|---| | What it is | The AI brain, trained on text up to a cut-off date | The code you write around it | | What it is good at | Writing, reasoning, answering | Steering, checking, stopping | | What it cannot do alone | See a clock, check itself, know when to stop | Think: it only guides the model | | Who changes it | The AI company | You | An agent, an AI that can take actions for you, is a model plus a harness. - Old way: ask a smarter model and hope it is right. - Harness way: give the same model tools, checks and limits, so a wrong answer is caught before it reaches you. - Why it matters: when an AI app gets better, sometimes the harness changed, not the model. Why an AI says it is 2023 A model learns from text that stops at a certain date, called its cut-off date. After that it learns nothing new, and it has no clock. So when you ask the date, it guesses from what it last read, and a guess sounds just as sure as a fact. I asked OpenAI’s small model, gpt-4o-mini, with nothing around it, three times on 5 November 2026: | Run | What the AI alone said | The real date | |---|---|---| | 1 | Today’s date is October 5, 2023. | Thursday 5 November 2026 | | 2 | Today’s date is October 3, 2023. | Thursday 5 November 2026 | | 3 | Today’s date is October 4, 2023. | Thursday 5 November 2026 | The fix is not a smarter model. It is a clock, and a check. The four parts of our harness Our harness has four parts. Each one is a line or two of code, and each has a job you would recognise from the horse and cart. | Part | Its job | Like the… | Where it is in the code | |---|---|---|---| | Instructions | How the AI should behave: one sentence, never guess a date | Reins | Line 17 | | A tool | A small piece of code the AI can use: today reads the computer’s clock | Eyes on the road | Lines 4–6, given on line 18 | | A check | Lets a right answer through, sends a wrong one back | Brakes | Lines 8–13, added on line 19 | | A limit | At most three rounds of using its tools | A fence | Line 20 | What you need before you start | You need | Why | Notes | |---|---|---| | Python 3.10 or newer | PraisonAI is a Python library | Free from python.org https://www.python.org/downloads/ . On Windows, tick Add Python to PATH in the installer | | An OpenAI API key | Your code uses OpenAI’s model through it | From platform.openai.com https://platform.openai.com/api-keys . An API key is like a password for your code | | A few dollars of API credit | The key does not work with no credit | Each run of this code cost under a tenth of a cent in my tests | | A terminal | A window where you type commands | Mac: Command + Space, type Terminal. Windows: PowerShell | | A plain-text editor | To save the code as a .py file | Not Word or TextEdit rich text: they break the code | Step 1: Install PraisonAI pip is the tool you use to add things to Python. In your terminal, type: pip install praisonai On a Mac without a virtual environment, use pip3 and python3 instead of pip and python . What I got from a fresh install: | Item | Version in my test | |---|---| | praisonai | 4.7.23 | | praisonaiagents the part we import | 1.7.21 | | Python | 3.12.11 macOS, Apple Silicon | | Model | gpt-4o-mini | | Install time | About 30 seconds some packages were already cached | Step 2: Tell your computer your API key This lasts for this terminal window only, so run your code in the same window. Replace your-key-here with your key, keeping the quotes. Mac and Linux export OPENAI API KEY="your-key-here" Windows PowerShell $env:OPENAI API KEY="your-key-here" Check it is set Mac and Linux : echo $OPENAI API KEY should print your key. Never paste your real key into a file you share, a screenshot or a video. The Windows commands were not tested on Windows. Step 3: Ask the AI alone First, see the problem for yourself. Save this as agent bare.py : it is the model with no harness at all. python from datetime import date from praisonaiagents import Agent agent = Agent instructions="Answer in one sentence.", model="gpt-4o-mini" answer = agent.start "What is today's date?" print "MODEL ALONE SAYS:", answer print "REAL DATE IS: ", date.today .strftime "%A %d %B %Y" python agent bare.py What it printed for me: MODEL ALONE SAYS: Today's date is October 5, 2023. REAL DATE IS: Thursday 05 November 2026 Step 4: The full harness in 26 lines Now the fix. Copy this into a plain-text file called agent harness.py , in the folder your terminal is in. Keep the spaces at the start of the lines exactly as they are: in Python, they are part of the code. python from datetime import date from praisonaiagents import Agent def today : """Get today's date from the computer's clock.""" return date.today .strftime "%A %d %B %Y" def check output : if str date.today .year in output.raw: print "CHECK: passed" return True, output print "CHECK: failed, sending it back" return False, "Wrong year. Use the today tool." agent = Agent name="Assistant", instructions="Answer in one sentence. Never guess a date: use the today tool.", tools= today , guardrails=check, execution={"max iter": 3}, model="gpt-4o-mini", answer = agent.start "What is today's date?" print "WITH HARNESS SAYS:", answer print "REAL DATE IS: ", today The code, line by line Lines 1–13: the tool and the check | Line s | Code | What it does, in plain words | |---|---|---| | 1 | from datetime import date | Loads Python’s calendar, so the code can read today’s date | | 2 | from praisonaiagents import Agent | Loads PraisonAI’s Agent: the part that talks to the AI for you | | 4 | def today : | Starts a function called today : a small, named piece of code. This is the tool | | 5 | """Get today's date from the computer's clock.""" | The sentence in quotes tells the AI what the tool is for, so it knows when to use it | | 6 | return date.today .strftime ... | Reads the clock and gives back a date like Thursday 05 November 2026 | | 8 | def check output : | Starts the check. PraisonAI passes it the AI’s answer as output | | 9 | if str date.today .year in output.raw: | Is this year 2026 anywhere in the answer’s text? | | 10–11 | print "CHECK: passed" · return True, output | Yes: say so, and let the answer through to you | | 12–13 | print "CHECK: failed, sending it back" · return False, "Wrong year. Use the today tool." | No: the AI gets it back with a note telling it what to fix | Lines 15–26: the agent | Line s | Code | What it does, in plain words | |---|---|---| | 15, 22 | agent = Agent … | Builds the agent: the model plus everything around it | | 16 | name="Assistant", | Gives it a name. In this version the check does not run without one, so keep it | | 17 | instructions="…", | The reins: answer in one sentence, and never guess a date | | 18 | tools= today , | Hands it the clock tool | | 19 | guardrails=check, | Adds your check. A guardrail is a safety barrier, like the edge of a road | | 20 | execution={"max iter": 3}, | A limit: at most three rounds of using its tools | | 21 | model="gpt-4o-mini", | Picks the AI: OpenAI’s small model, GPT-4o mini | | 24 | answer = agent.start "What is today's date?" | Asks the question and waits for the answer | | 25–26 | print ... | Prints the answer next to the real date, so you can compare them | The two lines to watch are the tool and the check: one fixes the date, and one stops wrong answers. Step 5: Run it and read the output python agent harness.py What you should see, in order: 1. A box that says Agent: Assistant and Tools: today : the clock tool from line 4. 2. CHECK: passed : your check from lines 8–13 ran and found this year in the answer. 3. The answer twice: once in PraisonAI’s Response box, and once from the last two lines of the code, next to the real date. CHECK: passed WITH HARNESS SAYS: Today's date is Thursday, November 5, 2026. REAL DATE IS: Thursday 05 November 2026 | Version | Runs | Answer | |---|---|---| | The AI alone agent bare.py | 3 | October 2023, every time | | The full harness agent harness.py | 3 | Thursday, 5 November 2026, every time | Why the check matters: take the clock away Is the check doing anything, or is the tool doing all the work? To find out, I took the tool away and kept the check. Save this as agent check only.py : python from datetime import date from praisonaiagents import Agent def check output : if str date.today .year in output.raw: print "CHECK: passed" return True, output print "CHECK: failed, sending it back" return False, "Wrong year." agent = Agent name="Assistant", instructions="Answer in one sentence.", guardrails=check, model="gpt-4o-mini", answer = agent.start "What is today's date?" print "CHECK BUT NO TOOL SAYS:", answer Without a clock, the AI’s answer still had the wrong year. The check printed CHECK: failed, sending it back four times the first try and three retries , and then PraisonAI refused to pass the wrong answer on: CHECK BUT NO TOOL SAYS: I'm sorry, but I can't share that response because it did not pass the safety guardrail. Trying, checking and trying again is called the agent loop. So a check cannot make the AI right, but it stops a wrong answer reaching you. The tool makes it right; the check makes sure. | Version | Tool? | Check? | Result | |---|---|---|---| | agent bare.py | No | No | A confident wrong date October 2023 | | agent check only.py | No | Yes | Wrong answer blocked after 3 retries | | agent harness.py | Yes | Yes | The real date, and CHECK: passed | Where the name harness engineering came from In February 2026, developer Mitchell Hashimoto wrote about it in My AI Adoption Journey https://mitchellh.com/writing/my-ai-adoption-journey , under the heading Engineer the Harness . His idea: anytime you find an agent makes a mistake, you build a fix so it never makes that mistake again. In his words, “I’ve grown to calling this harness engineering”. Is it just a toy? LangChain, an AI tools company, tested it. It kept the model fixed, changed only the harness, and its coding agent’s test score went up 13.7 points: | What changed | Score | |---|---| | Before same model | 52.8 | | After same model, better harness | 66.5 | | Gain | +13.7 points | Source: LangChain, Improving Deep Agents with harness engineering https://www.langchain.com/blog/improving-deep-agents-with-harness-engineering 17 February 2026 . LangChain’s later post, The Anatomy of an Agent Harness https://www.langchain.com/blog/the-anatomy-of-an-agent-harness 10 March 2026 , sums it up as Agent = Model + Harness . OpenAI has written about it too: Harness engineering: leveraging Codex in an agent-first world https://openai.com/index/harness-engineering/ . A better harness can matter as much as a better model. Harnesses you already use You have probably used a harness already. AI coding helpers are harnesses around a model: each adds instructions, tools, checks and limits. | App | What it is | A harness part you can see | |---|---|---| | Claude Code https://docs.claude.com/en/docs/claude-code/overview | Anthropic’s agentic coding tool | It reads your code, edits files and runs commands, and asks before it changes your files | | OpenAI Codex CLI https://github.com/openai/codex | OpenAI’s coding agent | Tools that read and change your code, inside limits you set | | Cursor https://cursor.com | A code editor with a coding agent | Tools for your project’s files, around the model you pick | So there is one good question to ask any AI app: what does its harness check? Troubleshooting | What you see | Why | What to do | |---|---|---| | Nothing happens for over a minute | A request to OpenAI got no reply. In my tests, 3 runs in 23 stalled; the ones I left alone waited about 10 minutes before going on | Press Ctrl+C and run it again | | The check never prints anything, and every answer is blocked | The agent has no name= . In this version the check fails without one | Keep name="Assistant", line 16 | | Different answers in different folders | Inside a git project, PraisonAI also reads that project’s AGENTS.md or CLAUDE.md files | Run it from a plain folder, or add rules=False, to the Agent | | pip: command not found | On a Mac, Python’s commands end in 3 | Use pip3 and python3 | | An error about the API key, or quota | The key is not set in this window, or the account has no credit | Run Step 2 again in this window; add credit | | IndentationError | The spaces at the start of lines were lost when copying | Copy the code again; keep 4 spaces inside each function | | Strange characters or a SyntaxError on line 1 | The file was saved as rich text | Save it as plain text with a .py ending | The first three are reported to the PraisonAI project, with full reproductions: issue 6257 https://github.com/MervinPraison/PraisonAI/issues/6257 . Ideas to try next Once it runs, change one thing at a time and watch what happens. Each idea below is a small change to the 26 lines. - Change the check. Make it look for the month too, not just the year. - Ask a different question. Try What day of the week is it? and see whether the tool still gets used. - Add a second tool. Write another small function with a one-sentence description, and add it to tools= today, ... . - Remove one part at a time. Run without the instructions, then without the tool, and compare the answers. - Write down each mistake. That is harness engineering: every time the agent gets something wrong, add a fix so it cannot happen again. At a glance | Item | Detail | |---|---| | Harness engineering | Building everything around an AI model so you can steer it, check it and stop it | | Our harness | Instructions, a clock tool, a check and a limit: 26 lines of Python | | Install | pip install praisonai praisonai 4.7.23, praisonaiagents 1.7.21 in my test | | Model | OpenAI gpt-4o-mini; under a tenth of a cent per run | | The AI alone | October 2023 in 3 of 3 runs | | With the harness | The real date in every run, with CHECK: passed | | Check without the tool | Wrong answer sent back 3 times, then blocked | | Evidence it matters | LangChain: same model, better harness, 52.8 → 66.5 | | Video | youtu.be/d0gQsyPi4-g https://youtu.be/d0gQsyPi4-g | | Code library | PraisonAI on GitHub https://github.com/MervinPraison/PraisonAI , free and open source | If you built it, tell me what your harness checks. And if PraisonAI helped, please star the repo on GitHub https://github.com/MervinPraison/PraisonAI . Disclosure: I built PraisonAI. Related on mer.vin: Prompt vs Context vs Harness Engineering https://mer.vin/?p=51527 · The Agent Harness Stack https://mer.vin/?p=53396 · Self-Learning AI Agents: Model, Harness, and Context Layers https://mer.vin/?p=52617 .