<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luca Lullo</title>
    <description>The latest articles on DEV Community by Luca Lullo (@lucalullo).</description>
    <link>https://dev.to/lucalullo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4231126%2Fce1aae25-404f-480e-a817-ab2a39956818.png</url>
      <title>DEV Community: Luca Lullo</title>
      <link>https://dev.to/lucalullo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucalullo"/>
    <language>en</language>
    <item>
      <title>Building an AI Agent from Scratch in Python: What I Learned</title>
      <dc:creator>Luca Lullo</dc:creator>
      <pubDate>Mon, 09 Nov 2026 12:45:22 +0000</pubDate>
      <link>https://dev.to/lucalullo/building-an-ai-agent-from-scratch-in-python-what-i-learned-1hbe</link>
      <guid>https://dev.to/lucalullo/building-an-ai-agent-from-scratch-in-python-what-i-learned-1hbe</guid>
      <description>&lt;h2&gt;
  
  
  Why I started this project
&lt;/h2&gt;

&lt;p&gt;I wanted to understand how AI agents actually work, beyond just using a framework.&lt;/p&gt;

&lt;p&gt;So I decided to build a small one from scratch in Python.&lt;/p&gt;

&lt;p&gt;It started as a personal learning exercise. I wasn't trying to build something production-ready or create another agent framework. I just wanted to understand the different components, how they interact, and what happens when you add more capabilities.&lt;/p&gt;

&lt;p&gt;I eventually ended up with nine versions of the same project, each introducing one new architectural concept.&lt;/p&gt;

&lt;p&gt;After finishing it, I thought it might be useful to share the process with anyone interested in learning how agents work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting with simple rules
&lt;/h2&gt;

&lt;p&gt;The first version was intentionally basic.&lt;/p&gt;

&lt;p&gt;It could receive a request, choose a tool using predefined rules, extract arguments, execute the tool, and store the result.&lt;/p&gt;

&lt;p&gt;Nothing fancy. No LLM, no external API, no framework.&lt;/p&gt;

&lt;p&gt;But that simplicity made it easier to see what each component was actually doing.&lt;/p&gt;

&lt;p&gt;From there, I started separating responsibilities. First the Executor, then a more generic Parser, followed by planning, memory management, and a Tool Registry.&lt;/p&gt;

&lt;p&gt;My approach was simple: one version, one concept, one architectural improvement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding an LLM
&lt;/h2&gt;

&lt;p&gt;Only after building those components did I introduce a language model.&lt;/p&gt;

&lt;p&gt;I used Qwen2.5-0.5B-Instruct, running locally, first for choosing tools and later for extracting arguments from natural language.&lt;/p&gt;

&lt;p&gt;What I found useful was that I could replace the rule-based components without having to redesign the entire system.&lt;/p&gt;

&lt;p&gt;The rest of the architecture stayed mostly the same.&lt;/p&gt;

&lt;p&gt;It helped me understand that the LLM is just one part of the agent. The surrounding code still handles tool execution, validation, planning, and state.&lt;/p&gt;

&lt;h2&gt;
  
  
  From one step to multiple steps
&lt;/h2&gt;

&lt;p&gt;The final version introduced basic multi-step execution.&lt;/p&gt;

&lt;p&gt;For example, given this request:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Add 2 and 3, then multiply the result by 4.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The agent creates two steps, executes the addition, and passes the result to the multiplication step.&lt;/p&gt;

&lt;p&gt;The final answer is 20.&lt;/p&gt;

&lt;p&gt;It's a small example, but it brings together the components developed throughout the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;The biggest takeaway for me was that building an agent became much less confusing once I stopped treating it as one big system.&lt;/p&gt;

&lt;p&gt;Separating routing, parsing, execution, planning, and memory made it easier to understand what each part was responsible for.&lt;/p&gt;

&lt;p&gt;It also made frameworks like LangChain or CrewAI easier to approach, because I now had a clearer idea of the problems those frameworks are trying to solve.&lt;/p&gt;

&lt;p&gt;There are still plenty of limitations. The planner uses simple rules, memory is stored in a Python list, and the local LLM can make mistakes when choosing tools or extracting arguments.&lt;/p&gt;

&lt;p&gt;But that's fine for what I wanted to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing the project
&lt;/h2&gt;

&lt;p&gt;I've made the whole project available on GitHub, with all nine versions, Jupyter notebooks, architecture diagrams, and documentation in English and Italian.&lt;/p&gt;

&lt;p&gt;There's also an executable notebook on Kaggle.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/lucalullo/building-ai-agent" rel="noopener noreferrer"&gt;https://github.com/lucalullo/building-ai-agent&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kaggle:&lt;/strong&gt; &lt;a href="https://www.kaggle.com/code/lucalullo/building-ai-agent" rel="noopener noreferrer"&gt;https://www.kaggle.com/code/lucalullo/building-ai-agent&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I originally built this for myself, but I hope the step-by-step approach might help someone else understand agent architecture a little better.&lt;/p&gt;

&lt;p&gt;If you've tried building an agent without a framework, I'd be interested to hear how you approached it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing note:&lt;/strong&gt; I used AI assistance to translate, organize, and polish this article in English. The project, its implementation, and the technical content are my own.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
