1 min read

A minimal AI agent in Python

How intelligence is embodied

I'm writing this post to show off a small project I built last week: a minimal AI agent that executes Python code to fulfill user requests.

Click here to try the demo.
Click here to read the core ~160 lines of code.

While I've built more complex AI applications before, I wanted to go back to the basics and fundamentally grasp what an AI agent is. Coding something myself forced the clarity of thought I was looking for.

I learned that an AI agent has the following components:

  1. Trigger: A user action or API call
  2. Intelligence: A way of interpreting the goal and deciding what to do next
  3. Memory: A way of keeping track of what's been done
  4. Parser: A way to transform text into code
  5. Tools: A way of taking action in the world

My minimal AI agent executes code to fulfill user requests. Its components are:

  1. Trigger: A user sends a request to the chatbot
  2. Intelligence: The Anthropic API (Claude) with a system prompt
  3. Memory: The message history
  4. Parser: Reading structured output from Claude
  5. Tools: An exec_code function that runs Python code from Claude

A more complex agent could have the ability to reminders to call itself in the future, a disk-based memory system containing gigabytes of information that requires a search function, or even a robot body to take action in the real world.

But the underlying components are the same. Take away any one of them and the AI agent would be useless.

Finally, I learned that without access to the right data, an AI agent is useless. While my minimal agent can modify image files on your local filesystem, it can't tell me what the weather is. This is where Model Context Protocol (MCP), web search, and even basic APIs are important.

I hope this is useful to someone out there. Send me your questions!