DEV Community

Mai Chi Bao
Mai Chi Bao

Posted on

🧰 Beyond the Prompt: Anatomy of an AI Agent Harness That Finishes Long Tasks

One LLM call can write a nice paragraph.

But I asked mine to write a whole blog post: research the topic, write it, find a cover image, recommend a YouTube video, add hashtags, then check its own work.

It wrote 3 paragraphs, said "Done!", and forgot the image, the video and the hashtags.

That's when I learned: the model is the engine. The harness is the car. This series is about building the car.

The prompt is 5% of the job. The harness is the other 95%.


Content Studio: my Deep Agent harness at a glance

Give it one sentence ("write a blog post about AI agents") and it runs a long, multi-step task on its own:

  • Memory: AGENTS.md holds brand voice + workflow rules, loaded into every run
  • Skills: playbooks loaded on demand (blog-post, social-media, code-analysis)
  • Planning: write_todos breaks the task into steps and ticks them off live
  • Agents: local subagents (researcher, evaluator) + remote A2A agents (infotainment, todolist, code_analyzer)
  • Sandbox: one Docker container per conversation
  • Checkpoints: every step is saved, so a crash or Stop can be resumed
  • Self-evaluation: it grades its own draft and revises until it passes
  • Streaming: FastAPI SSE → React UI showing plan, tool calls, subagents, files and score

This post (Part 1/5): the big picture, how all the pieces fit together


Key Takeaways

  • A harness = everything around the model: memory, skills, plan, subagents, sandbox, checkpoints, evaluation.
  • Memory says what always matters, skills say how to do this kind of task, todos say where we are now.
  • Long tasks fail because the agent forgets, skips or stops early, not because the model is dumb.

Table of Contents


🤔 What Is an Agent Harness

A plain ReAct loop is: model → tool → model → tool → answer.

That's fine for "what's the weather?". It breaks on anything long:

Step 7 of 12. Context is full of search results. The model forgets step 9 exists. Says "Done".

A harness is the code that keeps the agent on track:

Piece Without it With it
Plan Skips steps Ticks off a todo list
Memory Different tone every run Same rules every run
Skills One giant prompt Playbook loaded only when needed
Subagents One context does everything Research in a clean, separate context
Sandbox Agents share files One container per thread
Checkpoints Crash = start over Crash = resume
Evaluator "Looks good to me" Score + hard gates + retry

I built mine on top of LangChain Deep Agents, which gives you planning, a virtual file system and subagents out of the box. Then I added the production stuff on top.

Here's the home screen:

Content Studio home


🔌 Everything Plugs Into One Call

This is the heart of the whole project, from backend/agent_runner.py:

TOOLS = [web_search, download_image, generate_hashtags, move_file]

subagents = (
    load_subagents(config.SUBAGENTS_YAML, {t.name: t for t in TOOLS})   # local
    + SubAgentRegistry(agent_list_path=config.AGENT_LIST_PATH).get_subagents()  # A2A
)

self.agent = create_deep_agent(
    model=model,
    backend=backend,              # Docker sandbox for this thread
    tools=TOOLS,                  # custom tools
    subagents=subagents,          # local + remote agents
    checkpointer=checkpointer,    # save every step
    middleware=[
        TodoListMiddleware(system_prompt=WRITE_TODOS_SYSTEM_PROMPT,
                           tool_description=WRITE_TODOS_TOOL),  # planning
        self.crash,               # crash testing (Part 2)
    ],
    memory=["./AGENTS.md"],       # always-on rules
    skills=["./skills/"],         # on-demand playbooks
)
Enter fullscreen mode Exit fullscreen mode

Why this works:

  • Each line is one harness feature. Want to swap the sandbox? Change backend. Want a new agent? Add it to a JSON file.
  • The model doesn't know or care where a subagent lives. Local or remote, it just calls task(...).

Result: 1 call, 8 features. The rest of the series is one post per line.


🧠 Memory Skills and Todos

These three get mixed up a lot, so here's how I think about them:

Piece Question it answers Where it lives
Memory What always matters? AGENTS.md
Skill How do I do this kind of task? skills/blog-post/SKILL.md
Todos Where am I right now? write_todos state

Memory: AGENTS.md is loaded into every run. Brand voice + non-negotiable rules:

## Research Requirements
1. Use the `researcher` subagent for in-depth topic research
...
6. Use the `generate_hashtags` tool to generate hashtags for the post
7. Use the `download_image` tool to extract one relevant image
8. Use evaluator to evaluate the result ... Do not stop if the task not PASS.
Enter fullscreen mode Exit fullscreen mode

Skills: Only the skill's short description sits in the prompt. The full playbook is read only when the task matches. Asking for a LinkedIn post? The blog-post skill never fills your context.

---
name: blog-post
description: Create complete long-form blog posts from research to final
  evaluation. Includes task planning, research, article writing, hero image,
  YouTube recommendations, hashtags, and quality evaluation.
---
Enter fullscreen mode Exit fullscreen mode

Pro Tip: think of skills as lazy-loaded prompts. Small context, more tasks.

Todos: I override the default todo prompt to force small steps:

# backend/prompts.py
"6. The to do list should have from 6-10 tasks, and each task should be as small
 as possible, so that the agent can complete each task in one step."
"7. Update the to do list based on the feedback of human or evaluator ... This is a must."
Enter fullscreen mode Exit fullscreen mode

Result: the agent stopped "forgetting" the image. It's on the list, and the list is in state.


🎬 One Real Run Step by Step

Task: "Write a blog post about how AI agents are transforming software development"

  1. Writes a todo list (6–10 small steps)
  2. Sends research to the researcher subagent → saves research/<slug>.md
  3. Writes the draft into its sandbox
  4. download_image for the cover
  5. Asks the A2A infotainment agent for a YouTube video
  6. generate_hashtags
  7. evaluator scores it → FAIL → new todos → fix → PASS

Every step shows up live in the UI: the plan, each tool call (input, output, duration) and each subagent card:

Live plan and tool calls

And when it's done, 8 of 8 ticked:

Completed run


🏭 What Production Grade Means Here

For me, "production grade" for agents is not "uses GPT-5". It's:

  • Survives failure: crash or Stop, then resume (Part 2)
  • Scales across teams: agents as separate services via A2A (Part 3)
  • Isolated: users never share a filesystem (Part 4)
  • Checks itself: and you can see why it passed or failed (Part 5)

Note: this is a learning project, not a finished product. In every part I'll also tell you what I'd still change before real users touch it. Honest > hype.


✅ Conclusion

  • The model is the engine, the harness is the car
  • Memory = always, Skills = on demand, Todos = right now
  • One create_deep_agent(...) call wires 8 harness features
  • Long tasks fail by forgetting and stopping early, so fix that with structure, not a longer prompt

Future me: stop writing 2-page prompts. Write a harness.

Coming up next (Part 2): Crash, Stop, Resume. I'll crash my own agent on purpose (with ~20 lines of middleware) and show how it picks up exactly where it died.


Reference

All the code is live here on my GitHub:
mrzaizai2k/harness_learning

Feel free to clone it, star it, or ask me anything.

Like, comment, save. And hit follow so you don't miss Part 2!

Top comments (0)