[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-732947-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-732947-en":130,"doc-similar-732947":164},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","how-to-ai-an-ai-for-almost-anything-lecture-5-harness-engineering","How to AI an AI for Almost Anything - Lecture 5 - Harness Engineering","","Lecture 5 - Harness Engineering explains how to construct effective agent systems by combining a model with a “harness” that interprets actions, runs tools, and manages context. The lecture covers the agent loop in code, showing message histories, parsing actions, tool execution, and feeding observations back to the model. It also contrasts a single-turn Codex loop with deeper multi-call reasoning, introduces context management and prompt caching concepts, and presents mini-swe-agent design principles and reported performance on SWE-bench.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/how-to-ai-an-ai-for-almost-anything-lecture-5-harness-engineering/732947/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/how-to-ai-an-ai-for-almost-anything-lecture-5-harness-engineering/732947.png","ImageObject",300,407,{"name":42,"@type":43},"BAd apple","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-26","2026-11-22",true,{"@type":52,"interactionType":53,"userInteractionCount":30},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What does “agent = model + harness” mean in this lecture?","Question",{"text":62,"@type":63},"An agent is built by combining a model with a harness. The harness parses the model’s intended actions and runs the required tools while providing observations back into the interaction context.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How does the agent loop work in the code example?",{"text":67,"@type":63},"The loop repeatedly calls the LLM with stored messages, parses the reply into an action, executes the action, and appends the resulting output as a new user message. When no action is produced, the harness returns a final answer.",{"name":69,"@type":60,"acceptedAnswer":70},"How does the Codex agent loop differ from the single-step approach?",{"text":71,"@type":63},"The lecture describes one turn as requiring many model calls until tool-call conditions end, and then the whole history is carried over into the next turn. This unrolls reasoning across tool usage rather than treating each step as independent.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},732947,1795383041,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":30,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":144,"preview_page_count":96,"preview_urls":145},19241458193282,"https://us-avatar.wpscdn.com/davatar_a8503ba1806abce46bf441b54a3ca4cd","1  \nHow to AI an AI for Almost Anything Lecture 5-Harness Engineering  \nAo Qu  \n[https://quao627.github.io/](https://quao627.github.io/)  \n[https://x.com/ao_qu18465](https://x.com/ao_qu18465)  \n2  \nToday’s Lecture  \n• The Agent Loop  \n• Deep Dive: mini-swe-agent  \n• Tools & Tool Design  \n• Skills, MCP, Hooks, Plugins  \n• Context Management & Prompt Caching  \n• Plan Mode, Memory, Subagents  \n• Multi-agent Harnesses  \n• Safety  \n3  \nWhat Is a Harness?  \nAgent = Model + Harness  \n[Merrill et al., Terminal-Bench. ICLR 2026] Leaderboard: [https://www.tbench.ai/?version=2.0](https://www.tbench.ai/?version=2.0)[ ](https://www.tbench.ai/?version=2.0)Blog: [https://blog.langchain.com/the-anatomy-of-an-agent-harness/](https://blog.langchain.com/the-anatomy-of-an-agent-harness/)  \nsame model, 9 harnesses: 58.0% → 76.4%  \n4  \nWhat Is a Harness?  \nAgent = Model + Harness  \n[Pan et al., HarnessTax: How Much Does Harness Matter for Coding Agents? 2026] Blog: [https://arena.ai/blog/coding-agents-harness-tax](https://arena.ai/blog/coding-agents-harness-tax)  \nsame model: ≈ same success, 2× the cost  \n6  \nThe Agent Loop in Code  \nmessages = [{ \"role\" : \"system\" , \"content\" : SYSTEM},{ \"role\" : \"user\" , \"content\" : task}]  \nwhile True :  \nreply = llm(messages)  \nmessages.append({ \"role\" : \"assistant\" , \"content\" : reply}) action = parse_action(reply)  \nif action is None :  \nreturn reply output = execute(action)  \nmessages.append({ \"role\" : \"user\" , \"content\" : output})  \nmodel: Thought + Action  \nharness parses the action  \n\n| no action → Answer |\n| --- |\n| harness runs the Tool |\n| Observation → context |\n\nBlog: [https://minimal-agent.com/](https://minimal-agent.com/)  \n7  \nThe Agent Loop in Codex  \none turn = many model calls, until no tool call next turn: the whole history goes back in  \nBlog: [https://openai.com/index/unrolling-the-codex-agent-loop/](https://openai.com/index/unrolling-the-codex-agent-loop/)  \n8  \nWhat the Model Sees First  \n[gpt-5.2-codex_prompt.md](gpt-5.2-codex_prompt.md) ↗  \n≈47k tokens  \nbefore you type  \nrepo not in the prompt  \nread with tools  \nBlog: [https://openai.com/index/unrolling-the-codex-agent-loop/](https://openai.com/index/unrolling-the-codex-agent-loop/)  \nCode: [https://github.com/openai/codex/blob/e958d0337e98f6398771917867d7de689dab3b7a/codex-rs/core/gpt-5.2-codex_prompt. md](https://github.com/openai/codex/blob/e958d0337e98f6398771917867d7de689dab3b7a/codex-rs/core/gpt-5.2-codex_prompt. md)[ ](https://github.com/openai/codex/blob/e958d0337e98f6398771917867d7de689dab3b7a/codex-rs/core/gpt-5.2-codex_prompt. md)[credit: Juncheng Yang, Harvard CS 2680 Modern AI Systems: Agents and System Optimizations: [https://cs2680.com/](https://cs2680.com/)]  \n9  \nmini-swe-agent  \n• ~100 lines  \n• bash is the only tool  \n• linear history  \n• subprocess per action  \n• >74% SWE-bench Verified  \nCode: [https://github.com/SWE-agent/mini-swe-agent/blob/68d367b/src/minisweagent/agents/default.py](https://github.com/SWE-agent/mini-swe-agent/blob/68d367b/src/minisweagent/agents/default.py) (v1 .17.5)  \nDocs: [https://mini-swe-agent.com/v1/advanced/control_flow/](https://mini-swe-agent.com/v1/advanced/control_flow/)","cbCaibqU9gLF2C9v","https://ap.wps.com/l/cbCaibqU9gLF2C9v","pdf",4204147,47,"English","# Today’s Lecture\n## The Agent Loop\n## Deep Dive: mini-swe-agent\n## Tools & Tool Design\n## Skills, MCP, Hooks, Plugins\n## Context Management & Prompt Caching\n## Plan Mode, Memory, Subagents\n## Multi-agent Harnesses\n## Safety\n# What Is a Harness?\n## Agent = Model + Harness\n# The Agent Loop in Code\n## messages and action execution\n# The Agent Loop in Codex\n# What the Model Sees First\n# mini-swe-agent","[{\"question\":\"What does “agent = model + harness” mean in this lecture?\",\"answer\":\"An agent is built by combining a model with a harness. The harness parses the model’s intended actions and runs the required tools while providing observations back into the interaction context.\"},{\"question\":\"How does the agent loop work in the code example?\",\"answer\":\"The loop repeatedly calls the LLM with stored messages, parses the reply into an action, executes the action, and appends the resulting output as a new user message. When no action is produced, the harness returns a final answer.\"},{\"question\":\"How does the Codex agent loop differ from the single-step approach?\",\"answer\":\"The lecture describes one turn as requiring many model calls until tool-call conditions end, and then the whole history is carried over into the next turn. This unrolls reasoning across tool usage rather than treating each step as independent.\"}]","How to AI an AI for Almost Anything - Lecture 5 - Harness Engineering | PDF",118,[146,150,153,157,160],{"page_no":22,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-22/9ac302d7617e88dd60ae932b787fb12a.webp",983,552,{"page_no":26,"url":151,"width":152,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-22/cf72b5122973e1b99e4b2959889252fe.webp",982,{"page_no":30,"url":154,"width":155,"height":156},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-22/2a69d7977111ca8164c6c02893ba9ab1.webp",981,551,{"page_no":33,"url":158,"width":159,"height":156},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-22/696bc46d1f69598c5f9107a55b9efa0f.webp",980,{"page_no":96,"url":161,"width":162,"height":163},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-22/5f743d67f8a4e4fd699469b53f9c9ced.webp",979,550,{"list":165,"token":11},[166,172,178,184,191,198,205,211,218,224],{"doc_id":167,"doc_title":168,"file_type":137,"home_preview_img_url":169,"slug":170,"view_count":22,"category_name":29,"create_tm":171},759781,"Bring Your Own Model - GitHub Copilot with Microsoft Foundry, OpenRouter and Local LLMs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230044483876/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=cQcqNkMj8lvb3op4vggEdtu9MFM%3D","bring-your-own-model-github-copilot-with-microsoft-foundry-openrouter-and-local-llms",1795894679,{"doc_id":173,"doc_title":174,"file_type":137,"home_preview_img_url":175,"slug":176,"view_count":26,"category_name":29,"create_tm":177},732950,"Building an Agent Harness - How to Build Your Own","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031781394/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=7s9pTipTv74ZFk1%2F%2BrwmZ8mnxyw%3D","building-an-agent-harness-how-to-build-your-own",1795383050,{"doc_id":179,"doc_title":180,"file_type":137,"home_preview_img_url":181,"slug":182,"view_count":96,"category_name":29,"create_tm":183},696836,"Harness Engineering - A Design Guide to Claude Code","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230009178486/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=lIEVFVLCIgGYcFoNmz67JF1aoR4%3D","harness-engineering-a-design-guide-to-claude-code",1794435025,{"doc_id":185,"doc_title":186,"file_type":137,"home_preview_img_url":187,"slug":188,"view_count":189,"category_name":29,"create_tm":190},682227,"The Comprehensive Guide to AI Agent Engineering - March 2026","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999428213/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=KfPznYxfmWMiH%2BWCYXH6uIAZEWw%3D","the-comprehensive-guide-to-ai-agent-engineering-march-2026",14,1793963049,{"doc_id":192,"doc_title":193,"file_type":137,"home_preview_img_url":194,"slug":195,"view_count":196,"category_name":29,"create_tm":197},657499,"A Markdown Interpreter for TEX - Version 3.16.2","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229975517355/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=Pg9aSMKMRiGO8afMFUoTkBlXN%2Bc%3D","a-markdown-interpreter-for-tex-version-3162",13,1792981474,{"doc_id":199,"doc_title":200,"file_type":137,"home_preview_img_url":201,"slug":202,"view_count":203,"category_name":29,"create_tm":204},273696,"TASK-COEVOLVE - Efficient Harness Optimization via Adaptive Validation Task Selection","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229899555520/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=7cdJ16um2ymtOqbIYEZMMSXGkCA%3D","task-coevolve-efficient-harness-optimization-via-adaptive-validation-task-selection",15,1789472524,{"doc_id":206,"doc_title":207,"file_type":137,"home_preview_img_url":208,"slug":209,"view_count":26,"category_name":29,"create_tm":210},733010,"Agent From a User’s Perspective II - Multi-agent and Best Practice","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031782350/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=B7eYSJy5oSpAlv4RggehRsj5BnE%3D","agent-from-a-users-perspective-ii-multi-agent-and-best-practice",1795383315,{"doc_id":212,"doc_title":213,"file_type":137,"home_preview_img_url":214,"slug":215,"view_count":216,"category_name":29,"create_tm":217},86138,"Know Before Fix QA Driven Repository Knowledge Acquisition for Software Issue Resolution","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229809382113/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=6gADBn0CfHcVrWMdPvRJAFb%2Fpyg%3D","know-before-fix-qa-driven-repository-knowledge-acquisition-for-software-issue-resolution",32,1784208853,{"doc_id":219,"doc_title":220,"file_type":137,"home_preview_img_url":221,"slug":222,"view_count":33,"category_name":29,"create_tm":223},682046,"Agent Tooling - Memory and Context - CSE 291A - Lecture 7","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999341346/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=YJkTLl%2F2TqNBepq4HuJx1em84Og%3D","agent-tooling-memory-and-context-cse-291a-lecture-7",1793958916,{"doc_id":225,"doc_title":226,"file_type":137,"home_preview_img_url":227,"slug":228,"view_count":229,"category_name":29,"create_tm":230},81728,"Stop Hand Holding Your Coding Agent Engineering the Loops that Replace Step by Step Prompting","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229808475378/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796109539&Signature=1zbmHO4bnjfJ2XGh3rV53WlGeRM%3D","stop-hand-holding-your-coding-agent-engineering-the-loops-that-replace-step-by-step-prompting",26,1784175684]