How to Write Clean AI Agent Code | Issue #70


Hi there,

You’ve probably noticed this by now: LLM prototypes are easy to build. But as soon as you try to turn them into actual production LLM systems… a lot more goes into it.

In this week’s video, I walk through how to structure AI agents in Python using design patterns like Chain of Responsibility, Observer, and Strategy. I’ll build a fully functional travel assistant using Pydantic AI and explore how to make your agent pipelines more maintainable, testable, and modular.

Hope you enjoy the video, and wish you a great weekend.

Cheers,

Arjan


Now available: ArjanCodes merch

If you want to grab a nice t-shirt, hoodie, hat, or even a mouse pad (yes, some people still use those!), check out our brand-new merch shop.

To celebrate the launch, you get 10% off your order by using the coupon code CLEANMERCH at checkout. Note that this offer is only valid until next Friday, September 19!

I’ll be adding more items soon, including a few special drops you definitely don’t want to miss. Stay tuned!


Do you enjoy my content on YouTube and would you like to dive in deeper?

🚀 Check out my online courses

My courses have helped thousands of developers take the next step in their careers. Check out these courses to help grow your skills and become a senior developer:

🔧 Need help with a complex codebase?

If your team is struggling with tech debt, unclear architecture, or cloud costs that keep creeping up, my team and I can help. We don’t just review, we get in and fix things. We’re only working with a few companies at a time to stay focused, so if it sounds like a fit:

Unsubscribe | Send by ArjanCodes

Wolvenplein 25, Utrecht, UT 3512 CK

The Friday Loop

Every Friday, you'll get a recap of the most important and exciting Python and coding news. The Friday Loop also keeps everyone posted on new ArjanCodes courses and any limited offers coming up.

Read more from The Friday Loop

Hi there, Have you ever found yourself writing functions like this? def render_article(article_id, db, logger, user, config, feature_flags, etc): …and then passing the same parameters through five different layers of your app? In my latest video, I walk through a realistic Python example and show how to fix this mess using the Context Object Pattern. I’ll start with the "before" version, refactor step by step, and explore: How to group related dependencies using a context object When this...

Hi there, This week’s video is all about uv workspaces, and why they’ve completely changed the way I manage Python projects. In the video, I walk you through a real-world example: I build a CLI tool and a FastAPI API that both fetch and summarize news headlines using OpenAI. But the real lesson is in how the project is structured. I show you how to share a local package between apps, define common dependencies like openai or httpx only once. And you can manage everything using uv’s workspace...

Hi there, When I see an if-statement with multiple elifs in my code, it almost always triggers an investigation. Is there some way to rewrite this to make the logic simpler? Is there a chance that in the future I'll need to add even more complexity? If so, I'll try to redesign the code so that I don't need that chain of if-elif statements. In this week’s video, I cover a design pattern that helped me eliminate many of those chains from a project + at the same time made the code easier to...