Ollama and Qwen3 4B: Python agent template setup
Set up Python with Ollama and Qwen3 4B, configure local settings, and clean reasoning text for a connection test with an 80-token output limit.
Player not loading? Watch on YouTube
This tutorial builds a framework-free Python starter template for a local AI agent using Ollama and Qwen3 4B. The speaker tests whether Python can contact a local model and return a clean response. The template does not yet read files, use tools, or make decisions, so the result demonstrates a connection rather than useful work-task performance.
Setup covers installing Ollama, downloading and testing the model in the terminal, cloning the repository, and creating a Python virtual environment. A .env file holds the model name, Ollama URL, agent name, and thinking settings. The project separates its runtime from connectors that control information access and processors that clean and validate output. Git exclusions keep local settings and sensitive data out of the repository.
The speaker reports that Qwen overexplained a simple greeting. The working test disables thinking, adds a no-think instruction, and uses temperature 0, top P 0.1, and num predict 80. Cleanup code extracts the expected phrase, "local model connected," and removes common thinking blocks. It also flags certain reasoning-style responses as format failures. This distinction matters: a successful request does not by itself show that the model followed instructions. The final demonstration returns the expected phrase; an email summary agent is planned for the next experiment.