All posts

How to Build an AI Agent: Lessons from Anthropic, GitHub and Docker

Learn how to build reliable AI agents using lessons from Anthropic, GitHub, and Docker. Covers agent specs, task breakdown, state management, tool execution, and security. A practical guide for AI engineers building long-running, production-grade agents.

According to the McKinsey Global Survey on the state of AI in 2025, 62% of respondents say their organizations are experimenting with AI agents.

A similar finding was made by PwC, stating that AI agents could perform "complex, cross-functional workflows across finance, customer service, software development, etc..."

For AI engineers, building long-running agents is going to be a core competency in 2026. Agents that can successfully use external tools and have reliable behavior will positively impact many businesses.

Recent work from Anthropic, GitHub, and Docker shows us how we can do this step-by-step.


1. Start with a clear agent spec (agents.md or config)

Currently, most agents struggle with the following problems:

-- vague instructions
-- poor state management
-- poor workflow management

A good agent spec must include:

  • Role: what the agent does and does not do.
  • Tech stack: exact versions, frameworks, commands (pip install, npm test, pytest -q).
  • Examples: real samples of expected output.
  • Boundaries: things to avoid, private data that can't be touched, and API rate limits.
  • Structure: project layout, naming conventions, etc.

TLDR: Don’t rely on “You are a helpful assistant.” Give the agent a well-defined contract.


2. Break work into small, verifiable tasks

From Anthropic’s long-running agent experiments:

Agents fail when you tell them “build me a clone of X.” This task is vague, complex and ambiguous.

Instead, tell the agent what you want step-by-step. Break the problem into tasks, and then describe a clear workflow.
Plan → Code → Test → Deploy → Monitor

For this, the agent needs two things:

  • A task list
  • A strict workflow

TLDR: Agents cannot handle ambiguity. Choose small tasks, acceptance criteria, and tight feedback loops.


3. Persist state outside the model

Anthropic’s harness relies on:

  • progress logs
  • feature lists
  • file diffs
  • git commits
  • checklist of completed vs pending tasks

This ensures the agent survives session resets, context flush, and multi-hour workflows.
You can store your state in a file, database or even memory.

TLDR: Make sure your agent stores and retrieves the relevant context for all tasks in your workflow.


4. Don’t stuff everything in the context window

Most agents try to define everything in their system prompt and query context.
This leads to slow responses and excessive token charges.

Instead, try to skip the intermediate responses:

  • Let the agent generate Python/TS code
  • Let that code call external tools / APIs
  • Return results to the model

TLDR: As compared to simple context stuffing, this strategy leads to massive token savings. By choosing code generation to avoid intermediate responses, we make the agent respond faster and cheaper.


5. Security: sandbox the risky bits

If the agent executes code:

  • sandbox the environment
  • restrict allowed tools
  • restrict filesystem access
  • validate outputs
  • don't allow configs to be edited

When given infinite permissions, agents are (in)famous for creating havoc. Give them guardrails. You will sleep better.

TLDR: Run agents in containers to reduce application and server risk.


Conclusion

Agent = Behavior + State + Guardrails.

  1. Behavior: Clearly define what the agent is supposed to do using config files.
  2. State: Store contextual information in files, databases or memory.
  3. Guardrails: Define the tools it can access, the rate limits, and the things it MUST NOT do.

That's it, we hope your next AI Agent is a massive success. If you are looking to learn how Agents and LLMs work under the hood, try our AI Engineering Course here.