All AI videos

AI video

Build Your Own Agentic Harness in Python - Full Tutorial

A code-first guide to the main parts of an agent harness, from a single model call to tools, repeated tool execution, MCP servers, and persistent memory.

Tech With Tim · 2026 featured video

Watch on YouTube

What this video shows

Tim Ruscica starts with an OpenAI-compatible client pointed at a local model, then adds file-listing, reading, and writing functions as tools. The first version stops after one tool request. The next version keeps returning tool results to the model until it produces a final answer, which exposes the small control loop at the centre of many agent systems.

The later sections connect the harness to MCP servers, inject a local memory file on each run, and collect several model providers behind one configuration. The tutorial helps you see the mechanics that frameworks such as LangChain or CrewAI package for you, but its compact examples need stricter permissions, stopping rules, and tests before you use them with important files or remote services.

Read OpenAI's function-calling guide alongside the first tool example. Use the official MCP architecture and Python SDK when you rebuild the MCP client.

What you will learn

  • A tool schema describes an action to the model, but your application still validates the arguments, runs the Python function, and returns the result.
  • A useful agent loop needs an explicit stop condition and an iteration limit because the model may request several tools or repeat a failed request.
  • A host can discover tools from separate MCP servers, while direct Python functions can remain simpler for a small fixed tool set.
  • You can use a file to demonstrate persistent memory clearly, but production systems need rules for what gets stored, who can read it, and how stale or sensitive entries are removed.

How to apply this safely

  1. Rebuild the first two versions with one read-only tool and log every model request, tool argument, result, and stop reason.
  2. Add argument validation, a maximum iteration count, timeouts, and least-privilege tools before giving the loop access to an allowlisted workspace.
  3. Compare a direct Python tool with the same capability exposed through an MCP server, then keep the simpler option unless another client needs the shared server.
  4. Create tests for malformed arguments, missing files, repeated calls, tool errors, and the final response before connecting real data.

Important limitations

  • The tutorial demonstrates the harness mechanics in a local workspace. It does not implement authentication, approval gates, sandboxing, audit storage, concurrency control, or recovery after a process crash.
  • The memory example injects a text file into the prompt. That works for a small demo, but it does not solve retrieval quality, privacy, retention, or prompt-injection risks.

Sources to check

Continue learning on Learnetto

Best MCP courses

Learn when MCP helps and how clients, servers, tools, and resources connect.