<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv" -->

---
title: Build Your Own Agentic Harness in Python - Full Tutorial
description: A hands-on tutorial walks through building a custom AI agent 'harness' in pure Python without external agent frameworks, progressing version by version: a...
canonical: https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Build Your Own Agentic Harness in Python - Full Tutorial | daily.dev
og:description: A hands-on tutorial walks through building a custom AI agent 'harness' in pure Python without external agent frameworks, progressing version by version: a...
og:url: https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv
og:image: https://api.daily.dev/og/posts/O2DdZumbV.png
og:image:alt: Build Your Own Agentic Harness in Python - Full Tutorial
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build Your Own Agentic Harness in Python - Full Tutorial

**[Tech With Tim](https://daily.dev/sources/TechWithTim)** · 37 min read · 0 upvotes · 0 comments

## Summary

A hands-on tutorial walks through building a custom AI agent 'harness' in pure Python without external agent frameworks, progressing version by version: a basic LLM chat call using OpenAI's SDK (pointed at either OpenAI's API or a local Ollama model), then tool calling with manually written JSON schemas, an agentic loop that lets the model iterate until it stops requesting tools, MCP (Model Context Protocol) server integration for dynamically discovered tools like time and web fetch, simple persistent memory via a markdown file injected into the system prompt, and finally model routing/switching between local and cloud models. The video includes a HubSpot sponsorship segment promoting a free AI tools bundle.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=H5o1P8RMiMw>

## Questions this post answers

### How do you give a Python LLM agent the ability to call tools without using a framework like LangChain?

Write Python functions for each tool, map them by name in a dictionary, and create a JSON schema describing each function's name, description, and parameters to pass alongside the messages to the chat completions call. The model cannot execute functions itself; it only returns a tool_call response naming the function and arguments, which your code then executes and feeds back into the conversation as a tool result message.

_Developers piecing together agent tool-calling patterns can find practical code walkthroughs like this on daily.dev._

### How do I connect an MCP server to a custom Python AI agent instead of using Claude Code?

Use the MCP Python package along with async OpenAI and an async exit stack to connect to stdio-based MCP servers that run locally via uv. The agent loops through configured servers, initializes each session asynchronously, discovers the tools each server exposes, and merges them into the same tool schema used for local functions so the model can call MCP tools exactly like local ones.

_Anyone wiring MCP support into their own agent code can browse similar implementation walkthroughs on daily.dev._

### How can an AI agent remember information like a user's name across separate runs?

Persist memory to a plain markdown file and load its contents into the system prompt every time the agent starts, injecting whatever was previously saved as context before the conversation begins. A dedicated save_memory tool lets the model write new facts to that file during a session, so restarting the program still surfaces prior facts like a stored name and age in later runs.

_Developers adding simple persistent memory to agents can compare approaches like this on daily.dev._

## Similar posts on daily.dev

- [Building AI Agents in Python](https://daily.dev/posts/building-ai-agents-in-python-d6gjflukc) · Planet Python · 1 upvotes · 1 comments
- [The Ultimate Beginners’ Guide to Building an AI Agent in Python](https://daily.dev/posts/the-ultimate-beginners-guide-to-building-an-ai-agent-in-python-dkhiab38j) · Towards Data Science · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#ai-agents](https://daily.dev/tags/ai-agents), [#openai](https://daily.dev/tags/openai), [#mcp](https://daily.dev/tags/mcp), [#ollama](https://daily.dev/tags/ollama)

[View this post on daily.dev](https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Build Your Own Agentic Harness in Python - Full Tutorial","url":"https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv"},"datePublished":"2026-10-04T14:33:03.394Z","dateModified":"2026-10-04T21:47:10.532Z","description":"A hands-on tutorial walks through building a custom AI agent 'harness' in pure Python without external agent frameworks, progressing version by version: a...","image":"https://i.ytimg.com/vi/H5o1P8RMiMw/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/H5o1P8RMiMw/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Tech With Tim","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Tech With Tim","logo":"https://media.daily.dev/image/upload/s--6vVIDfU0--/f_auto/v1711726146/logos/TechWithTim","url":"https://daily.dev/sources/TechWithTim"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,ai-agents,openai,mcp,ollama","timeRequired":"PT37M","video":{"@type":"VideoObject","name":"Build Your Own Agentic Harness in Python - Full Tutorial","description":"A hands-on tutorial walks through building a custom AI agent 'harness' in pure Python without external agent frameworks, progressing version by version: a...","thumbnailUrl":"https://i.ytimg.com/vi/H5o1P8RMiMw/sddefault.jpg","uploadDate":"2026-10-04T14:33:03.394Z","duration":"PT37M","url":"https://api.daily.dev/r/O2DdZumbV","embedUrl":"https://www.youtube.com/embed/H5o1P8RMiMw"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Tech With Tim","item":"https://daily.dev/sources/TechWithTim"},{"@type":"ListItem","position":3,"name":"Build Your Own Agentic Harness in Python - Full Tutorial"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/build-your-own-agentic-harness-in-python---full-tutorial-o2ddzumbv#faq","mainEntity":[{"@type":"Question","name":"How do you give a Python LLM agent the ability to call tools without using a framework like LangChain?","acceptedAnswer":{"@type":"Answer","text":"Write Python functions for each tool, map them by name in a dictionary, and create a JSON schema describing each function's name, description, and parameters to pass alongside the messages to the chat completions call. The model cannot execute functions itself; it only returns a tool_call response naming the function and arguments, which your code then executes and feeds back into the conversation as a tool result message. Developers piecing together agent tool-calling patterns can find practical code walkthroughs like this on daily.dev."}},{"@type":"Question","name":"How do I connect an MCP server to a custom Python AI agent instead of using Claude Code?","acceptedAnswer":{"@type":"Answer","text":"Use the MCP Python package along with async OpenAI and an async exit stack to connect to stdio-based MCP servers that run locally via uv. The agent loops through configured servers, initializes each session asynchronously, discovers the tools each server exposes, and merges them into the same tool schema used for local functions so the model can call MCP tools exactly like local ones. Anyone wiring MCP support into their own agent code can browse similar implementation walkthroughs on daily.dev."}},{"@type":"Question","name":"How can an AI agent remember information like a user's name across separate runs?","acceptedAnswer":{"@type":"Answer","text":"Persist memory to a plain markdown file and load its contents into the system prompt every time the agent starts, injecting whatever was previously saved as context before the conversation begins. A dedicated save_memory tool lets the model write new facts to that file during a session, so restarting the program still surfaces prior facts like a stored name and age in later runs. Developers adding simple persistent memory to agents can compare approaches like this on daily.dev."}}]}
```

