<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hujaifa 00 on Medium]]></title>
        <description><![CDATA[Stories by Hujaifa 00 on Medium]]></description>
        <link>https://medium.com/@hujaifa0699?source=rss-c7a8af016d13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hqp-LFtJXf07xTMO</url>
            <title>Stories by Hujaifa 00 on Medium</title>
            <link>https://medium.com/@hujaifa0699?source=rss-c7a8af016d13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:36:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hujaifa0699/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Task-Oriented AI Agent With Planning and Execution]]></title>
            <link>https://medium.com/@hujaifa0699/building-a-task-oriented-ai-agent-with-planning-and-execution-14b7671d9196?source=rss-c7a8af016d13------2</link>
            <guid isPermaLink="false">https://medium.com/p/14b7671d9196</guid>
            <category><![CDATA[ollama]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[artifical-intellegence]]></category>
            <category><![CDATA[aiagentsdevelopment]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Hujaifa 00]]></dc:creator>
            <pubDate>Sun, 29 Nov 2026 12:37:54 GMT</pubDate>
            <atom:updated>2026-11-29T12:37:54.708Z</atom:updated>
            <content:encoded><![CDATA[<h3>“Title”:Building a Task-Oriented AI Agent With Planning and Execution</h3><p>How I used Python, a local LLM, and a custom toolset to build an agent that plans, executes, and verifies tasks.</p><p>## 1. Introduction<br>When we ask a typical chatbot to “make a study plan,” it just generates text. But a **Task-Oriented AI Agent** goes further. It breaks the request into smaller tasks, selects the right tools to execute those tasks, checks if the results are correct, and asks for human approval before finishing.</p><p>In this article, I will demonstrate how I built a simple task-oriented agent using Python and a locally hosted LLM (Ollama).</p><p>## 2. The Agent Architecture<br>To build this agent, I designed a workflow that handles both successful execution and failed actions. Here is the original architecture diagram I created:</p><p>[CLICK HERE TO INSERT YOUR EXCALIDRAW DIAGRAM SCREENSHOT]</p><p>**How the flow works:**<br>* **Task Input:** The user provides a complex request (e.g., “Make a 3-day study plan”).<br>* **Planner:** The LLM breaks the input into a JSON list of actionable steps.<br>* **Action Selection &amp; Tool Execution:** The agent calls specific Python functions (tools) to get subjects, estimate hours, and build the schedule.<br>* **Result Checking:** The agent verifies if the output makes sense. If it fails, it loops back (this is where human approval comes in).<br>* **Final Response:** The validated result is shown to the user.</p><p>## 3. Implementation: The Tools<br>The agent uses a controlled set of four Python tools. I kept these tools deterministic and simple, so the LLM only has to decide *which* tool to call. <br>*(In my code, these are in `tools.py`)*</p><p>* `get_subjects()`: Returns a list of subjects.<br>* `estimate_hours(subject)`: Returns the study hours needed for a specific subject.<br>* `create_schedule()`: Generates the plan.<br>* `check_schedule()`: Validates that the schedule is not empty.</p><p>## 4. Implementation: The Agent Loop<br>Using Python and the `requests` library, I connected to a local Ollama LLM (`llama3.2:1b`). The code prompts the LLM to output a JSON plan, parses it, and executes the tools.</p><p>Here is a screenshot of the agent successfully running:</p><p>[CLICK HERE TO INSERT YOUR SUCCESSFUL TERMINAL SCREENSHOT]</p><p>As you can see, the LLM generated the plan, the Python tools executed it, and the system paused to ask for human approval (`Approve this schedule? (y/n)`).</p><p>## 5. Testing &amp; Failed Actions<br>To test the agent’s planning quality, I ran different task descriptions.</p><p>**Test 1: The Impossible Request**<br>I asked the agent to: *”make a study plan for 5 subjects in 1 day”*.</p><p>[CLICK HERE TO INSERT YOUR IMPOSSIBLE REQUEST SCREENSHOT]</p><p>**Observation:** The LLM tried to plan this, but the Python tools caught the constraint issue. This proved that the **Result Checking** loop is vital. Without it, the agent would blindly generate an impossible plan.</p><p>**Test 2: The Vague Request**<br>I simply typed: *”plan”*.</p><p>[CLICK HERE TO INSERT YOUR VAGUE REQUEST SCREENSHOT]</p><p>**Observation:** The planning quality degraded. The LLM hallucinated or returned generic steps. This showed me that prompt engineering and structured JSON outputs are critical for reliable agent behavior.</p><p>## 6. Human Approval<br>Before finalizing the response, the code uses an `input()` function to ask the human user for permission. This ensures that the agent does not execute risky actions (like saving a file or sending an email) without a human in the loop.</p><p>## 7. Lessons Learned<br>Building this agent taught me several key lessons about AI Engineering:<br>1. **Structured Output is Everything:** Local LLMs often output extra text. I had to write logic to find the `[` and `]` to extract the JSON plan safely.<br>2. **LLMs Need Guardrails:** The LLM doesn’t know when it’s failing; my Python “Result Checking” function had to catch the failures.<br>3. **Model Names Matter:** I learned that using the correct local model identifier (like `llama3.2:1b` instead of `llama3.2`) is crucial for API calls to succeed.</p><p>## 8. Conclusion<br>Task-oriented agents are the future of AI applications. By combining LLM planning with controlled Python execution and human approval, we can build systems that are both powerful and safe.</p><figure><img alt="A horizontal flowchart showing a 6-step AI Agent architecture. The steps are: 1. Task Input, 2. Planner (LLM), 3. Action Selection, 4. Tool Execution, 5. Result Checking, and 6. Final Response. A curved arrow points from Result Checking back to the Planner, labeled “Failed Action / Human Approval”." src="https://cdn-images-1.medium.com/max/848/1*suybDYSF6wX1P0xevSyd1A.png" /></figure><figure><img alt="The successful end-to-end execution. The agent breaks down the request into a plan, executes the Python tools to calculate hours and build the schedule, verifies the result, and pauses for user approval before giving the final response." src="https://cdn-images-1.medium.com/max/677/1*nRO71Qzjt1zRdWcxme4z7A.png" /></figure><figure><img alt="Testing edge cases with an impossible request. The agent attempts to plan, but the controlled Python tools prevent it from generating a logically flawed schedule, demonstrating the necessity of the Result Checking step." src="https://cdn-images-1.medium.com/max/788/1*ZyGz4osBCs_n3fWGgwYKWQ.png" /></figure><figure><img alt="Testing a vague user input. The LLM’s planning quality degrades, showing that task-oriented agents require clear prompts or further clarification loops to execute actions effectively." src="https://cdn-images-1.medium.com/max/782/1*Vee0r-Nj6vXE8F70jYFxmQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14b7671d9196" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>