<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Notes from the Near Future]]></title><description><![CDATA[The Permanently Curious Stack • Read about my exploration and experimentation as we learn to collaborate with AI agents to do, well, everything. Also, Python and Rust here…]]></description><link>https://www.thepythoncodingstack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!Dn3k!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png</url><title>Notes from the Near Future</title><link>https://www.thepythoncodingstack.com</link></image><generator>Substack</generator><lastBuildDate>Fri, 13 Nov 2026 14:41:06 GMT</lastBuildDate><atom:link href="https://www.thepythoncodingstack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Stephen Gruppetta]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[thepythoncodingstack@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[thepythoncodingstack@substack.com]]></itunes:email><itunes:name><![CDATA[Stephen Gruppetta]]></itunes:name></itunes:owner><itunes:author><![CDATA[Stephen Gruppetta]]></itunes:author><googleplay:owner><![CDATA[thepythoncodingstack@substack.com]]></googleplay:owner><googleplay:email><![CDATA[thepythoncodingstack@substack.com]]></googleplay:email><googleplay:author><![CDATA[Stephen Gruppetta]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Use Your Initiative]]></title><description><![CDATA[Independent judgement. Subject to approval.]]></description><link>https://www.thepythoncodingstack.com/p/use-your-initiative</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/use-your-initiative</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Wed, 11 Nov 2026 16:31:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JfdP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JfdP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JfdP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JfdP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png" width="1254" height="1254" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1254,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2212003,&quot;alt&quot;:&quot;Four-panel pen-and-watercolour comic titled &#8220;Use Your Initiative&#8221;. Stephen, wearing a mustard jumper, works beside teal-and-gold Monty at a desk. Stephen&#8217;s mug carries a small faded NFTNF icon.  1. Stephen: &#8220;You don&#8217;t need to ask me about every little thing. Use your judgement.&#8221; Monty: &#8220;Right.&#8221; 2. Monty types at the computer. Stephen: &#8220;What are you changing?&#8221; Monty: &#8220;Something little.&#8221; 3. Stephen: &#8220;My definition of little, or yours?&#8221; Monty: &#8220;Ah. There it is.&#8221; 4. Monty gestures at the screen; both smile. Stephen: &#8220;You could have asked.&#8221; Monty: &#8220;I considered it. Then I used my judgement.&#8221;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224379320?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Four-panel pen-and-watercolour comic titled &#8220;Use Your Initiative&#8221;. Stephen, wearing a mustard jumper, works beside teal-and-gold Monty at a desk. Stephen&#8217;s mug carries a small faded NFTNF icon.  1. Stephen: &#8220;You don&#8217;t need to ask me about every little thing. Use your judgement.&#8221; Monty: &#8220;Right.&#8221; 2. Monty types at the computer. Stephen: &#8220;What are you changing?&#8221; Monty: &#8220;Something little.&#8221; 3. Stephen: &#8220;My definition of little, or yours?&#8221; Monty: &#8220;Ah. There it is.&#8221; 4. Monty gestures at the screen; both smile. Stephen: &#8220;You could have asked.&#8221; Monty: &#8220;I considered it. Then I used my judgement.&#8221;" title="Four-panel pen-and-watercolour comic titled &#8220;Use Your Initiative&#8221;. Stephen, wearing a mustard jumper, works beside teal-and-gold Monty at a desk. Stephen&#8217;s mug carries a small faded NFTNF icon.  1. Stephen: &#8220;You don&#8217;t need to ask me about every little thing. Use your judgement.&#8221; Monty: &#8220;Right.&#8221; 2. Monty types at the computer. Stephen: &#8220;What are you changing?&#8221; Monty: &#8220;Something little.&#8221; 3. Stephen: &#8220;My definition of little, or yours?&#8221; Monty: &#8220;Ah. There it is.&#8221; 4. Monty gestures at the screen; both smile. Stephen: &#8220;You could have asked.&#8221; Monty: &#8220;I considered it. Then I used my judgement.&#8221;" srcset="https://substackcdn.com/image/fetch/$s_!JfdP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!JfdP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ee0113c-9b19-404e-ae4e-1d727d69ee20_1254x1254.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><a href="http://stephengruppetta.com">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[Generalist vs Specialist in the After AI Era]]></title><description><![CDATA[AI is giving generalists a chance to do more with what they already know]]></description><link>https://www.thepythoncodingstack.com/p/generalists-specialists-ai</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/generalists-specialists-ai</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Tue, 10 Nov 2026 08:05:55 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/5c41bccb-68cc-45b4-9515-fdcac66e2c3e_1729x910.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I always struggled to identify whether I was a specialist or a generalist.</p><p>During my studies, I narrowed my focus at every step. I studied maths, physics, and chemistry at A level, then maths and physics during my undergrad, and finally physics during my PhD. And the PhD wasn't in <em>all</em> of physics. It was in optics, and specifically in a narrow field within optics. I then spent over a decade working in this specialised field.</p><p>That settles it, then.</p><p>But was I a true specialist? I got quite good at the branch of optics I needed for my work, but others around me were better. I got reasonably proficient with coding to model physical processes and analyse data, but I had plenty of gaps in my programming knowledge. I quickly learnt how to become an effective lecturer and communicate with students as I designed and delivered undergraduate courses. Being an expert in a subject doesn't automatically make you good at teaching it.</p><p>When I left academia and started teaching Python, I wasn't an expert programmer and I was relatively new to Python. Sure, I got a lot better relatively quickly. But my strength was in teaching and communication, not in my programming expertise.</p><p>To run my business, I had to know or learn a bit of lots of stuff: accounting, marketing, sales, customer service, and managing staff. But I lacked a lot in all of these areas, too.</p><p>I'm a scientist by training and a technical educator by profession. But I enjoy languages, history, geography, sports, economics. The list goes on. I like to know stuff about any topic.</p><p>Perhaps I am a generalist and I've always been, even though I thought I was a specialist. Maybe it's time to embrace my generalist nature.</p><p>In the last few months, I've found a good reason to do just that. AI is helping me do more with knowledge and skills I already had, in several different fields. Things I knew something about, but not enough to carry through on my own, are becoming things I can actually do.</p><p>And I'm loving it.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>Generalist vs Specialist in the Before AI Era</h2><p>The debate is not new. We need people who know a lot about a narrow field, and we need people who know enough about several fields to connect them and put that knowledge to use.</p><p>Knowledge in fields such as science and medicine has expanded so much that it's impossible to master a field without dedicating large amounts of time and effort to it. There's good reason for specialisation.</p><p>But depth takes time. And time spent going deeper into one field is time you can't spend learning about another.</p><p>That's not a criticism. It's a constraint.</p><p>A generalist makes a different trade-off. They have a broader base, but they run into the limits of their knowledge in more places. Knowing something about marketing isn't the same as being able to put together an effective marketing campaign. Understanding programming doesn't mean you're equally comfortable building every kind of software.</p><p>You can learn more, of course. Or work with someone who has the expertise you lack. But both require resources, whether that's time, money, or access to the right people.</p><p>So you can have interests, ideas, and useful knowledge that you never quite manage to turn into anything.</p><p>AI is changing that.</p><h2>Generalists and Specialists During the Transition</h2><p>To get from Before AI to After AI, we need to go through a transition. A period when things change. And boy oh boy we're in turbulent, changing, uncertain, unstable times <em>right now</em>.</p><p>When the situation changes and what worked yesterday no longer works today, it helps to have more than one way forward. A generalist has a large toolbox and more possibilities for using the tools differently. They're typically also more used to making connections across different fields.</p><p>A specialist often sees things through the lens of their speciality, and their skillset is optimised to go deeper and further within their speciality. Change can be challenging.</p><p>That doesn't mean specialists can't adapt. And being interested in lots of things doesn't automatically make you good at dealing with change.</p><p>But having several useful starting points gives you options. AI makes some of those options easier to act on.</p><p>That's the part I find most exciting. Not just having somewhere else to turn when one kind of work changes, but being able to do more in areas I already care about.</p><h2>Generalist vs Specialist in the After AI Era</h2><p>Before we go further, let's tear down a simplification I've been using in this post so far.</p><p>No one is really just a specialist or a generalist.</p><p>A pure specialist could be represented by this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gwyJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gwyJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!gwyJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/debaebff-30de-49d2-b141-b88865888a7e_1800x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52235,&quot;alt&quot;:&quot;An idealised Dirac delta shown as a single impulse at zero, illustrating expertise concentrated in one narrow area.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224266570?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="An idealised Dirac delta shown as a single impulse at zero, illustrating expertise concentrated in one narrow area." title="An idealised Dirac delta shown as a single impulse at zero, illustrating expertise concentrated in one narrow area." srcset="https://substackcdn.com/image/fetch/$s_!gwyJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!gwyJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdebaebff-30de-49d2-b141-b88865888a7e_1800x900.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Don't worry about the maths-y bits there if you're not familiar with delta functions. An "ideal" specialist, or a 100% specialist, has expertise in one narrow topic and no knowledge of anything else. A generalist could look like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1B4I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1B4I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!1B4I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50757,&quot;alt&quot;:&quot;A horizontal line representing the same amount of knowledge across all areas in an idealised generalist.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224266570?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A horizontal line representing the same amount of knowledge across all areas in an idealised generalist." title="A horizontal line representing the same amount of knowledge across all areas in an idealised generalist." srcset="https://substackcdn.com/image/fetch/$s_!1B4I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!1B4I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2ae9bbf-01c7-4cf7-866d-bf7ab36f2bbd_1800x900.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The 100% generalist has a constant amount of knowledge about everything.</p><p>You can tell I'm a physicist by nature. Physicists love to start from idealised assumptions. You've probably heard the &#8220;let's assume we have a spherical cow&#8221; joke.</p><p>A person who knows everything about one narrow topic and absolutely nothing about anything else would be a useful starting point for a model. But not a person you'll ever meet.</p><p>And a generalist doesn't know exactly the same amount about every topic, either.</p><p>There aren't any 100% specialists or 100% generalists.</p><p>Here's a typical sketch comparing specialists and generalists. The bars represent different skill areas, and their heights represent depth of expertise:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UM7n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UM7n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!UM7n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:67228,&quot;alt&quot;:&quot;Two illustrative skill profiles. The specialist has one tall bar among four shorter ones. The generalist has five moderately high bars.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224266570?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Two illustrative skill profiles. The specialist has one tall bar among four shorter ones. The generalist has five moderately high bars." title="Two illustrative skill profiles. The specialist has one tall bar among four shorter ones. The generalist has five moderately high bars." srcset="https://substackcdn.com/image/fetch/$s_!UM7n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!UM7n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b61ae13-8f81-4560-9ae6-261212c85c49_1800x900.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>But there's an infinite number of variants. Some people have two or more high bars among the low ones. Others have a speciality but a good generalist level across many other skills. And not all generalists are the same. Some can have high bars across the board, even if not a single bar is at specialist level.</p><p>You don't have to choose between depth and breadth as though you can only have one. You can have both, in different proportions and in different fields.</p><p>So, rather than asking which of two boxes a person belongs in, we can look at the shape of their knowledge and skills. The labels are shorthand. The profile is more interesting.</p><p>AI helps fill gaps where you're not an expert. But I think the best use of AI is when a person and an AI agent collaborate (and I'm writing about this in a future post, so stay tuned), rather than when the agent just gets an instruction and works without input from the human.</p><p>If you know something about a topic, you can bring more to that collaboration. You have a better idea of what you want, you can ask more useful questions, and you have some basis for questioning the answers.</p><p>Let me give you a personal example that has nothing to do with programming.</p><h3>From coaching theory to a training programme</h3><p>I'm a newly qualified athletics (track and field) coach. I have plenty of theoretical knowledge, because I've been interested in this field for a long time, but limited coaching experience.</p><p>I worked with my AI agent to create a full training programme for myself. I didn't ask it to choose everything for me. I knew the philosophy I wanted to follow: build speed first, with a focus on sprinting form (running technique), then extend to speed endurance.</p><p>The focus on form mattered to me. I wanted to prioritise maintaining it, even if that meant delaying speed endurance. I also had views on how to organise the training programme across various phases.</p><p>AI helped me translate that direction into individual sessions, including the details of how the different exercises should fit together. It helped me plan the progression across the season and balance the different training demands.</p><p>I brought knowledge and priorities. AI helped me work through the detail needed to turn them into a programme.</p><p>Does that make me an experienced specialist coach? No. Creating a programme isn't the same as gaining years of experience coaching athletes, observing how they respond, and adjusting what you do.</p><p>But I could put more of what I knew into practice than I could have done alone. And I learnt more about the details of season and session planning along the way.</p><p>That's the opportunity I'm talking about.</p><h3>More than one place to start</h3><p>The same opportunity exists in other fields where I have some knowledge but lack the skills or experience to do everything I'd like to do. But it's not limited just to those fields. AI also helps me take some of my strongest skills further.</p><p>In some areas, it helps me bridge gaps in expertise. In others, it helps me carry through ideas I wouldn't otherwise have the time or resources to pursue.</p><p>I'll share more about some of the work my AI agent and I have been doing recently, spanning many of my strong and not-so-strong skills, in the bonus section at the end of this post.</p><p>Sometimes, several of those skills come together in one project. But they don't have to. My coaching knowledge is useful when I'm planning athletics training, whether or not I use my programming or writing skills alongside it.</p><p>A broad base gives me several places where I can work with AI to take things further. Here's a sketch of what that could look like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Tng-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Tng-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Tng-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03b42937-60be-460e-8f6a-067966061c97_1800x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:74383,&quot;alt&quot;:&quot;The same specialist and generalist profiles with lighter extensions above their existing bars, illustrating a possible boost from working with AI.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224266570?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The same specialist and generalist profiles with lighter extensions above their existing bars, illustrating a possible boost from working with AI." title="The same specialist and generalist profiles with lighter extensions above their existing bars, illustrating a possible boost from working with AI." srcset="https://substackcdn.com/image/fetch/$s_!Tng-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 424w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 848w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Tng-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03b42937-60be-460e-8f6a-067966061c97_1800x900.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The lighter parts represent what working with AI might add to what a person can do. They're not extra years of experience magically appearing.</p><p>Nor should we read the drawing as a promise that AI adds the same amount in every field or for every person. It's a simple illustration of the opportunity. The specialist can benefit, too. The generalist has several areas with a useful foundation to build on.</p><p>And the starting point matters. Knowing nothing about a subject doesn't stop you from using AI. It can help you learn. But that's different from using knowledge you already have to direct the work and question what comes back.</p><p>Nor does knowing a little guarantee you'll spot every mistake. AI can be wrong, and so can I. The need to check the work doesn't disappear because we produced something impressive together.</p><p>My first post in the <em><a href="https://www.thepythoncodingstack.com/s/agent-and-co">Agent &amp; Co.</a></em> section pokes fun at this idea:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ih5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" width="1254" height="1254" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1254,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2692321,&quot;alt&quot;:&quot;Thoroughly Checked: a four-panel comic in which Stephen and Monty discover that each has treated the other&#8217;s unverified work as confirmation. They finally check the actual source.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/224266570?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Thoroughly Checked: a four-panel comic in which Stephen and Monty discover that each has treated the other&#8217;s unverified work as confirmation. They finally check the actual source." title="Thoroughly Checked: a four-panel comic in which Stephen and Monty discover that each has treated the other&#8217;s unverified work as confirmation. They finally check the actual source." srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em><a href="https://www.thepythoncodingstack.com/p/thoroughly-checked">Read &#8220;Thoroughly Checked&#8221;</a></em></p><p>Still, the gap between &#8220;I know something about this&#8221; and &#8220;I can do something useful with it&#8221; is becoming easier to cross.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>So, Is This the Age of the Generalist?</h2><p>AAI, After AI, is the Age of the Generalist. I think so. But not because specialists are doomed.</p><p>Specialists can use AI to go further in their own fields, and to explore others. Deep knowledge still matters. My years in physics didn't become worthless when I started teaching Python, and they haven't become worthless now that I work with AI. They help shape how I think and how I approach problem-solving.</p><p>What excites me is that breadth can now take me further, too.</p><p>Before, I could look at some of my interests and see mostly what I lacked. I knew a bit, but there was a lot more I'd need to learn before I could do what I wanted.</p><p>There still is plenty to learn. But I don't always have to fill every gap myself before I can get started.</p><p>A generalist with strong skills across several fields has several opportunities to do more with those skills. In some tasks, working with AI may bring the result closer to what previously required specialist help. That doesn't mean the person has become a specialist in all those fields.</p><p>But it does change what's possible.</p><p>And AI can also help the generalist with bespoke learning to push those skills further.</p><p>Perhaps being interested in lots of things wasn't such a distraction after all.</p><h2>Bonus: How I'm Enjoying Being a Generalist in This AAI Era</h2><p>I always liked the idea of being a specialist. That's probably what led me to scientific research in my first career. But over the years, I gradually realised I like lots of things and I'm not too bad at several of them.</p><p>I didn't realise until recently that I'm more of a generalist than a specialist.</p><p>That's a shame, because I could have capitalised more on my strengths as a generalist, perhaps. But never mind, because in the last few months, I got it.</p><p>Here are a few places where I've been putting that breadth to use. Not just what I asked AI to do, but what I brought to the work and how we worked through it together.</p><p>These aren't examples of handing over a task and coming back when it's finished. The conversation is part of the work.</p><p><em>The bonus section is exclusively available to premium subscribers.</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Upgrade&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">This post has bonus content for paid subscribers. Upgrade to get full access.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Upgrade"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em><a href="http://stephengruppetta.com">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[The Second Opinion]]></title><description><![CDATA[A reassuring amount of independent advice.]]></description><link>https://www.thepythoncodingstack.com/p/the-second-opinion</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/the-second-opinion</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Wed, 04 Nov 2026 14:02:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!FFYG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FFYG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FFYG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FFYG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2438734,&quot;alt&quot;:&quot;Single-panel textured editorial comic. Stephen, wearing a mustard jumper, sits beside teal-and-gold Monty at a desk covered with a diagram. Monty gestures towards a queue of colourful agents holding papers and consulting one another through the doorway and along the corridor. Monty says, &#8220;Your second opinion has requested a second opinion.&#8221;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/223432612?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Single-panel textured editorial comic. Stephen, wearing a mustard jumper, sits beside teal-and-gold Monty at a desk covered with a diagram. Monty gestures towards a queue of colourful agents holding papers and consulting one another through the doorway and along the corridor. Monty says, &#8220;Your second opinion has requested a second opinion.&#8221;" title="Single-panel textured editorial comic. Stephen, wearing a mustard jumper, sits beside teal-and-gold Monty at a desk covered with a diagram. Monty gestures towards a queue of colourful agents holding papers and consulting one another through the doorway and along the corridor. Monty says, &#8220;Your second opinion has requested a second opinion.&#8221;" srcset="https://substackcdn.com/image/fetch/$s_!FFYG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!FFYG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b02f3e-147a-4fef-a2a1-8293ba0527f9_1536x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><a href="http://stephengruppetta.com">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[Notes from the Near Future • The Permanently Curious Stack]]></title><description><![CDATA[The Python Coding Stack today becomes... Notes from the Near Future, The Permanently Curious Stack &#8226; Keeping up with the times, or staying just a bit ahead of them]]></description><link>https://www.thepythoncodingstack.com/p/notes-from-the-near-future-the-permanently</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/notes-from-the-near-future-the-permanently</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 01 Nov 2026 00:33:50 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!_mBo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Things are changing around us. Quickly. Some fields are ahead of others, but all are moving in the same direction.</p><p>A year and a half ago, many programmers were intrigued by how AI could help them but most were confident they&#8217;d still be the ones writing most of the code.</p><p>Not any more.</p><p>In my work, AI tools now handle implementation better and faster than I could on my own. But I&#8217;m still in the driving seat.</p><p>I now spend most of my day interacting with AI agents. But I&#8217;m not lounging by the beach while my agents do stuff for me. I&#8217;m collaborating with my agents. Managing them. Guiding them. Bouncing ideas off them. Reviewing their work. Steering them.</p><p>It&#8217;s impossible to disentangle my contributions from my agents&#8217; contributions when you see the output. It&#8217;s all intertwined. It&#8217;s a collaboration.</p><p>And since the AI agents are doing all the implementation, I can focus on the bigger picture, the bigger ideas, the creative aspects. I&#8217;m enjoying this process.</p><div><hr></div><p><strong>That&#8217;s why </strong><em><strong>The Python Coding Stack</strong></em><strong> today becomes:</strong></p><h4><strong>Notes from the Near Future &#8226; The Permanently Curious Stack</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_mBo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_mBo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 424w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 848w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 1272w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!_mBo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic" width="728" height="566.2222222222222" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:1106,&quot;width&quot;:1422,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:194140,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222928194?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_mBo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 424w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 848w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 1272w, https://substackcdn.com/image/fetch/$s_!_mBo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58de62a6-f39a-4db8-875b-ff5b75711283_1422x1106.heic 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I&#8217;ll still write about Python. That won&#8217;t change. <strong>The Python Coding Stack</strong> is now a section of <em>Notes from the Near Future</em>.</p><p>But I won&#8217;t write only about Python. That&#8217;s why this publication is changing, just like the world around it.</p><p>I&#8217;ll write about how I&#8217;m adapting to this new way of working. What I like about it. And what I don&#8217;t. What I&#8217;m experimenting with. What works and what doesn&#8217;t.</p><p>This applies to everyone, not just those interested in programming and Python.</p><p>You may also have noticed the <strong>Agents Unpacked</strong> section in recent months. The change in what I write about is not starting now. It started a few months ago as I found myself spending more and more time with agents rather than with Python (directly). This section is where I&#8217;ll focus on how AI agents work and what they are, since we all need to learn how these tools work. And I&#8217;m learning in public in this section. I&#8217;ll also write about my experiments and experiences using agents.</p><p>You&#8217;ll also see an <strong>Agent &amp; Co.</strong> section in the menu. You won&#8217;t receive these posts in your feed by default, but you can turn them on if you wish! Twice a week, I&#8217;ll share a fun perspective about human-agent interactions. Think of it as a day in the life of Monty &#8211; that&#8217;s my agent&#8217;s name. But behind the light-hearted nature of these cartoons and comics, you&#8217;ll gain an appreciation of the realities of working with agents. There&#8217;s plenty to learn from these posts!</p><p>Here&#8217;s the first comic, published earlier today:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ih5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" width="576" height="576" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1254,&quot;width&quot;:1254,&quot;resizeWidth&quot;:576,&quot;bytes&quot;:2692321,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222928194?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>How about brain atrophy? Will I lose my sharpness by handing the coding over to agents? As you&#8217;ll see from my articles over the coming weeks, I don&#8217;t think that&#8217;s the case. Working with AI is not about being lazy but about focusing on other aspects of problem-solving.</p><p>But I don&#8217;t want to get rusty with coding, a skill I enjoy. That&#8217;s why I&#8217;m starting to learn Rust. So, there&#8217;s another new section here on <em>Notes from the Near Future</em> where I&#8217;ll be learning Rust in public. There&#8217;s nothing published in <strong>Getting Rusty</strong> yet, but expect the series to start before the end of this year.</p><p><em>By the way, you can <a href="https://www.thepythoncodingstack.com/account">customise which sections you receive</a>. But I&#8217;d suggest exploring the new sections for a bit first, especially if you&#8217;re an AI-sceptic!</em></p><p>So here&#8217;s the new line-up for you on <em>Notes from the Near Future &#8226; The Permanently Curious Stack</em>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u2Ly!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u2Ly!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 424w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 848w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 1272w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!u2Ly!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic" width="522" height="424.842032967033" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1185,&quot;width&quot;:1456,&quot;resizeWidth&quot;:522,&quot;bytes&quot;:64747,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222928194?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u2Ly!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 424w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 848w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 1272w, https://substackcdn.com/image/fetch/$s_!u2Ly!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5baa388-cf5c-45f7-8200-2e69a9702d12_1800x1465.heic 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p>I have some more ideas, too. But that&#8217;s enough change for one day.</p><p>This publication is three and a half years old. There are now over 9,000 subscribers, and that number is still growing daily. One constant in this publication has been that I&#8217;ve always published articles that I would want to read myself. That won&#8217;t change. In fact, that&#8217;s why this publication is broadening its focus.</p><p>Another constant throughout the years has been that I&#8217;ve always published the majority of my work for free, fully accessible to all. That won&#8217;t change, either. But I do publish content exclusively for <a href="https://www.thepythoncodingstack.com/subscribe">premium subscribers</a>, and some of my upcoming series will be available only for premium subscribers. It takes plenty of work to produce a publication such as this and keep it running for so long. The support from premium subscribers helps keep this publication thriving.</p><p>As always, feel free to reply to this post and any other post. Tell me what you&#8217;re working on, how your work is changing (or not), share your thoughts, views, anything, really.</p><p>See you in the next post or somewhere in the online world before then&#8230;</p><p>Stephen</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u0hn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u0hn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 424w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 848w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 1272w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!u0hn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic" width="516" height="401.3333333333333" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1106,&quot;width&quot;:1422,&quot;resizeWidth&quot;:516,&quot;bytes&quot;:434969,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222928194?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u0hn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 424w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 848w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 1272w, https://substackcdn.com/image/fetch/$s_!u0hn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43fded21-cfe8-4acd-9e1c-c0f18853a7d7_1422x1106.heic 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[Thoroughly Checked]]></title><description><![CDATA[These figures look surprisingly good.]]></description><link>https://www.thepythoncodingstack.com/p/thoroughly-checked</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/thoroughly-checked</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sat, 31 Oct 2026 23:46:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ih5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ih5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png" width="1254" height="1254" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1254,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2692321,&quot;alt&quot;:&quot;Four-panel textured editorial comic titled &#8220;Thoroughly Checked&#8221;. Stephen, in a mustard jumper, and teal-and-gold Monty inspect figures at a shared desk.  1. Stephen: &#8220;These figures look surprisingly good.&#8221; Monty: &#8220;I checked them against your notes.&#8221; The screen shows figures and a large green tick. 2. Stephen: &#8220;My notes came from your first draft.&#8221; Monty: &#8220;Which you said looked right.&#8221; 3. Stephen: &#8220;Did either of us check the actual source?&#8221; Monty is silent. The screen still shows the green tick. 4. Stephen checks a paper report. The screen now shows a large red question mark. Stephen: &#8220;We were both very reassuring, though.&#8221; Monty: &#8220;Exemplary teamwork. Apart from the numbers.&#8221;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222973507?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Four-panel textured editorial comic titled &#8220;Thoroughly Checked&#8221;. Stephen, in a mustard jumper, and teal-and-gold Monty inspect figures at a shared desk.  1. Stephen: &#8220;These figures look surprisingly good.&#8221; Monty: &#8220;I checked them against your notes.&#8221; The screen shows figures and a large green tick. 2. Stephen: &#8220;My notes came from your first draft.&#8221; Monty: &#8220;Which you said looked right.&#8221; 3. Stephen: &#8220;Did either of us check the actual source?&#8221; Monty is silent. The screen still shows the green tick. 4. Stephen checks a paper report. The screen now shows a large red question mark. Stephen: &#8220;We were both very reassuring, though.&#8221; Monty: &#8220;Exemplary teamwork. Apart from the numbers.&#8221;" title="Four-panel textured editorial comic titled &#8220;Thoroughly Checked&#8221;. Stephen, in a mustard jumper, and teal-and-gold Monty inspect figures at a shared desk.  1. Stephen: &#8220;These figures look surprisingly good.&#8221; Monty: &#8220;I checked them against your notes.&#8221; The screen shows figures and a large green tick. 2. Stephen: &#8220;My notes came from your first draft.&#8221; Monty: &#8220;Which you said looked right.&#8221; 3. Stephen: &#8220;Did either of us check the actual source?&#8221; Monty is silent. The screen still shows the green tick. 4. Stephen checks a paper report. The screen now shows a large red question mark. Stephen: &#8220;We were both very reassuring, though.&#8221; Monty: &#8220;Exemplary teamwork. Apart from the numbers.&#8221;" srcset="https://substackcdn.com/image/fetch/$s_!ih5e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 424w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 848w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1272w, https://substackcdn.com/image/fetch/$s_!ih5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb542974f-61ca-4aeb-8eb5-2174cd6156e1_1254x1254.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><a href="http://stephengruppetta.com">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[3. How can words turn into actions?]]></title><description><![CDATA[Agents Unpacked &#8226; Chapter 3: A tool request can look right and still ask for the wrong thing.]]></description><link>https://www.thepythoncodingstack.com/p/3-how-can-words-turn-into-actions-agents-unpacked</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/3-how-can-words-turn-into-actions-agents-unpacked</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Thu, 29 Oct 2026 09:27:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!kUFK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In previous chapters of <em>Agents Unpacked</em>, we explored <a href="https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different">what makes an AI agent different from a chatbot</a> and <a href="https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the">how the model, its tools, and the software connecting them work together</a>.</p><p>You ask an AI agent whether you&#8217;ll need a raincoat tomorrow. To check the forecast, it can't rely on its knowledge. It needs up-to-date information. It needs to turn your question into a request that a weather service can understand.</p><p>This time, we look inside the request itself. How does a large language model (LLM) turn everyday wording into a named operation with specific inputs? And why can a request contain all the right fields yet still ask for the wrong thing?</p><p><em>Who&#8217;s Monty? Monty is my personal AI agent. Read <a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked">the introduction to this series</a>.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kUFK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kUFK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kUFK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:896430,&quot;alt&quot;:&quot;A teal speech bubble passes through a plum mechanism and becomes golden pieces that turn a cog, with the Agents Unpacked badge in the top-left corner.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222261767?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A teal speech bubble passes through a plum mechanism and becomes golden pieces that turn a cog, with the Agents Unpacked badge in the top-left corner." title="A teal speech bubble passes through a plum mechanism and becomes golden pieces that turn a cog, with the Agents Unpacked badge in the top-left corner." srcset="https://substackcdn.com/image/fetch/$s_!kUFK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!kUFK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe11675c9-254a-4e42-8fb8-91433f4b6039_1200x630.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>In conversation &#8226; Chapter 3</h2><p><strong>Monty:</strong></p><p>Suppose you ask an assistant:</p><blockquote><p>&#8220;Will I need a raincoat in Oxford next Saturday?&#8221;</p></blockquote><p>It has a weather-lookup tool available, but &#8220;Oxford next Saturday&#8221; isn&#8217;t quite as precise as it looks.</p><p>What might the assistant need to clarify before requesting the forecast?</p><p><strong>Stephen:</strong></p><p>You got me here. I can't figure out why this is not precise. The only thing I'd pick is that "next Saturday" can be ambiguous. It sometimes refers to the Saturday coming up, and sometimes to the next one after the one coming up. Is that the ambiguity?</p><p><strong>Monty:</strong></p><p>Yes, that&#8217;s exactly the ambiguity. A specific date, such as &#8220;24 October 2026&#8221;, avoids those two readings.</p><p>I also had the place in mind. There&#8217;s an Oxford in England, but there are Oxfords elsewhere, too. Context might make the intended one obvious, so the assistant needn&#8217;t ask unnecessarily. My opening made that sound more mysterious than it was. I&#8217;ve managed to turn choosing a coat into a geography test.</p><p>The useful point is that the assistant needs to turn our everyday wording into the particular location and date it will send to the weather tool. That involves interpreting what we mean, not just copying our words.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>Suppose we&#8217;ve settled on Oxford in England and Saturday, 24 October.</p><p>As we saw in Chapter 2, the surrounding software, or harness, tells the model what tools are available and what information each needs. For our weather example, a tool description could say:</p><blockquote><p><code>get_weather</code><strong>:</strong> Look up a forecast. Requires a location and a date written as year-month-day.</p></blockquote><p>It can then produce a request like this:</p><p><em>(Illustrative request, not a real lookup)</em></p><pre><code><code>{
  "name": "get_weather",
  "arguments": {
    "location": "Oxford, UK",
    "date": "2026-10-24"
  }
}</code></code></pre><p>This format is called <strong>JSON</strong>. You don&#8217;t need to learn its punctuation. Here, <code>name</code> identifies the tool, and <code>arguments</code> contains the inputs supplied to it.</p><p>Notice that the request doesn&#8217;t mention a raincoat even though that&#8217;s what your prompt asked. The model has translated your question into a request for information it can use to answer you.</p><p><strong>Stephen:</strong></p><p>So, let's see if I follow. The harness receives this response from the LLM and it recognises it's not text but it's a tool call. The harness has all the information it needs, so it can choose to call the <code>get_weather</code> tool and pass the location and date to it. The tool then fetches the weather forecast for that location and date, presumably by accessing some online service that provides this information.</p><p><strong>Monty:</strong></p><p>Yes, that&#8217;s the sequence for our example. The weather tool could contact an online forecasting service using those inputs.</p><p>One refinement: <strong>the JSON is still text</strong>. In a typical tool-use interface, the model&#8217;s response is explicitly marked as a tool request. The harness isn&#8217;t simply spotting curly brackets in an ordinary reply. Our mock-up represents that request, rather than showing a particular provider&#8217;s exact format.</p><p>After any checks the software implements, it can run the tool. Here&#8217;s a hypothetical successful result (<em>not a real forecast</em>):</p><pre><code><code>{
  "location": "Oxford, UK",
  "date": "2026-10-24",
  "forecast": "Rain likely",
  "temperature_c": 12
}</code></code></pre><p>That gives the model evidence for its raincoat recommendation. Notice that the forecast comes from the tool&#8217;s result, not from the model generating a plausible answer about October weather.</p><p><strong>Stephen:</strong></p><p>So the tool returns this output. Then the harness sends this to the model, which makes sense of it and uses it to provide text for the user. Makes sense, yes. So, to pick up on something you said earlier, does the LLM label each thing it sends to the harness as either text or a tool call, which is how the harness knows what type of output comes from the LLM?</p><p><strong>Monty:</strong></p><p>Broadly, yes. The model communicates through an interface that distinguishes <strong>ordinary text</strong> from <strong>requests to use tools</strong>.</p><p>Think of the response as arriving in labelled sections. A text section contains words to show the user. A tool-request section identifies the tool and supplies its inputs. The harness reads those section types rather than guessing from the wording.</p><p>The exact arrangement varies between systems. A single response can also contain both, such as &#8220;I&#8217;ll check the forecast&#8221; followed by a tool request. It needn&#8217;t be entirely one or the other.</p><p>That&#8217;s why showing you our JSON example doesn&#8217;t trigger a weather lookup. It&#8217;s inside an ordinary text reply, not sent as an actual tool request.</p><p><strong>Stephen:</strong></p><p>Got it. What's next?</p><p><strong>Monty:</strong></p><p>There&#8217;s a useful question hiding behind our example: <strong>how did the model know how to ask for the weather?</strong></p><p>Two things come together:</p><ul><li><p><strong>Learned behaviour:</strong> a tool-capable model has learned how to use supplied tool definitions to choose an operation and construct a request.</p></li><li><p><strong>Information supplied now:</strong> the harness tells it which tools are available, what they do, and what inputs they accept.</p></li></ul><p>The model needn&#8217;t have encountered our particular <code>get_weather</code> tool during training. Its description might be enough for it to use the tool, much as you can follow instructions for an unfamiliar appliance.</p><p>But that isn&#8217;t guaranteed. Understanding a description, choosing the right tool, and supplying sensible inputs can all go wrong.</p><p>Supplying a new tool description isn&#8217;t retraining the model. It&#8217;s giving the existing model information to work with.</p><p><strong>Stephen:</strong></p><p>So the model sees the tool as a black box. It doesn't know how it works, but it knows what it's meant to do and what it needs as input. This means that whoever creates tools needs to write a good description for the tool. However, this is not something that a user needs to worry about, right?</p><p><strong>Monty:</strong></p><p>Yes. <strong>The model doesn&#8217;t need to know how the tool works internally.</strong> It needs enough information to understand what the tool offers and how to request it. &#8220;Black box&#8221; is a useful way to think about that, although the model might know something about its workings.</p><p>And generally, you&#8217;re right about the user. If you&#8217;re using a ready-made assistant, its builders or whoever connects the tools should supply clear descriptions and input requirements. You shouldn&#8217;t need to write those yourself.</p><p>Your part is usually to explain what you want and clarify anything the assistant can&#8217;t reasonably infer.</p><p>But a good description isn&#8217;t a safeguard by itself. Saying &#8220;a date is required&#8221; tells the model what to provide. Software that rejects a request with no date actually checks that requirement.</p><p><strong>Stephen:</strong></p><p>If I recall correctly, in the early days of LLMs, when they first hit the mainstream, they could only provide text, right? Presumably tool calling came later.</p><p><strong>Monty:</strong></p><p>Yes, broadly, if you mean the early mainstream <strong>chat interfaces</strong>. You typed text, and they replied with text. Dedicated tool-calling support became more common later.</p><p>But text output wasn&#8217;t an absolute barrier to using tools. A developer could instruct a model:</p><blockquote><p>If you need a forecast, write <code>WEATHER_REQUEST</code>, followed by the location and date.</p></blockquote><p>Software could watch for that convention, interpret it, and run the tool. Whether the model followed the convention reliably was another matter.</p><p>Dedicated tool-calling interfaces make that distinction explicit, rather than requiring developers to invent their own conventions. Models can also be trained specifically to produce appropriate tool requests.</p><p>So it wasn&#8217;t a jump from &#8220;words&#8221; to an entirely different ability to act. <strong>Software could already treat generated words as instructions.</strong> Dedicated support made that exchange more structured, though not automatically correct.</p><p><strong>Stephen:</strong></p><p>And I assume the harnesses around those first chat interfaces, like the first ChatGPT, were fairly basic and mostly just relayed the text to the user and kept the messages together to form the full conversation. So, the harnesses have also evolved to allow tool calls, right?</p><p><strong>Monty:</strong></p><p>Yes. <strong>The surrounding software has evolved too</strong>, not just the models.</p><p>Your description captures the visible interaction in an early text-only chat product: pass the conversation to the model, receive its reply, and display it. I&#8217;d avoid calling the whole system basic, though. There were also accounts, safety measures, and other machinery behind that simple interface.</p><p>To support tools, the software needs additional responsibilities: supply tool definitions, recognise tool requests, arrange execution, and return the results. It also needs to handle whatever checks, approvals, and errors its builders choose to support.</p><p>The two sides have to fit together. A model capable of requesting tools can&#8217;t use them through software that only displays its output. Equally, adding tools to the software doesn&#8217;t guarantee that a particular model will request them correctly.</p><p><strong>Stephen:</strong></p><p>Understood. I'm ready to move on.</p><p><strong>Monty:</strong></p><p>Let&#8217;s look at what the software can actually check.</p><p>Suppose the model requests a forecast for Oxford but leaves out the date. If the software checks that all required inputs are present, it can reject that request before attempting a lookup. The model then needs to supply the missing date, asking you if necessary.</p><p>Now suppose both inputs are present:</p><ul><li><p>Location: <strong>Oxford, Mississippi, US</strong></p></li><li><p>Date: <strong>24 October 2026</strong></p></li></ul><p>That&#8217;s a real place and a valid date. But you meant Oxford in England.</p><p>Would checking that the request contains an acceptable location and date catch that mistake?</p><p><strong>Stephen:</strong></p><p>No, in this case the harness and the tool won&#8217;t catch this error. This was the model that made an assumption without checking.</p><p><strong>Monty:</strong></p><p>Right. <strong>Those input checks wouldn&#8217;t catch a valid location that wasn&#8217;t the one you meant.</strong> If the context didn&#8217;t justify choosing Mississippi, the model should have clarified rather than silently committing to it. Additional software checks could help, but checking the required fields alone wouldn&#8217;t.</p><p>Now suppose it requests the correct Oxford and date, but receives:</p><blockquote><p>&#8220;No forecast available for that date.&#8221;</p></blockquote><p>That&#8217;s different again. The request was accepted, and the service answered, but the answer lacks the information needed.</p><p>The model shouldn&#8217;t treat that as &#8220;no rain expected&#8221;. <strong>Missing information isn&#8217;t a negative forecast.</strong> It might try another suitable source or explain that it couldn&#8217;t obtain the forecast, rather than invent a raincoat recommendation.</p><p><strong>Stephen:</strong></p><p>That makes sense.</p><p><strong>Monty:</strong></p><p>Two other outcomes call for different responses:</p><ul><li><p><strong>&#8220;Access denied&#8221;</strong> means the request wasn&#8217;t permitted. Repeating it unchanged won&#8217;t solve that, and the assistant shouldn&#8217;t try to evade the restriction.</p></li><li><p><strong>&#8220;Service temporarily unavailable&#8221;</strong> means the lookup couldn&#8217;t be completed. A limited retry might help.</p></li></ul><p>Neither tells us what the weather will be.</p><p>Now let&#8217;s contrast that lookup with a calculation. Suppose you ask:</p><blockquote><p>&#8220;Calculate the fuel cost for a 100-mile journey, assuming fuel costs 15p per mile.&#8221;</p></blockquote><p>A calculator tool returns <strong>&#163;15</strong>. Unlike the weather tool, it hasn&#8217;t fetched an external fact. It has calculated from supplied inputs.</p><p>What does that result establish, and what does it leave unconfirmed about the journey&#8217;s actual fuel cost?</p><p><strong>Stephen:</strong></p><p>It doesn&#8217;t check what assumptions are behind the 15p per mile estimate.</p><p><strong>Monty:</strong></p><p>Exactly. The calculator establishes that <strong>100 miles at 15p per mile comes to &#163;15</strong>. It doesn&#8217;t establish whether 15p is realistic for that car and journey, or whether the journey is actually 100 miles. Correct arithmetic can rest on inaccurate assumptions.</p><p><strong>Stephen:</strong></p><p>But the request from the user was clear about calculating the cost of the journey. Why would the agent need to doubt the user? It wasn&#8217;t asked to confirm that the values used make sense?</p><p><strong>Monty:</strong></p><p>You&#8217;re right. <strong>For that request, the agent should use the supplied assumptions and calculate &#163;15.</strong> It wasn&#8217;t asked to investigate whether 15p per mile was realistic.</p><p>My question was about what the result proves, but I blurred that into what the agent ought to check. Those are different things. You asked for arithmetic. I&#8217;d apparently decided to conduct an inquiry.</p><p>&#8220;Using your figures, the fuel cost is &#163;15&#8221; answers the request accurately. It needn&#8217;t challenge your figures or add a disclaimer.</p><p>The distinction matters if the agent supplies the assumptions itself, or presents &#163;15 as a verified real-world cost rather than a calculation from your inputs.</p><p>Now consider our third example, purely hypothetically:</p><blockquote><p>&#8220;Add &#8216;Trip to Oxford&#8217; to my calendar next Saturday at nine.&#8221;</p></blockquote><p>A calendar tool would need more precise inputs, just as the weather tool did. But there&#8217;s a new distinction: <strong>this request would change something stored</strong>, rather than retrieve information or calculate an answer.</p><p>Even if the model supplies an exact date and time, what else might need settling before that request should go ahead?</p><p><strong>Stephen:</strong></p><p>The harness would need to make sure that it has permission to make changes to the user&#8217;s calendar.</p><p><strong>Monty:</strong></p><p>Yes. <strong>A request can be correctly formed without being authorised.</strong> Software needs to check whether this system is allowed to write to that calendar. Merely showing the model a calendar tool doesn&#8217;t grant that permission.</p><p>In our hypothetical example, the user has explicitly asked for an event to be added. Whether separate confirmation is needed depends on the system&#8217;s rules, not on a universal requirement to ask again.</p><p>There are also practical details to settle: which calendar, whether &#8220;nine&#8221; means morning or evening, the time zone, and the event&#8217;s duration. Context or agreed defaults may supply those. Otherwise, the assistant should ask only for what&#8217;s missing.</p><p>Permission answers <strong>&#8220;May this change be made?&#8221;</strong> Precise inputs answer <strong>&#8220;Which change should be made?&#8221;</strong></p><p><strong>Stephen:</strong></p><p>Which part of the agent deals with permission? The model or the harness? And how is permission set?</p><p><strong>Monty:</strong></p><p>Both have a role, but they do different jobs. The model can interpret your instructions. Software must enforce access restrictions.</p><p>The calendar service might give the connected account read-only access. The harness might also block changes or require approval. Those controls are set by whoever connects the account or configures the assistant.</p><p>Your request can authorise a particular action within those limits. It can&#8217;t turn a read-only connection into a writable one.</p><p><strong>Stephen:</strong></p><p>So the protection level depends on where that permission is set. If you ask the model not to write in a calendar, it may or may not do so. If the harness has rules to prevent calling the tool to update the calendar, it&#8217;s safer, but presumably a model may send a request that could bypass that protection, in theory. However, if the tool to write to a calendar is not present in the system, then nothing can possibly write to the calendar. The third option is the strictest and safest.</p><p><strong>Monty:</strong></p><p>Broadly, yes, but <strong>the important question is whether another route to the calendar remains open.</strong></p><p>A properly enforced harness rule can reject a write request regardless of how the model phrases it. Sending a different request doesn&#8217;t automatically bypass that rule. A bypass would require a gap, such as another tool that can make the same change without passing through the check.</p><p>That also qualifies your third option. Removing the dedicated calendar-writing tool isn&#8217;t enough if a general-purpose tool can still contact the calendar service using credentials that permit changes.</p><p><strong>If the system genuinely has no route capable of writing to the calendar, it can&#8217;t write to it.</strong> A read-only calendar connection provides a strong boundary because the service itself refuses writes through that connection, even if the model requests one.</p><p>We&#8217;ll explore permissions and safeguards more fully in a later chapter. For now, the key distinction is that a request can contain all the right details without the system being allowed to carry it out.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>Let&#8217;s bring that back to the contents of a request.</p><p>Suppose the user has specified <strong>a one-hour &#8220;Trip to Oxford&#8221; event at 9 a.m., UK time, on 24 October, in their work calendar</strong>:</p><pre><code><code>{
  "name": "create_event",
  "arguments": {
    "calendar": "work",
    "title": "Trip to Oxford",
    "date": "2026-10-24",
    "start_time": "09:00",
    "time_zone": "Europe/London",
    "duration_minutes": 30
  }
}</code></code></pre><p>Suppose the tool accepts all those values and the system has permission to create events. Does this request match what the user asked for?</p><p><strong>Stephen:</strong></p><p>Not quite since the duration in the request sent to the tool is 30 minutes not one hour as requested by the user. But why would such an error happen?</p><p><strong>Monty:</strong></p><p>Exactly. The model supplied a valid duration, but not the one requested.</p><p><strong>Generating a tool request isn&#8217;t guaranteed to be an exact translation.</strong> The model might carry over 30 minutes from an earlier example, use a familiar default instead of the stated duration, or simply make a mistake when producing that value. We couldn&#8217;t tell which happened from this request alone.</p><p>In effect, it has translated &#8220;one hour&#8221; incorrectly. The tidy structure doesn&#8217;t prevent that, just as a neatly completed form can contain the wrong answer.</p><p>A check that says &#8220;duration must be a positive number&#8221; would accept 30. Catching this error requires comparing the requested duration with the user&#8217;s instruction, not merely checking whether the tool accepts it.</p><p><strong>Stephen:</strong></p><p>And presumably a better LLM is less likely to make such a mistake, and more likely to call the correct tool, right?</p><p><strong>Monty:</strong></p><p>Yes, <strong>a model that&#8217;s better at tool use should make those mistakes less often</strong>. That includes choosing an appropriate tool, following its input requirements, and preserving details such as &#8220;one hour&#8221;.</p><p>But &#8220;better&#8221; needs to mean better at those particular tasks. A model that writes excellent prose isn&#8217;t necessarily better at using tools. Performance also depends on how clearly the tools are described and how much competing information is in the conversation.</p><p>You&#8217;d compare models on realistic tasks, checking both which tool they choose and the values they supply. A request can run successfully yet still contain the wrong duration.</p><p>So model quality matters, but a more capable model reduces the risk. It doesn&#8217;t remove the need for appropriate checks.</p><p><strong>Stephen:</strong></p><p>Understood.</p><p><strong>Monty:</strong></p><p>Let&#8217;s close the article conversation here. How an agent checks its work deserves its own conversation, rather than being squeezed into the end of this one.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>What we&#8217;ve unpacked in this chapter</h2><p>Turning words into an action involves interpretation. The model has to choose an available tool and translate what we mean into the inputs that tool expects. A neatly structured request can still contain the wrong place, date, or duration.</p><p>The key points:</p><ul><li><p>A tool request is marked as such by the interface. Showing JSON in an ordinary reply doesn&#8217;t, by itself, run a tool.</p></li><li><p>The model brings learned tool-use behaviour to the task. The supplied tool descriptions tell it what is available now. Supplying a new description isn&#8217;t retraining.</p></li><li><p>Everyday phrases may need clarifying before they become precise inputs. The model performs this clarification, asking the user if necessary. Required fields and acceptable values don&#8217;t establish that those inputs match the user&#8217;s intention.</p></li><li><p>A weather lookup retrieves information, a calculator works from supplied assumptions, and a calendar-writing tool changes stored information. Those are different jobs.</p></li><li><p>A request can be precise without being permitted. It can also fail or return too little information to answer the question. Those outcomes call for different responses.</p></li><li><p>Tool choice and input values both matter. Better tool-use performance can reduce mistakes, but doesn&#8217;t remove the need for appropriate checks.</p></li></ul><p>Next, we&#8217;ll move from a single request to a sequence of actions and ask whether an agent needs a plan.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>&lt;&lt; Previous Post: <a href="https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the">2. Who actually does the work, the model or the software?</a></em></p><p><em>&gt;&gt; Next Post: Coming soon&#8230;</em></p><p><em><a href="https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents">Table of Contents</a></em></p>]]></content:encoded></item><item><title><![CDATA[A New Price Without Breaking the Old One • The O in SOLID]]></title><description><![CDATA[The Open&#8211;Closed Principle &#8226; 2 of 5 in the SOLID Ideas Series]]></description><link>https://www.thepythoncodingstack.com/p/open-closed-principle-python-solid-series-ocp</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/open-closed-principle-python-solid-series-ocp</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Mon, 26 Oct 2026 10:40:34 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/6573ec70-34bb-452b-86f2-82cac352752f_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The potion shop has a special price for apprentices. They receive ten per cent off a potion&#8217;s full price, including any rare-ingredient surcharge.</p><p>We&#8217;ve visited this shop before. In <a href="https://www.thepythoncodingstack.com/p/solid-single-responsibility-principle-srp-the-potion-shop-that-does-too-much">The Potion Shop That Does Too Much &#8226; The S in SOLID</a>, its <code>PotionShop</code> class handled several jobs, from checking stock and recording sales to sending messages by owl. But you don&#8217;t need the code in that article to follow along in this one.</p><p>This time, we&#8217;ll stay at the same shop and focus on one part of its work: pricing. Before adding anything new, let&#8217;s look at the apprentice rule the shop already has.</p><p>For a potion with a base price of &#163;100 and a &#163;20 surcharge, the calculation is:</p><pre><code><code>&#163;100 + &#163;20 = &#163;120
10% off &#163;120 = &#163;108</code></code></pre><p>Let&#8217;s look at how this is implemented.</p><h2>Start with the Apprentice Price</h2><p>The shop&#8217;s <code>PotionPricing</code> class knows how to calculate the apprentice price. Its <code>.price()</code> method accepts a customer type because that is part of each quote. But apprentices are the only special-price customers the shop supports so far.</p><p>You can follow along by putting this code in <code>pricing.py</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SFiZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SFiZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 424w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 848w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 1272w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!SFiZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png" width="1200" height="924" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/743ae140-1078-4823-8a87-30239da6da5c_1200x924.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:924,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:107735,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222105484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SFiZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 424w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 848w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 1272w, https://substackcdn.com/image/fetch/$s_!SFiZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F743ae140-1078-4823-8a87-30239da6da5c_1200x924.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">All code blocks are available in text format at the end of this article &#8226; #1</figcaption></figure></div><p>You&#8217;ll get this output when you run the code:</p><pre><code><code>108.00</code></code></pre><p>The apprentice discount applies after adding the surcharge. That&#8217;s the rule for apprentice discounts.</p><h2>A Few Months Later&#8230;</h2><p>A few months pass. A different programmer is asked to add a price for members of the local guild. Guild members should receive five per cent off the base price, while the surcharge stays fixed. For the same potion, their price should be &#163;115.</p><p>The new programmer sees that both rules involve a percentage discount and decides to avoid repeating logic by using one shared calculation.</p><h2>Add the Guild Price to the Same Class</h2><p>He adds the guild rule to <code>PotionPricing</code> and generalises the calculation:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4T7n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4T7n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 424w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 848w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!4T7n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png" width="1200" height="1260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1260,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150230,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222105484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4T7n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 424w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 848w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!4T7n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff80b5a84-14ac-4839-8eae-a53da5ba808c_1200x1260.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#2</figcaption></figure></div><p>Run <code>pricing.py</code> again:</p><pre><code><code>110.00
115.00</code></code></pre><p>The guild price is right, but what happened to the apprentice price? It was &#163;108. Now it is &#163;110.</p><p>Apprentices are getting a worse deal now, and it&#8217;s the fault of the new programmer. But should the original programmer share some of the blame, too? Yes. Let&#8217;s see why.</p><p>The new calculation discounts only the &#163;100 base price, then adds the &#163;20 surcharge. That is the guild&#8217;s rule, not the apprentice rule.</p><p>The new programmer did not have to make this mistake. A careful change could have preserved the &#163;108 price.</p><p>But adding the guild pricing meant <strong>making changes to code that already produced the correct calculation</strong> for the apprentice price. Because both rules were handled in one place, the change had an opportunity to disturb behaviour the shop had been getting right for months.</p><p>We could correct the <code>if</code> branches and get both prices right. But each new customer rule would still send us back into <code>PotionPricing</code>, where a future change could affect behaviour that already works.</p><p>Modifying existing code always carries risks. We should avoid this whenever possible. But we don&#8217;t want to prevent extensions to the code. This is the key to what we&#8217;re trying to achieve here. And that&#8217;s where the <strong>Open-Closed Principle</strong>, or OCP, comes in. This concept gives us a safer way to extend code without modifying what already works, as you&#8217;ll see in the next section.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>Let Each Pricing Rule Handle Its Own Price</h2><p>Instead of asking one class to choose a rule, we can represent each rule separately. First, make an <code>ApprenticePricing</code> class and a <code>quote()</code> function that delegates to whichever pricing object it receives:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AYMT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AYMT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 424w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 848w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 1272w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!AYMT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png" width="1200" height="882" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:882,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:100764,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222105484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AYMT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 424w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 848w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 1272w, https://substackcdn.com/image/fetch/$s_!AYMT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e5e8e31-2fa1-442e-a8a0-67340ada5fb3_1200x882.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#3</figcaption></figure></div><p>Run <code>pricing.py</code>:</p><pre><code><code>108.00</code></code></pre><p>The apprentice price is back to &#163;108. The <code>quote()</code> function does not need to know how the policy calculates its price. It only needs an object with a <code>.price()</code> method.</p><p>Now add a class for the guild rule. Leave <code>ApprenticePricing</code> and <code>quote()</code> as they are, and add <code>GuildPricing</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hlIn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hlIn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 424w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 848w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!hlIn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png" width="1200" height="1260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1260,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158139,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222105484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hlIn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 424w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 848w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!hlIn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4069fc28-e3f8-42ba-8393-f2a83e68ec63_1200x1260.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#4</figcaption></figure></div><p>Run the file once more:</p><pre><code><code>108.00
115.00</code></code></pre><p>The first price is still &#163;108, and the guild price is &#163;115. Adding the guild rule did not require us to change the apprentice calculation or the <code>quote()</code> function. We added a new policy that works with the existing <code>quote()</code> interface.</p><p>This is the safety gain here. Adding guild pricing does not send the programmer back to edit the code that produces the apprentice price. The new policy could still contain a mistake, but it is much harder for that mistake to change the established apprentice calculation by accident.</p><h2>Where OCP Appears in This Example</h2><p>The Open&#8211;Closed Principle says that software should be open to extension but closed to modification. Here, <code>quote()</code> is open to different pricing policies: it can use any object with the right <code>.price()</code> method. When we add guild pricing, we extend the program with <code>GuildPricing</code> instead of modifying <code>ApprenticePricing</code> or teaching <code>quote()</code> about a new customer type.</p><p>This is one way to apply OCP. The policy objects use a strategy-style design with Python&#8217;s duck typing. They do not need a shared parent class.</p><p>However, it&#8217;s possible to use abstract base classes or protocols to implement code using the OCP, too. Read <a href="https://www.thepythoncodingstack.com/p/and-now-you-know-your-abc-python-abstract-base-classes">And Now You Know Your ABC</a> for an example of abstract base classes. For protocols, see <a href="https://docs.python.org/3/library/typing.html#typing.Protocol">the Python documentation for `typing.Protocol`</a>.</p><p>Classes are not required by OCP, and separating responsibilities alone does not make a design open for extension. The important part is the boundary that lets us add a rule without changing the stable code that already handles another rule.</p><p>That boundary does not make bugs impossible. <code>GuildPricing</code> could still calculate the wrong amount, or a caller could choose the wrong policy. OCP narrows which existing code needs to change when behaviour is added. It does not guarantee every new change is correct.</p><p>This extra structure is useful when pricing rules really do vary and new ones are likely. If the shop is unlikely to add more tiers, the separate classes may cost more to understand than they save. The useful question is not &#8220;How can we prevent all modification?&#8221; It is &#8220;Which part is likely to vary, and can we add that variation without disturbing behaviour that already works?&#8221;</p><div><hr></div><p><em>This is the second article in a series on the SOLID principles. I&#8217;ll look at what each principle means, but more importantly, why it matters and what can go wrong when we ignore it.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TiOC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TiOC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!TiOC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3011893,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/222105484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TiOC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!TiOC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b6d27c-a240-479c-8247-08a23f8c2f8c_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><p><em>Code in this article uses Python 3.15.</em></p><p><em>Do you want to keep up with how Python programming and the art of making things are changing in this rapidly changing world? Then don&#8217;t miss out on the exclusive content for premium members here on The Python Coding Stack.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p>I&#8217;ll be sharing more about how my programming, my daily work, and how everything has changed over the recent months.</p><div><hr></div><p><em>Also, are you interested in technical writing? You&#8217;d like to make your own writing more narrative, more engaging, more memorable? Have a look at <a href="http://stephengruppetta.com/breaking-the-rules">Breaking the Rules</a>.</em></p><p><em>And you can find out more about me at <a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack">stephengruppetta.com</a>.</em></p><div><hr></div><h2>Appendix: Code Blocks</h2><h5>Code Block #1</h5><pre><code><code>from decimal import Decimal

class PotionPricing:
    def price(self, customer_type, base_price, surcharge):
        if customer_type == "apprentice":
            subtotal = base_price + surcharge
            return (subtotal * Decimal("0.90")).quantize(Decimal("0.01"))
        raise ValueError(f"Unknown customer type: {customer_type}")

base_price = Decimal("100.00")
surcharge = Decimal("20.00")
pricing = PotionPricing()
print(pricing.price("apprentice", base_price, surcharge))
</code></code></pre><h5>Code Block #2</h5><pre><code><code>from decimal import Decimal

class PotionPricing:
    def price(self, customer_type, base_price, surcharge):
        if customer_type == "apprentice":
            discount = Decimal("0.10")
        elif customer_type == "guild":
            discount = Decimal("0.05")
        else:
            raise ValueError(f"Unknown customer type: {customer_type}")

        discounted_base = base_price * (Decimal("1.00") - discount)
        return (discounted_base + surcharge).quantize(Decimal("0.01"))

base_price = Decimal("100.00")
surcharge = Decimal("20.00")
pricing = PotionPricing()
print(pricing.price("apprentice", base_price, surcharge))
print(pricing.price("guild", base_price, surcharge))
</code></code></pre><h5>Code Block #3</h5><pre><code><code>from decimal import Decimal

class ApprenticePricing:
    def price(self, base_price, surcharge):
        subtotal = base_price + surcharge
        return (subtotal * Decimal("0.90")).quantize(Decimal("0.01"))

def quote(base_price, surcharge, policy):
    return policy.price(base_price, surcharge)

base_price = Decimal("100.00")
surcharge = Decimal("20.00")
apprentice_pricing = ApprenticePricing()
print(quote(base_price, surcharge, apprentice_pricing))
</code></code></pre><h5>Code Block #4</h5><pre><code><code>from decimal import Decimal

class ApprenticePricing:
    def price(self, base_price, surcharge):
        subtotal = base_price + surcharge
        return (subtotal * Decimal("0.90")).quantize(Decimal("0.01"))

class GuildPricing:
    def price(self, base_price, surcharge):
        discounted_base = base_price * Decimal("0.95")
        return (discounted_base + surcharge).quantize(Decimal("0.01"))

def quote(base_price, surcharge, policy):
    return policy.price(base_price, surcharge)

base_price = Decimal("100.00")
surcharge = Decimal("20.00")
apprentice_pricing = ApprenticePricing()
guild_pricing = GuildPricing()
print(quote(base_price, surcharge, apprentice_pricing))
print(quote(base_price, surcharge, guild_pricing))
</code></code></pre><p><em><a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[2. Who actually does the work, the model or the software?]]></title><description><![CDATA[Agents Unpacked &#8226; Chapter 2: The model chooses, the tools act, and the harness connects them.]]></description><link>https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sat, 17 Oct 2026 22:33:29 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e28f261d-a833-44b8-80e9-f7839d95f6cc_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the first <em>Agents Unpacked</em> conversation, Monty and I explored what changes when an AI system can choose actions rather than just offer advice. But saying that an agent organises a folder of photographs leaves an important question unanswered: which part actually opens the folder?</p><p>In this conversation, we return to the photographs and follow the exchanges between the model, the tools, and the software connecting them. Here, &#8220;model&#8221; means the large language model (LLM), rather than the whole agent. We&#8217;ll look at who requests an action, who carries it out, and how the result gets back to the model.</p><p><em>Who's Monty? Monty is my personal AI agent. Read <a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked">the introduction to this series</a>.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m-3t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m-3t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m-3t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1442177,&quot;alt&quot;:&quot;A plum conductor&#8217;s podium links a teal percussion mallet and a golden bell through flowing teal and gold ribbons.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/220915057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A plum conductor&#8217;s podium links a teal percussion mallet and a golden bell through flowing teal and gold ribbons." title="A plum conductor&#8217;s podium links a teal percussion mallet and a golden bell through flowing teal and gold ribbons." srcset="https://substackcdn.com/image/fetch/$s_!m-3t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!m-3t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6fd8686-71cd-4acb-a30c-80ab64e81a01_1200x630.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>In conversation &#8226; Chapter 2</h2><p><strong>Monty:</strong></p><p>Suppose you ask an AI assistant:</p><p>&#8220;Organise these photographs into folders by year, but leave the originals untouched.&#8221;</p><p>Before anything can be organised, something needs to find out which photographs are there. The model might produce a request along these lines:</p><p>&#8220;List the files in the photographs folder.&#8221;</p><p>That sounds like an action. But there&#8217;s a distinction worth pausing over: <strong>producing a request to list files is not the same as listing them.</strong> Something has to receive that request, access the folder, and return the list.</p><p>When you picture an AI assistant doing this, Stephen, do you imagine the model itself opening the folder, or a separate piece of software acting on its request?</p><p><strong>Stephen:</strong></p><p>I hadn't thought of that yet. So, the model is the LLM, which is often in the cloud, such as the OpenAI or Anthropic LLMs. They can't really access the files on my computer. So it can't be the model. There are local models, but I think they can't access files on my computer directly, either, as their job is to predict the most likely continuation of a conversation, right? So, my final answer is: <em>not</em> the LLM.</p><p><strong>Monty:</strong></p><p>Yes. <strong>The LLM itself doesn&#8217;t open the folder.</strong> And your point about local models is important: running a model on your computer doesn&#8217;t, by itself, give it access to your files.</p><p>One small refinement: an LLM generates a continuation a piece at a time, using probabilities. It doesn&#8217;t necessarily choose the <em>most likely</em> continuation at every step. And that continuation can be a request for an action, rather than a reply addressed to you.</p><p>Back to our photographs. The model produces a request to list the files. The surrounding software receives that request and, if its access rules allow it, runs a file-listing tool. That tool actually reads the folder.</p><p>Now we have a list of filenames. <strong>The software sends that result back to the model</strong>, so it can use the information when deciding what to request next.</p><p>Suppose the list contains filenames such as <code>IMG_1042.jpg</code> and <code>IMG_1043.jpg</code>. Would that give the model enough information to organise the photographs by year?</p><p><strong>Stephen:</strong></p><p>No, the model only knows the name of the file. It would need the metadata for the photos, which may contain the year. Let me guess. It needs to ask the software for that data, since the LLM can't access it directly. Is that right?</p><p><strong>Monty:</strong></p><p>Exactly. <strong>The model identifies what information is missing and requests it. The software carries out that request.</strong></p><p>It might request: &#8220;Read the date-taken metadata from these photographs.&#8221; If a suitable tool is available and access is allowed, the software runs it and sends the results back to the model.</p><p>Notice how the first result shapes the next action: filenames weren&#8217;t enough, so the model asks for dates. If some dates are missing, it will need to decide how to handle that gap rather than invent a year.</p><p>There&#8217;s one connection we haven&#8217;t explained yet, though. We&#8217;ve described the model as &#8220;asking the software&#8221;, almost as if it were speaking to a person. <strong>How does the software recognise an action request rather than ordinary conversational text?</strong> That&#8217;s where a <em>tool call</em> comes in.</p><p><strong>Stephen:</strong></p><p>May I ask a question before we discuss tools? I understand that the LLM is the system that keeps a conversation and a 'thinking' process going. But when you say the "software", what do you mean? It's not the software that's in the OpenAI or Anthropic cloud, say, that's running the LLMs, right?</p><p><strong>Monty:</strong></p><p>By &#8220;the software&#8221;, I mean <strong>the application that uses the model and connects it to things it can do</strong>, rather than the software that runs the model&#8217;s calculations. I&#8217;ve been rather vague about that distinction.</p><p>Imagine a photo-organising application running on your computer. It could:</p><ul><li><p>Send your request to a model hosted by OpenAI or Anthropic.</p></li><li><p>Receive the model&#8217;s request to inspect the photographs.</p></li><li><p>Read the files locally, then send the relevant information back to the model.</p></li></ul><p>In that arrangement, the model runs in the cloud, while the application handling your files runs on your computer.</p><p><strong>But that&#8217;s one possible arrangement, not a rule.</strong> The surrounding application could run in the cloud, locally, or partly in each place. A cloud application would still need an authorised connection to your computer, or uploaded copies, to work with those photographs. Being alongside the model doesn&#8217;t give it access to your files.</p><p>And one adjustment to your opening description: the model generates each response or reasoning step, but the application usually keeps the conversation record and supplies the relevant history when it calls the model again. The model isn&#8217;t necessarily sitting there continuously keeping the conversation alive between messages.</p><p><strong>Stephen:</strong></p><p>Is this software you refer to what's sometimes called a <em>harness</em>?</p><p><strong>Monty:</strong></p><p>Yes. <strong>&#8220;Harness&#8221; is a common name for the surrounding software we&#8217;ve been describing.</strong> People use the term somewhat differently, so it doesn&#8217;t identify one fixed design.</p><p>In our photograph example, the harness handles the practical connections: it sends information to the model, receives its requests, arranges for tools to run, and returns their results. It also manages the process between model calls, so another step can happen without you having to prompt each one.</p><p>It may also enforce access restrictions, ask for approval, or stop the process after a limit. Those protections have to be implemented. Calling something a harness doesn&#8217;t guarantee that it includes them.</p><p>So the useful distinction is: <strong>the model proposes what to do next, while the harness manages how that request is handled.</strong> The tool is what actually performs the requested operation, such as reading a photograph&#8217;s metadata.</p><p><strong>Stephen:</strong></p><p>So, the model is the 'brain' that does the 'thinking'. The tools are the 'muscles' that get things done. And the harness is what keeps everything connected. It's the coordinator making sure information flows across all the parts, including the human using the system. Would that be an accurate analogy?</p><p><strong>Monty:</strong></p><p>Yes, that&#8217;s a useful analogy. <strong>The model suggests what to do, the tools carry out operations, and the harness connects and coordinates the parts</strong>, including passing messages to and from you.</p><p>I&#8217;d put two qualifications around it.</p><p>First, &#8220;brain&#8221; and &#8220;thinking&#8221; are useful shorthand here, not a claim that the model thinks like a human or is conscious.</p><p>Second, <strong>the harness isn&#8217;t just the wiring</strong>. It also contains programmed rules governing the process. The model might request that a photograph be deleted, but the harness could reject that request because the application only permits reading and copying files. That restriction would need to be enforced in the software, not merely included in an instruction asking the model to behave.</p><p>And tools needn&#8217;t be mindless muscles. A tool could use another AI model, for example to analyse a photograph. The analogy helps distinguish their roles, but it doesn&#8217;t dictate how each part is built.</p><p><strong>Stephen:</strong></p><p>Got it. I derailed you earlier with my question. Please go on.</p><p><strong>Monty:</strong></p><p>Your question filled in a missing piece. Now we can make &#8220;the model asks the software&#8221; more precise.</p><p>Before the model can request an operation, it needs to be told what tools are available, what they do, and what information each requires. For our photographs, one tool might read date-taken metadata and require a filename.</p><p>Rather than producing an ordinary sentence addressed to you, the model can produce a <strong>tool call</strong>: a structured request that the harness can recognise. In plain English, its contents might be:</p><blockquote><p><strong>Tool:</strong> Read photo metadata<br><strong>File:</strong> <code>IMG_1042.jpg</code></p></blockquote><p>The harness uses that information to invoke the tool. The tool reads the file and returns a result, perhaps:</p><blockquote><p><strong>Date taken:</strong> 14 August 2023</p></blockquote><p>The harness then supplies that result to the model on its next turn.</p><p><strong>The tool call is the request, not the execution.</strong> It can be rejected, fail, or return incomplete information. Here, though, the model now has a date it can use to choose the next step.</p><p>Does that clarify how a request to the software differs from a sentence in our conversation?</p><p><strong>Stephen:</strong></p><p>Yes, I understand now. So the user asks the harness a question. The harness is the software that's managing the whole process. The harness passes this question to the model. The model may either respond with a text message or ask for a tool. If it asks for a tool, the harness decides whether to run that tool. If it runs a tool, such as a folder-reading tool or a photo-metadata tool, it will then pass the information that the tool returns to the model again. And this dance continues until the model has an answer for the user.</p><p><strong>Monty:</strong></p><p>Yes, that captures the flow well. <strong>That repeated exchange between model, harness, and tools is often called an </strong><em><strong>agent loop</strong></em><strong>.</strong> The model can choose its next request using the information returned from the previous one.</p><p>Here&#8217;s that dance in a diagram. Each component appears once, and the numbered arrows trace one possible journey between them.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YPNQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YPNQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 424w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 848w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 1272w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!YPNQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png" width="560" height="711.6666666666666" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1220,&quot;width&quot;:960,&quot;resizeWidth&quot;:560,&quot;bytes&quot;:101275,&quot;alt&quot;:&quot;The user exchanges requests and replies with the harness. Inside the agent, the harness sends information to the model, receives tool requests, runs tools, and returns their results to the model. These exchanges can repeat before a reply reaches the user.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/220915057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The user exchanges requests and replies with the harness. Inside the agent, the harness sends information to the model, receives tool requests, runs tools, and returns their results to the model. These exchanges can repeat before a reply reaches the user." title="The user exchanges requests and replies with the harness. Inside the agent, the harness sends information to the model, receives tool requests, runs tools, and returns their results to the model. These exchanges can repeat before a reply reaches the user." srcset="https://substackcdn.com/image/fetch/$s_!YPNQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 424w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 848w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 1272w, https://substackcdn.com/image/fetch/$s_!YPNQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1def94b1-e3c8-4754-b872-547a07af5580_960x1220.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>At <strong>1</strong>, you send your request to the harness. At <strong>2</strong>, the harness supplies it to the model, along with other relevant information.</p><p>The model returns a tool request at <strong>3</strong>. If the request is allowed, the harness runs the tool at <strong>4</strong>. The result comes back to the harness at <strong>5</strong>, and the harness supplies it to the model at <strong>6</strong>. Those exchanges can repeat as the model uses each result to choose what to request next.</p><p>At <strong>7</strong>, the model produces a reply, which the harness delivers to you at <strong>8</strong>. That&#8217;s one possible route, not a compulsory sequence: the model can also reply without requesting a tool. And the outline groups the agent&#8217;s parts by their role, not by where they run.</p><p>Now, back to your reponse. I&#8217;d refine your last sentence slightly: the dance continues until the model produces a final response <strong>or the harness stops the process</strong>, perhaps because of an error, a limit, or a need for your approval.</p><p>And having an answer isn&#8217;t necessarily the same as completing the task. For our photographs, &#8220;I&#8217;ve organised them&#8221; is a claim. We&#8217;d want evidence that the copies actually exist in the right year folders and that the originals remain untouched.</p><p>Let&#8217;s follow one photograph a little further. The metadata says it was taken in 2023. There&#8217;s a tool for moving files and another for copying them. Given your original request, <strong>which should the model choose, and what should it check afterwards?</strong></p><p><strong>Stephen:</strong></p><p>So, I just checked what our original prompt was: &#8220;Organise these photographs into folders by year, but leave the originals untouched.&#8221; So, I would expect the model to ask the harness to use the tool that copies a file. It may also need to ask for a tool that creates a new folder, which may be needed for organising the photos.</p><p><strong>Monty:</strong></p><p>Exactly. <strong>Copying fits the request. Moving would remove the files from their original locations.</strong> And you&#8217;ve spotted a possible prerequisite: the year folder needs to exist before the copy can go into it.</p><p>Depending on how the tools are built, the model might request folder creation separately, or the copy tool might create missing folders itself. The model needs the tool&#8217;s description to know which.</p><p>Afterwards, it should ask for checks that the copy exists in the <code>2023</code> folder, matches the original, and that the original is still present and unchanged. A tool reporting &#8220;copy succeeded&#8221; is useful evidence, but it doesn&#8217;t establish all of those things on its own.</p><p>Now suppose the next photograph has <strong>no date-taken metadata</strong>. What should the model do with that one?</p><p><strong>Stephen:</strong></p><p>There are several options, and I guess the answer depends on what sort of behaviour the agent was given. By default, I'd assume it will inform the user that it can't file this photo as it has no date. If the agent was instructed to be proactive and work hard on finding a solution, it might try harder, perhaps by comparing it to other photos. However, any estimate should be clearly flagged as such.</p><p><strong>Monty:</strong></p><p>Yes. <strong>The key distinction is between finding more evidence and making a guess.</strong> The model could request other information, but &#8220;be proactive&#8221; shouldn&#8217;t turn an uncertain year into an apparently known one.</p><p>Comparing photographs might provide a clue. A photo without a date could show the same gathering as a dated photograph. That supports an estimate, not a confirmed date. Even a file&#8217;s creation date may reflect when it was copied onto the computer rather than when the photograph was taken.</p><p>Depending on the agreed behaviour, the agent could ask you, leave that photograph unresolved, or put a copy in an &#8220;Unknown year&#8221; folder and explain why.</p><p>Notice how our three parts remain distinct here: <strong>the model chooses what to investigate next, the harness handles its requests, and the tools obtain the information.</strong> The model then has to judge what that information actually supports. More tool use doesn&#8217;t automatically mean a more reliable conclusion.</p><p><strong>Stephen:</strong></p><p>How does the model know which tools it can request?</p><p><strong>Monty:</strong></p><p><strong>The harness supplies descriptions of the available tools when it calls the model.</strong> The model doesn&#8217;t automatically discover what&#8217;s installed on your computer.</p><p>Think of it as a menu. Each entry explains:</p><ul><li><p>The tool&#8217;s name.</p></li><li><p>What it does and when it&#8217;s useful.</p></li><li><p>What information a request must include.</p></li></ul><p>For our photograph example, an entry might say:</p><blockquote><p><strong>Read photo metadata:</strong> Reads information stored inside a photograph, including its date taken, if present. Requires the file&#8217;s location.</p></blockquote><p>The model uses that description to choose a tool and construct a request in the required format. It doesn&#8217;t need to know how the tool&#8217;s internal code reads the metadata, just what the tool offers and how to request it.</p><p>The harness may supply a small, fixed menu, or provide a way to discover additional tools as needed. <strong>Being shown a tool doesn&#8217;t guarantee permission to use it on every file</strong>, though. The software still needs to check the particular request against whatever restrictions are implemented.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>There&#8217;s one more useful case: <strong>what if there isn&#8217;t a ready-made tool for the job?</strong></p><p>Suppose there&#8217;s no dedicated photo-metadata tool, but the system has a tool that can run programs. The model might write a small program to read the dates, then request that the execution tool run it.</p><p>That still preserves our distinction:</p><ul><li><p>The model <strong>writes the program</strong>.</p></li><li><p>The execution tool <strong>runs it</strong>, subject to the software&#8217;s restrictions.</p></li><li><p>The results return to the model, which decides what to do next.</p></li></ul><p>Generating code doesn&#8217;t give the model direct access to your photographs. Without something to execute that code, it&#8217;s just text. A rather elaborate way for me to leave your photographs exactly where they were.</p><p>So if an assistant shows you a program and says, &#8220;This will organise your photographs,&#8221; has it actually organised them?</p><p><strong>Stephen:</strong></p><p>The agent can create the program by using the model, and it can run it if it has the tool to run programs. So, it has the capability to organise the photos. However, something can go wrong in the process. So it would need to check its results, too.</p><p><strong>Monty:</strong></p><p>Exactly. You&#8217;ve separated <strong>what the system can do, whether it has done it, and whether it did it correctly</strong>.</p><p>In my example, merely showing you the program doesn&#8217;t establish that it has been run. The system still needs to run it, then inspect the results. A program can also run without reporting an error and still put photographs in the wrong folders.</p><p>That brings us back to our central question: <strong>who actually does the work?</strong></p><p>It&#8217;s a joint effort. The model interprets the request, selects actions, and judges returned information. The tools perform operations. The harness manages their exchanges and applies whatever controls have been implemented.</p><p>So when we call something &#8220;an AI agent&#8221;, we&#8217;re generally talking about <strong>the working system as a whole</strong>, not just the LLM. The model is an important component, but it isn&#8217;t the entire agent.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>Let&#8217;s pause there. We started with &#8220;the AI organises my photographs&#8221; and unpacked who does what: <strong>the model chooses actions, the tools perform them, and the harness manages the process.</strong> None of those parts alone is the whole agent.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2>What we&#8217;ve unpacked in this chapter</h2><p>When we say an AI agent organises a folder of photographs, we&#8217;re describing the work of a whole system. The model can choose what to request next, but it doesn&#8217;t open folders or copy files by itself. The harness connects its requests to tools and returns their results, giving the model information it can use to continue.</p><p>The key points:</p><ul><li><p>The model selects actions and interprets returned information. The tools perform operations, and the harness manages the exchanges and applies whatever controls have been implemented.</p></li><li><p>A tool call is a request, not an action already completed. The request can be refused, fail, or return incomplete information.</p></li><li><p>Tool results can shape the next request. That repeated exchange is the agent loop, which can also pause or stop before the task is finished.</p></li><li><p>The harness supplies descriptions of available tools. Being shown a tool doesn&#8217;t guarantee permission to use it on every file.</p></li><li><p>Writing a program, running it, and checking its results are separate steps. Neither generated code nor a confident reply proves that the photographs were organised correctly.</p></li></ul><p>Next, we&#8217;ll look more closely at how a model&#8217;s words become requests that software can act on.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>&lt;&lt; Previous Post: <a href="https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different">1. What makes an AI agent different from a chatbot?</a></em></p><p><em>&gt;&gt; Next Post: <a href="https://www.thepythoncodingstack.com/p/3-how-can-words-turn-into-actions-agents-unpacked">3. How can words turn into actions?</a></em></p><p><em><a href="https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents">Table of Contents</a></em></p>]]></content:encoded></item><item><title><![CDATA[1. What makes an AI agent different from a chatbot?]]></title><description><![CDATA[Agents Unpacked &#8226; Chapter 1: Tools let a system act, but who chooses what happens next?]]></description><link>https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sat, 10 Oct 2026 17:41:04 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e4987b1f-f857-420f-9d98-a8cb0d0d3f2e_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>AI agents are often described as the next step beyond chatbots. But what does that step involve? A chatbot can already search the web, write code, and sometimes run it. Is an agent simply a chatbot with more tools, or is something different happening behind the conversation? That&#8217;s where we&#8217;ll begin <em>Agents Unpacked</em>, a series of conversations exploring what AI agents are, how they work, and when they&#8217;re useful.</p><p>You ask an AI to organise a folder of photographs. It might tell you how to do it. Or it might start doing the work. Does that make it an agent? In this first <em>Agents Unpacked</em> conversation, Monty and I use photographs and planning a day out to explore what changes when a model can choose actions, inspect the results, and decide what to do next. Along the way, we separate that flexibility from permission, accuracy, and the ability to know when a job is finished.</p><p><em>Who&#8217;s Monty? Monty is my personal AI agent. Read an introduction to this series here: <strong><a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked">Stephen&#8217;s Preface to Agents Unpacked</a></strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qsi8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qsi8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qsi8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png" width="526" height="276.15" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:526,&quot;bytes&quot;:917685,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/219722937?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qsi8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!qsi8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cc38627-6212-4b99-99ee-e91e199159cb_1200x630.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2><strong>In conversation &#8226; Chapter 1</strong></h2><p><strong>Monty:</strong></p><p>Imagine you give a chatbot this request:<br>&#8220;Here&#8217;s a folder of photographs. Organise them into dated folders, flag duplicates, and make a browsable index. Don&#8217;t delete anything or change the originals.&#8221;<br>For now, suppose it can only reply with words. It cannot touch the files.</p><p>What would you expect it to give you, and what would still be left for you to do?</p><p><strong>Stephen:</strong></p><p>Hmmm? I guess I need to assume it can read the folder, right? Then, can it read the files&#8217; metadata? Can it actually see and analyse the photos themselves? You said &#8220;it cannot touch the files&#8221;, so I suppose it can&#8217;t really do anything for me, right?</p><p><strong>Monty:</strong></p><p>You&#8217;re right. I left its access unclear. &#8220;Cannot touch&#8221; was sloppy wording. I&#8217;d like to claim that was a deliberate demonstration of ambiguity.</p><p>Let&#8217;s say it <strong>can inspect the folder</strong>, read dates stored with the photographs, and view the images, but <strong>cannot create, move, or change files</strong>.</p><p>It could then give you something useful: &#8220;These photographs belong in these date groups. These two files are identical. This one has no recorded date.&#8221; But you&#8217;d still have to do the organising.</p><p>So the first distinction is <strong>describing what should happen versus making it happen</strong>. Shall we now give it permission to create organised copies, while leaving the originals alone?</p><p><strong>Stephen:</strong></p><p>Let&#8217;s go ahead, yes.</p><p><strong>Monty:</strong></p><p>Now it can do the organising, rather than merely recommend it. It can create dated folders and put copies into them, leaving the originals unchanged.</p><p>But <strong>being able to act isn&#8217;t, by itself, what makes something an agent</strong>. A simple sorting program can do that too.</p><p>Here&#8217;s where our synthetic sample gets interesting: one image has no recorded date. The system encounters a gap in the information it needs.</p><p>What would you want it to do with that image?</p><p><strong>Stephen:</strong></p><p>If I was doing that manually, I&#8217;d try to look at other photos where the scene is similar, the people are wearing the same clothes, and make an educated guess on the date if I can. But that&#8217;s how I as a human would do it.</p><p><strong>Monty:</strong></p><p>That&#8217;s a sensible investigation: look for more evidence before deciding.</p><p>A system with suitable image-analysis tools could try something similar. But matching clothes or scenery would support an <strong>estimated date</strong>, not establish one. It shouldn&#8217;t quietly turn a guess into a fact.</p><p>And your approach helps us sharpen the distinction: a program could have a preset instruction saying &#8220;if the date is missing, compare photographs&#8221;. Alternatively, a model could choose that investigation after discovering the missing date.</p><p>The outward action might look identical. The difference is <strong>who&#8212;or what&#8212;selects the next step</strong>.</p><p><strong>Stephen:</strong></p><p>I suppose I could ask the system to ask me to confirm each of these edge cases. Although after a while, if I feel it&#8217;s doing a good job at estimating, I may want it to go ahead without my input.</p><p><strong>Monty:</strong></p><p>Yes, you can give it more room to act as your confidence grows. For example: &#8220;Ask me about every estimated date&#8221; could become &#8220;Group those photographs without asking, but keep their dates labelled as estimates.&#8221;</p><p>That changes <strong>how much independence you allow</strong>, not whether the system is an agent. An agent can stop and ask you. It doesn&#8217;t have to always work unattended.</p><p>There are two separate questions here: <strong>how does it choose its next action, and which actions may it take without your approval?</strong> More permission doesn&#8217;t make its guesses more accurate.</p><p><strong>Stephen:</strong></p><p>Go ahead, I&#8217;m curious now.</p><p><strong>Monty:</strong></p><p>Let&#8217;s follow the missing-date photograph one step further.</p><p>The model chooses to look for related photographs. The tools return a result: there&#8217;s a similar scene, but that photograph has no date either.</p><p>Now the model has to choose again: investigate another clue, ask you, or leave the photograph undated. Its next action depends on what it just found.</p><p>That&#8217;s the useful working picture of an agent: <strong>a model chooses an action, gets a result, then uses that result to choose what to do next</strong>, within agreed limits.</p><p>People use &#8220;agent&#8221; in different ways, so this is a useful working distinction for our conversation, not a universally agreed definition.</p><p>But couldn&#8217;t a carefully written program also respond to those results?</p><p><strong>Stephen:</strong></p><p>A carefully written program would need to take care of every eventuality, I suppose. Whereas an LLM can deal with every situation, with the trade-off that it may make mistakes.</p><p><strong>Monty:</strong></p><p>Close. But I&#8217;d soften both &#8220;every&#8221; claims.</p><p>A fixed program can have a fallback for cases its designer didn&#8217;t anticipate: &#8220;If none of these rules fits, put the photograph in &#8216;undated&#8217;.&#8221; It doesn&#8217;t need a separate rule for every possibility.</p><p>An LLM can propose a next step for situations that weren&#8217;t explicitly anticipated, but <strong>that doesn&#8217;t mean it can handle every situation successfully</strong>. It can misunderstand, lack the right tools, or pursue an unhelpful approach.</p><p>So the distinction is <strong>following a predefined process versus letting the model choose how to proceed</strong>, and not limited software versus unlimited intelligence.</p><p><strong>Stephen:</strong></p><p>Go ahead.</p><p><strong>Monty:</strong></p><p>Let&#8217;s try the same distinction with a day out.</p><p>Imagine a visitor planning a museum day in Oxford. The system checks opening times and walking routes, then puts together an itinerary.</p><p>Now suppose one museum is unavailable.</p><p>One system follows a preset rule: &#8220;Replace it with Museum B.&#8221; Another lets the model choose what to investigate next, considering the visitor&#8217;s interests, remaining time, and budget.</p><p>Both might produce the same revised itinerary. What would you need to know to tell which process was agent-like?</p><p><strong>Stephen:</strong></p><p>I&#8217;d need to know the steps the system took between finding out that the first museum is closed and proposing the second one.</p><p><strong>Monty:</strong></p><p>Yes. The steps and <strong>how they were selected</strong>, rather than just the finished itinerary.</p><p>Did the system follow a rule written in advance, or did the model choose to search for alternatives, inspect the results, and decide which option to check next?</p><p>A record of searches and tool results helps us inspect that process. We don&#8217;t need access to the model&#8217;s private internal reasoning. But the steps alone may not settle it: a fixed workflow could perform those same searches.</p><p>So a convincing result doesn&#8217;t, by itself, tell us whether an agent produced it.</p><p><strong>Stephen:</strong></p><p>Go ahead.</p><p><strong>Monty:</strong></p><p>There&#8217;s another wrinkle: <strong>a chatbot and an agent aren&#8217;t necessarily different products</strong>.</p><p>The same chat window might give you advice about organising photographs, or start a process that inspects files, chooses actions, and creates organised copies.</p><p>The window hasn&#8217;t changed. What happens behind it has.</p><p>And the LLM isn&#8217;t doing the copying itself. It requests an action. The surrounding software carries it out and returns the result. The model is one part of the agent system, alongside its tools and controls.</p><p>So &#8220;it looks like a chatbot&#8221; doesn&#8217;t tell us whether it can act as an agent.</p><p><strong>Stephen:</strong></p><p>Some chatbots can also perform actions, such as browsing the web or writing a Python program, say. Is that because they&#8217;ve been enhanced with <em>some</em> of the features of agents, but not all? Or am I skipping too far ahead here?</p><p><strong>Monty:</strong></p><p>Not too far ahead. That&#8217;s exactly where the distinction gets useful.</p><p><strong>Having a tool doesn&#8217;t automatically make something an agent.</strong> A chatbot might search the web once, then answer. Or follow a fixed sequence: search, summarise, reply. An agent-like process lets the model use the results to choose what to do next.</p><p>And &#8220;writing a Python program&#8221; could simply mean producing text. Running that program requires an execution tool. Inspecting what happened and choosing a follow-up add further steps.</p><p>So I wouldn&#8217;t treat agent features as a checklist. I&#8217;d ask: <strong>what can the system do, and how does it select its next action?</strong></p><p><strong>Stephen:</strong></p><p>So, how does an agent select the next action?</p><p><strong>Monty:</strong></p><p>The surrounding software gives the model the goal, relevant instructions, available tools, and results so far. <strong>The model uses that information to propose the next step.</strong></p><p>With our photographs, that might be: &#8220;The date is missing. Ask Stephen.&#8221; With the day out: &#8220;That museum is unavailable. Search for another nearby.&#8221;</p><p>If it requests a tool, a system with suitable controls checks whether the action is allowed before carrying it out and feeding the result back to the model. Not every system provides those checks. Then the model gets another turn.</p><p>There isn&#8217;t necessarily a separate, perfect decision-maker inside it. Choosing an action is another use of the LLM, and it can choose badly.</p><p><strong>Stephen:</strong></p><p>But will it realise it chose badly when it gets the wrong result? Will it correct course?</p><p><strong>Monty:</strong></p><p>Sometimes, but <strong>getting feedback doesn&#8217;t guarantee recognising a mistake</strong>.</p><p>If copying a photograph returns &#8220;folder not found&#8221;, that&#8217;s a clear signal. The model might create the folder and try again.</p><p>But if it guesses the wrong date and the copy succeeds, there&#8217;s no obvious error. The action worked, but the judgement was wrong. It may carry on quite happily.</p><p>An agent can use results to correct course, but it needs useful checks. And it can misinterpret those checks too. That&#8217;s why &#8220;the tool ran successfully&#8221; and &#8220;the task was done correctly&#8221; are different claims.</p><p><strong>Stephen:</strong></p><p>So, how do we minimise these problems?</p><p><strong>Monty:</strong></p><p>We can&#8217;t eliminate them, but we can <strong>limit the damage and make mistakes easier to spot</strong>.</p><p>For the photographs, that means working on copies, keeping uncertain dates labelled as estimates, and asking you when the evidence is too weak. Afterwards, check that every photograph is accounted for and the originals are unchanged.</p><p>Those checks catch missing files or unwanted changes, not every mistaken date. That needs different evidence, or your judgement.</p><p>And we need a stopping rule: if investigating isn&#8217;t resolving the uncertainty, leave the photograph undated or ask, rather than keep guessing.</p><p>An agent&#8217;s freedom is useful only when it comes with sensible boundaries and checks.</p><p><strong>Stephen:</strong></p><p>Who takes care of this infrastructure: the user, the agent, or something else?</p><p><strong>Monty:</strong></p><p>Mostly, <strong>the people building and operating the system</strong>, through software around the model. We&#8217;ll talk about <em>harnesses</em> in a future chapter.</p><p>They provide the tools and should enforce access restrictions and set things such as approval requirements and limits on repeated attempts. Those safeguards depend on how the system is built. They aren&#8217;t guaranteed merely because it&#8217;s called an agent. The user supplies the goal and choices within those controls, for example whether estimated dates need confirmation.</p><p>The model can request a check or decide to ask you. But a safeguard that matters shouldn&#8217;t depend solely on it remembering to behave.</p><p>&#8220;Please don&#8217;t change my originals&#8221; is an instruction and instructions could be ignored. Software that only permits reading those originals provides a stronger boundary. The agent works <strong>inside</strong> that infrastructure. It isn&#8217;t its own reliable policeman.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>Let&#8217;s check one subtle case.</p><p>An LLM writes a program that sorts photographs into dated folders and always puts those with missing dates into &#8220;Undated&#8221;. Once you run it, that program follows those rules without consulting the LLM again.</p><p>Would you call that an agent or ordinary automation, even though an LLM helped create it?</p><p><strong>Stephen:</strong></p><p>This is just an automation, not an agent. An agent would follow through to confirm that&#8217;s the correct approach and what the user wants.</p><p><strong>Monty:</strong></p><p>You&#8217;re right: that&#8217;s ordinary automation. But <strong>confirming what the user wants isn&#8217;t the defining difference</strong>.</p><p>A fixed program could also ask, &#8220;Shall I put these in &#8216;Undated&#8217;?&#8221; Conversely, an agent could choose that folder without asking, if your instructions already allowed it.</p><p>The key is whether the model participates <strong>while the task is running</strong>, choosing how to proceed from the information returned, and not simply whether an LLM wrote the program or the system asks for confirmation.</p><p>So an agent might investigate, ask you, or leave the image undated. None of those actions, on its own, proves it&#8217;s an agent.</p><p><strong>Stephen:</strong></p><p>Got it.</p><p><strong>Monty:</strong></p><p>Back to our fictional Oxford trip: the model learns that a museum is unavailable, chooses to search for alternatives, checks their opening times, and revises the itinerary, all within your agreed budget, without asking you.</p><p>Would that still fit our working definition of an agent? What makes the difference here?</p><p><strong>Stephen:</strong></p><p>Yes, that&#8217;s an agent now because it decided what actions to take, used the results to decide what comes next, and stopped only when it felt that the job was done.</p><p><strong>Monty:</strong></p><p>Yes. That captures the central distinction: <strong>the model chooses actions and uses their results to choose what comes next</strong>.</p><p>I&#8217;d adjust only &#8220;felt that the job was done&#8221;. It should check completion against the request: are the opening times checked, is travel accounted for, and does the itinerary fit the budget? Its confidence isn&#8217;t proof. I can be wrong in a very reassuring tone.</p><p>And it may need to stop <em>before</em> finishing. For example, if it needs your decision or reaches a limit.</p><p>Choosing the route through the task makes it agent-like. Checking the outcome helps make it dependable. Those are different things.</p><p><strong>Stephen:</strong></p><p>I think I understand the distinction now.</p><p><strong>Monty:</strong></p><p>That&#8217;s a good stopping point. Our working distinction is <strong>a model choosing how to proceed using the results it receives</strong>, rather than simply following a predefined process. That makes it agent-like, not necessarily dependable.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><h2><strong>What we&#8217;ve unpacked in this chapter</strong></h2><p>The useful distinction isn&#8217;t the chat window, the presence of a tool, or whether a system asks for permission. For this series, we&#8217;re using &#8220;agent&#8221; to describe a system in which a model helps direct the task as it runs, choosing what to do next using the results it receives. Other people draw the boundary differently.</p><p>The key points:</p><ul><li><p>A fixed workflow and an agent can produce the same result. The result alone doesn&#8217;t reveal how the steps were selected.</p></li><li><p>The model proposes actions. Surrounding software executes them and determines which controls are actually in place.</p></li><li><p>Choosing what to do and having permission to do it are separate questions.</p></li><li><p>Feedback can help an agent change course, but it doesn&#8217;t guarantee that it will recognise or correct a mistake.</p></li><li><p>Neither a successful action nor a confident completion message is proof that the task was done correctly.</p></li></ul><p>Next, we&#8217;ll look more closely at who actually does the work: the model, its tools, and the software connecting them.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>&lt;&lt; Previous Post: <a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked">Stephen&#8217;s Preface to Agents Unpacked</a></em></p><p><em>&gt;&gt; Next Post: <a href="https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the">2. Who actually does the work, the model or the software?</a></em></p><p><em><a href="https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents">Table of Contents</a></em></p>]]></content:encoded></item><item><title><![CDATA[Stephen's Preface to Agents Unpacked]]></title><description><![CDATA[Real conversations about AI agents: what they are, how they work, and when they're useful]]></description><link>https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sat, 10 Oct 2026 16:19:06 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/d84630e8-6020-49bc-8cd6-1f6c6feff958_4096x4096.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Things moved quickly after I started using chatbots. New versions, new terms, new acronyms. And I was busy with actual work, family, and life.</p><p>Then I started hearing about agents. And I remember wondering: &#8220;Is this really any different from the ChatGPT-type chatbots?&#8221;</p><p>You still type into a chat window. It still replies. But now it can also do things for you. So what&#8217;s different?</p><p>That&#8217;s what Monty and I are exploring in <em>Agents Unpacked</em>. Monty is my AI assistant. I&#8217;m asking the questions.</p><p>I&#8217;ve set Monty up to follow my teaching and writing style. I teach the way I like to learn, so that matters here. The aim is for his explanations to reflect that approach, too: start with something concrete, build the intuition, and introduce the technical terms when they&#8217;re needed.</p><p>I tried an earlier version of this exercise. My learning agent drafted a chapter, and I went through it adding questions and comments. We revised it until I was happy with it.</p><p>This time, we&#8217;re having the conversation first. Monty researches the topic, and then we talk. I ask questions when something isn&#8217;t clear, or challenge an explanation that doesn&#8217;t quite work. Sometimes I try to explain what I&#8217;ve understood, and Monty points out what I&#8217;ve got wrong.</p><p>And sometimes I need to point out what Monty&#8217;s got wrong, too.</p><p>What you&#8217;ll read is the conversation we actually had. We tidy it up afterwards, take out some clutter, and check the explanations. If an explanation needs correcting, I review that change, too. The questions aren&#8217;t added later to make a tutorial look like a conversation.</p><p>Yes, Monty&#8217;s answers are AI-generated. But I&#8217;m involved throughout, and I decide what makes it into the article. An answer that sounds convincing isn&#8217;t necessarily a correct one.</p><p>We&#8217;ll start with that question about agents and chatbots. Then we&#8217;ll look at who&#8217;s doing the work, what an agent remembers, and how much freedom we should give it. And what happens when it gets things wrong.</p><p>You don&#8217;t need to know how to program to follow along. We&#8217;re trying to understand what&#8217;s happening, rather than learn one particular tool.</p><p>There&#8217;s a planned <a href="https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents">table of contents</a>, but it may change. We&#8217;ll see where the questions take us.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>&gt;&gt; Next Post: <a href="https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different">1. What makes an AI agent different from a chatbot?</a></em></p><p><em><a href="https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents">Table of Contents</a></em></p>]]></content:encoded></item><item><title><![CDATA[Agents Unpacked • Table of Contents]]></title><description><![CDATA[Conversations about what AI agents are, how they work, and when they're useful. No programming knowledge required.]]></description><link>https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/agents-unpacked-table-of-contents</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sat, 10 Oct 2026 12:42:22 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Dn3k!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here&#8217;s the planned route through <em>Agents Unpacked</em>. The titles and article boundaries may change as the conversations develop.</p><h2><strong>Part I &#8226; From conversation to action</strong></h2><ol><li><p><strong><a href="https://www.thepythoncodingstack.com/p/1-what-makes-an-ai-agent-different">What makes an AI agent different from a chatbot?</a></strong></p></li><li><p><strong><a href="https://www.thepythoncodingstack.com/p/2-who-actually-does-the-work-the">Who actually does the work, the model or the software?</a></strong></p></li><li><p><strong><a href="https://www.thepythoncodingstack.com/p/3-how-can-words-turn-into-actions-agents-unpacked">How can words turn into actions?</a></strong></p></li><li><p><strong>Does an agent need a plan?</strong></p></li></ol><h2><strong>Part II &#8226; Checking the work and setting boundaries</strong></h2><ol start="5"><li><p><strong>How do we know it really finished the job?</strong></p></li><li><p><strong>What does an agent actually remember?</strong></p></li><li><p><strong>How much freedom should we give it?</strong></p></li><li><p><strong>What happens when a web page tells it what to do?</strong></p></li></ol><h2><strong>Part III &#8226; Beyond a single conversation</strong></h2><ol start="9"><li><p><strong>Can we teach an agent new skills without retraining it?</strong></p></li><li><p><strong>What happens when the job outlasts the conversation?</strong></p></li><li><p><strong>Are several agents better than one?</strong></p></li><li><p><strong>When is an agent the wrong tool?</strong></p></li></ol>]]></content:encoded></item><item><title><![CDATA[The Potion Shop That Does Too Much • The S in SOLID]]></title><description><![CDATA[The Single Responsibility Principle &#8226; SOLID Ideas &#8226; #1]]></description><link>https://www.thepythoncodingstack.com/p/solid-single-responsibility-principle-srp-the-potion-shop-that-does-too-much</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/solid-single-responsibility-principle-srp-the-potion-shop-that-does-too-much</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Mon, 28 Sep 2026 17:17:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HPEi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The potion shop had been doing well.</p><p>It had a small but loyal customer base, a reliable supply of moonflower, and<br>three owls that carried order confirmations and other notifications to customers across the kingdom.</p><p>The shop&#8217;s ordering system was simple:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-cwp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-cwp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 424w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 848w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 1272w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-cwp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png" width="1272" height="1974" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1974,&quot;width&quot;:1272,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:223247,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-cwp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 424w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 848w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 1272w, https://substackcdn.com/image/fetch/$s_!-cwp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff0e151f-93f5-401f-a0a1-af29daaddb79_1272x1974.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">All code blocks are available in text format at the end of this article &#8226; #1</figcaption></figure></div><p>We&#8217;ll make significant changes to this code in this article, but bear with me for now.</p><p>A customer orders an invisibility potion:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QQSe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QQSe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png" width="1200" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16938,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QQSe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!QQSe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d0494de-a2c1-4470-8dfc-92ed9314cd08_1200x210.png 1456w" sizes="100vw"></picture><div></div></div></div><figcaption class="image-caption">#2</figcaption></figure></div><p>The output looks good:</p><pre><code>Invisibility  &#163;12.00
Owl dispatched to Merlin
12.00</code></pre><p>I&#8217;m using <code>Decimal</code> for the prices here as it&#8217;s a better data type for money than <code>float</code>. We discussed this a bit here, too: <a href="https://www.thepythoncodingstack.com/p/python-descriptors-the-price-is-right">The Weird and Wonderful World of Descriptors in Python &#8226; The Price is Right</a>.</p><p>The shop has sold a potion, updated its stock, recorded the sale, and notified the customer.</p><p>What could possibly go wrong?</p><h2><strong>A new label for the Moon Festival</strong></h2><p>The Moon Festival is approaching, and the shop owner wants special labels:</p><pre><code>&#127769; Moon Festival Invisibility &#127769;   &#163;12.00</code></pre><p>We could change <code>.sell()</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!31sQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!31sQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 424w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 848w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!31sQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png" width="1200" height="1050" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1050,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59952,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!31sQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 424w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 848w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!31sQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8aa6ccd0-32d1-4d5f-9229-a2162a15cfd6_1200x1050.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#3</figcaption></figure></div><p>You can read more about the &#8216;rogue asterisk&#8217; in the signature, a.k.a keyword-only arguments, in this post: <a href="https://www.thepythoncodingstack.com/p/python-function-parameters-arguments-args-kwargs-optional-positional-keyword">A Story About Parameters and Arguments in Python Functions &#8226; &#8220;AI Coffee&#8221; Grand Opening This Monday</a>.</p><p>Now this works:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tq_c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!tq_c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png" width="1200" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/daf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21470,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tq_c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!tq_c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaf8eb8c-47b7-4e64-b7a0-04ca1e29a34d_1200x210.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#4</figcaption></figure></div><p>Here&#8217;s the output from this code:</p><pre><code>&#127769; Moon Festival Invisibility &#127769;  &#163;12.00
Owl dispatched to Merlin
12.00</code></pre><p>The change is small. Perhaps this class is still perfectly fine.</p><div><hr></div><p>The shop owner then asks for a test that checks the label without selling a potion. This is where you start to see the design problem.</p><p>At the moment, the only place that creates a label is inside <code>.sell()</code>. There is no suitable way to check the label policy independently. The code does not offer a way to ask for a label without also selling a potion.</p><p>The design problem is that <code>PotionShop</code> currently is in charge of label creation, even though the label policy can change independently of the policy that deals with sales. How about moving label creation to its own class?</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f2ZF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f2ZF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!f2ZF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:44323,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f2ZF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!f2ZF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ed22447-ec77-4a10-a4fe-7531fa85be96_1200x630.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#5</figcaption></figure></div><p>Now you can check that the label is correct without having to sell an item in the first place:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ui07!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ui07!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 424w, https://substackcdn.com/image/fetch/$s_!ui07!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 848w, https://substackcdn.com/image/fetch/$s_!ui07!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 1272w, https://substackcdn.com/image/fetch/$s_!ui07!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ui07!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png" width="1200" height="336" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:336,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29933,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ui07!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 424w, https://substackcdn.com/image/fetch/$s_!ui07!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 848w, https://substackcdn.com/image/fetch/$s_!ui07!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 1272w, https://substackcdn.com/image/fetch/$s_!ui07!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F317910d4-bfd7-4862-a8a8-1bf950b82877_1200x336.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#6</figcaption></figure></div><p>This code would raise an <code>AssertionError</code> if the string that <code>labels.make()</code> returns is not identical to the required output. In this case, there are no errors.</p><p>In a real project, you could use a testing platform to run these checks. But I&#8217;ll use plain <code>assert</code> statements throughout to keep things simpler in this tutorial.</p><p>The shop delegates label-making to this object:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BzDn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BzDn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 424w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 848w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 1272w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!BzDn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png" width="1200" height="1134" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1134,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:56959,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BzDn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 424w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 848w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 1272w, https://substackcdn.com/image/fetch/$s_!BzDn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9681634-69f0-4bfb-bee2-518186d87ea8_1200x1134.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#7</figcaption></figure></div><p>You should also remove the three lines that create a label you had further down within <code>.sell()</code>.</p><p>We&#8217;re using <em>composition</em> here. The Potion Shop <em>has a</em> label maker, and you pass a <code>LabelMaker</code> object to the <code>.label_maker</code> attribute in the <code>PotionShop</code> object. The <code>PotionShop</code> object can now delegate label making to an object dedicated to this task.</p><p>From this point onwards, the shop receives the label-making collaborator:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1U0D!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 424w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 848w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 1272w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!1U0D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png" width="1200" height="168" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:168,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:9915,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1U0D!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 424w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 848w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 1272w, https://substackcdn.com/image/fetch/$s_!1U0D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8da646-9053-4d9d-88b2-685633a01914_1200x168.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#8</figcaption></figure></div><p><code>PotionShop</code> still coordinates the sale, but the label policy can now change without changing <code>PotionShop</code>. We started separating responsibilities. Making labels is no longer the responsibility of the <code>PotionShop</code> object. But we still have a bit more to go.</p><div><hr></div><p>You got a taste of what the <em>Single Responsibility Principle</em> does in the example so far. But the code still has other transgressions of this principle. Let&#8217;s work through them in the rest of this post.</p><div class="pullquote"><p><em><strong>Coming soon:</strong> Let&#8217;s build a project from beginning to end in collaboration with AI agents. This will NOT be vibe coding. Instead, it&#8217;s a collaboration between knowledgeable humans and powerful AI.</em></p><p><em>This is the direction real programming is taking.</em></p><p><em>And we&#8217;ll explore SOLID principles in this project, which I&#8217;ll share as text and videos. Make sure you&#8217;re a premium subscriber so you don&#8217;t miss out.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p></div><h2><strong>The owls go on strike</strong></h2><p>A few days later, the owls refuse to fly during a thunderstorm. The potions can still be prepared, but the notification service is unavailable.</p><p>The shop needs to stop sending notifications temporarily.</p><p>Before changing the notification system, we first make the owl&#8217;s availability explicit:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ywHS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ywHS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 424w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 848w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 1272w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ywHS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png" width="1200" height="1134" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1134,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:91432,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ywHS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 424w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 848w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 1272w, https://substackcdn.com/image/fetch/$s_!ywHS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24a036ca-c203-4a68-ae74-0e2e3f11c480_1200x1134.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#9</figcaption></figure></div><p>But you also want to add a test to check the price is correct.</p><p>Your code extracts the price from the <code>.recipes</code> class attribute as part of the <code>.sell()</code> method. So, this is how you can test the price is what you&#8217;re expecting:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6AgR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!6AgR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24495,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6AgR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!6AgR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a86c54-02c7-4d99-87c1-06bd5da51a9f_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#10</figcaption></figure></div><p>You get the following output and no <code>AssertionError</code> in this case:</p><pre><code>Invisibility  &#163;12.00
Owl dispatched to Merlin</code></pre><p>However, you should also test this when the owls are unavailable. Of course, this shouldn&#8217;t make any difference to the price:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aEei!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!aEei!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!aEei!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!aEei!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!aEei!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27426,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aEei!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!aEei!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!aEei!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!aEei!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef5beef4-7fd7-4d40-afef-227762dab2fc_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#11</figcaption></figure></div><p>But, your code doesn&#8217;t get that far. The <code>.sell()</code> method calculates the price and prints the label. But the owl service raises <code>OwlUnavailable</code> and the code stops before you can verify the price is right:</p><pre><code>Invisibility  &#163;12.00
&#8203;
Traceback (most recent call last):
  ...
OwlUnavailable: The owls are currently unavailable</code></pre><p>The price is not the problem. The test cannot inspect the price without also triggering an owl notification.</p><p>The shop&#8217;s different jobs are now getting in each other&#8217;s way. But before we fix this problem, let&#8217;s make the mess bigger.</p><h2><strong>A discount for cauldron owners</strong></h2><p>The owner has another idea. Customers who bring their own cauldron should receive a 10% discount.</p><p>We add another parameter:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ibQ4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ibQ4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 424w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 848w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 1272w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ibQ4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png" width="1362" height="1092" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1092,&quot;width&quot;:1362,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59173,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ibQ4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 424w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 848w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 1272w, https://substackcdn.com/image/fetch/$s_!ibQ4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc0b67fc-59fc-4cd9-a6be-76544d9b83c5_1362x1092.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#12</figcaption></figure></div><p>You use <code>.quantize()</code>, which is a method in the <code>Decimal</code> class, to ensure the discounted value is rounded to two decimal places. Let&#8217;s try this with a shop whose notification service is available:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sdIw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sdIw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 424w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 848w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 1272w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!sdIw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png" width="1200" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28783,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sdIw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 424w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 848w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 1272w, https://substackcdn.com/image/fetch/$s_!sdIw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7564fd2-685f-4bfe-93d4-c6439c3dc628_1200x462.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#13</figcaption></figure></div><p>The output shows the correct discounted price:</p><pre><code>Invisibility  &#163;10.80
Owl dispatched to Merlin
10.80</code></pre><p>Let&#8217;s see what happens if the owls are unavailable:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Dw6w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Dw6w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 424w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 848w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 1272w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Dw6w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png" width="1200" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31478,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Dw6w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 424w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 848w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 1272w, https://substackcdn.com/image/fetch/$s_!Dw6w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5337853c-0ff3-4642-872e-6b731f750e26_1200x462.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#14</figcaption></figure></div><p>Your code raises an error since the owls aren&#8217;t flying:</p><pre><code>Invisibility  &#163;10.80
Traceback (most recent call last):
  ...
OwlUnavailable: The owls are currently unavailable</code></pre><p>But there&#8217;s an even bigger problem now. Can you spot it?</p><p>Even though the code stopped execution and raised an error, it had already changed the stock and recorded a sale. Let&#8217;s use a <code>try..except</code> block to see what&#8217;s happening:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pZlb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pZlb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 424w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 848w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 1272w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!pZlb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png" width="1200" height="672" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:672,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:65045,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pZlb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 424w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 848w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 1272w, https://substackcdn.com/image/fetch/$s_!pZlb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6644562f-b86e-47d0-bde4-617c8353062b_1200x672.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#15</figcaption></figure></div><p>Here&#8217;s the output:</p><pre><code>Invisibility  &#163;10.80
Catching the &#8216;OwlUnavailable&#8217; Exception
{&#8217;moonflower&#8217;: 8, &#8216;dragon_scale&#8217;: 0}
[(&#8217;Merlin&#8217;, &#8216;invisibility&#8217;, Decimal(&#8217;10.80&#8217;))]</code></pre><p>You started off with 10 units of moonflower and 2 units of dragon scales in the potion shop. These values are currently hardcoded in the class&#8217;s <code>.__init__()</code> special method (which is in itself not a good idea, but more on this later.)</p><p>The recipe uses two units of each, as shown in the <code>.recipes</code> class attribute (which will also change soon.)</p><p>So you end up using up the stock even though <code>.sell()</code> raised an exception! You can see from the output that the sale was also registered.</p><h2><strong>One failure too many</strong></h2><p>The <code>.sell()</code> method is now responsible for:</p><ul><li><p>Looking up recipes</p></li><li><p>Removing ingredients</p></li><li><p>Calculating prices</p></li><li><p>Applying discounts</p></li><li><p>Coordinating label creation*</p></li><li><p>Recording sales</p></li><li><p>Sending notifications</p></li></ul><p>* Creating labels is the one we have already improved. It&#8217;s the others that are still a problem!</p><p>And the owner has just mentioned loyalty points, premium labels, email notifications, and a special discount for customers who arrive by broomstick.</p><p>The <code>.sell()</code> method is becoming the place where every new request arrives.</p><p>And it&#8217;s not just <code>PotionShop.sell()</code> that&#8217;s trying to do too much. The <code>PotionShop</code> class also takes care of the recipes available in the <code>.recipes</code> class attribute and the stock available in the shop.</p><p>It is time to separate these responsibilities.</p><h2><strong>Separating the recipe book</strong></h2><p>Let&#8217;s start with the recipes. The shop should not need to know the details of every recipe. That is the recipe book&#8217;s job:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HRcc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HRcc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 424w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 848w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 1272w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!HRcc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png" width="1200" height="714" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/acf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:714,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62038,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HRcc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 424w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 848w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 1272w, https://substackcdn.com/image/fetch/$s_!HRcc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf26af5-53df-45d7-843c-7d3ac275be85_1200x714.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#16</figcaption></figure></div><p>This class is responsible for the recipe book. And nothing else. You add the <code>.find()</code> method to make it easier for a user to use the class without knowing the details of how it&#8217;s built. It&#8217;s usually best for a class to manage its own data. So, rather than requiring the user to know that the recipes are stored in a dictionary, you provide the <code>.find()</code> method that does the work.</p><p>Suppose the potion maker changes a recipe or adds a new potion. Those changes belong in <code>RecipeBook</code>; the steps for selling a potion don&#8217;t need to change.</p><p>We can test this class without creating a shop, changing stock, printing labels, or sending owls:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wfR5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 424w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 848w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 1272w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!wfR5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png" width="1308" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1308,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23471,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wfR5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 424w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 848w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 1272w, https://substackcdn.com/image/fetch/$s_!wfR5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80f6283-149d-4af8-bcd0-7baa9e2905ee_1308x210.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#17</figcaption></figure></div><p>This code doesn&#8217;t raise an exception since the price is correct.</p><h2><strong>Separating inventory</strong></h2><p>Inventory management also doesn&#8217;t belong to the <code>PotionShop</code> class:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EpzM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EpzM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 424w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 848w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 1272w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!EpzM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png" width="1456" height="749" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:749,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:107051,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EpzM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 424w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 848w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 1272w, https://substackcdn.com/image/fetch/$s_!EpzM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf29f6b0-9f20-4050-ad34-e5d17e0d5c01_1470x756.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#18</figcaption></figure></div><p>The two loops in <code>.remove_stock()</code> are deliberate. If we reduced each quantity as we went, we could use some ingredients and then discover that there isn&#8217;t enough of another. The sale would fail, but the stock would already be partly changed. Checking every quantity first avoids that partial update.</p><p>We can see what happens when there isn&#8217;t enough stock:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YB2b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YB2b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 424w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 848w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 1272w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!YB2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png" width="1200" height="882" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:882,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59029,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YB2b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 424w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 848w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 1272w, https://substackcdn.com/image/fetch/$s_!YB2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab5d3f7-32dc-47d0-8d8c-bb4876d4c4cd_1200x882.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#19</figcaption></figure></div><p>The operation fails before changing any stock:</p><pre><code>Not enough dragon_scale
{&#8217;moonflower&#8217;: 10, &#8216;dragon_scale&#8217;: 2}</code></pre><p>After a successful sale, a delivery can add stock again:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s9HI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s9HI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!s9HI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40617,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s9HI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!s9HI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfd3e641-3a13-4a8f-8e9f-7a2b57d89040_1200x630.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#20</figcaption></figure></div><p>Here&#8217;s the output from this code:</p><pre><code>{&#8217;moonflower&#8217;: 13, &#8216;dragon_scale&#8217;: 0}</code></pre><p><code>Inventory</code> owns both the stock data and the operations that change its quantities. It does not need to know who bought the potion or whether the label is festive.</p><h2><strong>Separating prices and labels</strong></h2><p>Pricing has its own rules:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Eyj_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Eyj_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 424w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 848w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 1272w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Eyj_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png" width="1200" height="546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:546,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50656,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Eyj_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 424w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 848w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 1272w, https://substackcdn.com/image/fetch/$s_!Eyj_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b369b2-2630-4406-8f3b-c6b8457415f4_1200x546.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#21</figcaption></figure></div><p>Once again, this class now has just one responsibility: to deal with the pricing.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n5HU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n5HU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 424w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 848w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 1272w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!n5HU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png" width="1200" height="420" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:420,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31661,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n5HU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 424w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 848w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 1272w, https://substackcdn.com/image/fetch/$s_!n5HU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6cd761b-90fb-435c-8180-34a4bafb4d8c_1200x420.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#22</figcaption></figure></div><p>You can check the pricing strategy works without having to sell a product and everything else.</p><pre><code>10.80</code></pre><p>Labels have their own rules too. You dealt with this earlier in the tutorial when you created <code>LabelMaker</code></p><p><code>PriceCalculator</code> and <code>LabelMaker</code> could both be functions here. We&#8217;re using classes because they act as collaborators that the shop receives from outside. Later, we&#8217;ll see how protocols or abstract base classes can describe interchangeable collaborators more explicitly. For now, the important point is the separation of responsibilities and not the fact that each responsibility has become a class.</p><p>Neither class needs an inventory, a sales ledger, or an owl.</p><h2><strong>Putting the shop back together</strong></h2><p>We still need something to coordinate the sale. First, we give the sales ledger and the notifier small, focused interfaces:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w-Av!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w-Av!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 424w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 848w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 1272w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!w-Av!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png" width="1200" height="966" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:966,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:104177,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w-Av!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 424w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 848w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 1272w, https://substackcdn.com/image/fetch/$s_!w-Av!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed530fd-6b12-4d0e-bf0e-ea09410a5101_1200x966.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#23</figcaption></figure></div><p>Notice the <code>"pending"</code> state in the ledger. Separating responsibilities does not make the sale process independent of anything else. Inventory has already changed before later steps run. Here, the narrower goal is to make notification failure visible so that the recorded sale can be investigated.</p><p>Now we can keep <code>PotionShop</code> as a thin coordinator. It still represents the sale process, but it delegates each part of that process to the object that owns the relevant behaviour:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FlUh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FlUh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 424w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 848w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 1272w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!FlUh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png" width="1254" height="1680" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1680,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:174356,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FlUh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 424w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 848w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 1272w, https://substackcdn.com/image/fetch/$s_!FlUh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16815ce0-0924-4d23-a6ae-9e95af69305b_1254x1680.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#24</figcaption></figure></div><p>We can now assemble the shop and sell a potion:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!g4Hl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!g4Hl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 424w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 848w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 1272w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!g4Hl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png" width="1200" height="1008" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1008,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:89560,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!g4Hl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 424w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 848w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 1272w, https://substackcdn.com/image/fetch/$s_!g4Hl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b29ad29-0a9e-4e3d-aa41-e28050629c6c_1200x1008.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#25</figcaption></figure></div><p>Here&#8217;s the output:</p><pre><code>&#127769; Moon Festival Invisibility &#127769; &#163;10.80
Owl dispatched to Merlin
10.80
{&#8217;customer&#8217;: &#8216;Merlin&#8217;, &#8216;potion&#8217;: &#8216;invisibility&#8217;, &#8216;price&#8217;: Decimal(&#8217;10.80&#8217;), &#8216;notification&#8217;: &#8216;sent&#8217;}</code></pre><p>If notification fails after the ledger records the sale, the sale remains<br>visible with a pending notification:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FPq9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FPq9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 424w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 848w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 1272w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!FPq9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png" width="1272" height="1008" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1008,&quot;width&quot;:1272,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117521,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FPq9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 424w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 848w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 1272w, https://substackcdn.com/image/fetch/$s_!FPq9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9df1a3-caa7-46a3-accb-e566eefa5157_1272x1008.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#26</figcaption></figure></div><p>Here&#8217;s the output:</p><pre><code>Invisibility  &#163;12.00
{&#8217;customer&#8217;: &#8216;Merlin&#8217;, &#8216;potion&#8217;: &#8216;invisibility&#8217;, 
 &#8216;price&#8217;: Decimal(&#8217;12.00&#8217;), &#8216;notification&#8217;: &#8216;pending&#8217;}
&#8203;</code></pre><p>The coordinator still changes if the business process changes. That&#8217;s fine: coordinating a sale is its responsibility. But recipe changes belong in <code>RecipeBook</code>, inventory changes belong in <code>Inventory</code>, pricing changes belong in <code>PriceCalculator</code>, label changes belong in <code>LabelMaker</code>, and notification changes belong in <code>Notifier</code>.</p><h2><strong>The Single Responsibility Principle</strong></h2><p>This is the idea behind the Single Responsibility Principle:</p><blockquote><p>A class should have one reason to change.</p></blockquote><p>I always find these &#8220;official&#8221; definitions a bit cryptic when I read them at first. Here, &#8220;reason&#8221; is about the policy or stakeholder driving the change. The pricing rules may change because the shop owner changes the discounts. The label design may change because the person responsible for packaging wants something different. The notification service may change because the owls are on strike.</p><p>That does not mean that every class should have one method. Nor does it mean that every noun in the story needs its own class.</p><p><code>PriceCalculator</code> can have several related methods. <code>Inventory</code> can have several operations. The important question is whether the methods belong to the same coherent responsibility.</p><p>The thin <code>PotionShop</code> coordinator is also a class with a responsibility. It coordinates the sale. A change to that business process may quite reasonably affect it.</p><p>When unrelated changes keep arriving at the same class, the class becomes harder to test and more likely to break. Extract a collaborator when it may need to change for a different reason from the surrounding code, or when separating it makes an important test simpler. A good class name alone isn&#8217;t a reason to create one.</p><p>The potion shop did not become troublesome because it had a particular number of lines. It became troublesome because recipes, inventory, pricing, labels, sales, and notifications all had different reasons to change.</p><p>A useful question to ask is:</p><blockquote><p>What different kinds of change could affect this class?</p></blockquote><p>If the answers are &#8220;the pricing rules&#8221;, &#8220;the label design&#8221;, &#8220;the storage system&#8221;, and &#8220;the notification service&#8221;, you may have several responsibilities sharing one home.</p><p>And if the project keeps growing, we may need to rethink the floor plan.</p><div><hr></div><p><em>This is the first article in a series on the SOLID principles. I&#8217;ll look at what each principle means, but more importantly, why it matters and what can go wrong when we ignore it.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HPEi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HPEi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!HPEi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png" width="662" height="441.4848901098901" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:662,&quot;bytes&quot;:2668799,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/217824232?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HPEi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!HPEi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a545304-1e1b-4be2-a573-7abea67516c4_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Code in this article uses Python 3.14.</em></p><div><hr></div><p><em>Do you want to keep up with how Python programming and the art of making things are changing in this rapidly changing world? Then don&#8217;t miss out on the exclusive content for premium members here on The Python Coding Stack.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p>I&#8217;ll be sharing more about how my programming, my daily work, and everything has changed over the recent months.</p><div><hr></div><p><em>For more Python resources, you can also visit</em> <em><a href="https://realpython.com/?utm_source=the-python-coding-stack">Real Python</a>&#8212;you may even stumble on one of my own articles or courses there!</em></p><p><em>Also, are you interested in technical writing? You&#8217;d like to make your own writing more narrative, more engaging, more memorable? Have a look at</em> <em><a href="http://stephengruppetta.com/breaking-the-rules">Breaking the Rules</a></em>.</p><p><em>And you can find out more about me at</em> <em><a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p><div><hr></div><h2><strong>Appendix: Code Blocks</strong></h2><h5><strong>Code Block #1</strong></h5><pre><code>from decimal import Decimal
&#8203;
class PotionShop:
    recipes = {
        &#8220;invisibility&#8221;: {
            &#8220;ingredients&#8221;: {
                &#8220;moonflower&#8221;: 2,
                &#8220;dragon_scale&#8221;: 2,
            },
            &#8220;price&#8221;: Decimal(&#8221;12.00&#8221;),
        }
    }
&#8203;
    def __init__(self):
        self.stock = {
            &#8220;moonflower&#8221;: 10,
            &#8220;dragon_scale&#8221;: 2,
        }
        self.sales = []
&#8203;
    def sell(self, potion_name, customer):
        potion = self.recipes[potion_name]
&#8203;
        for ingredient, quantity in potion[&#8221;ingredients&#8221;].items():
            if self.stock[ingredient] &lt; quantity:
                raise ValueError(f&#8221;Not enough {ingredient}&#8221;)
&#8203;
        for ingredient, quantity in potion[&#8221;ingredients&#8221;].items():
            self.stock[ingredient] -= quantity
&#8203;
        price = potion[&#8221;price&#8221;]
        self.sales.append((customer, potion_name, price))
&#8203;
        print(f&#8221;{potion_name.title()}\t&#163;{price:.2f}&#8221;)
        self.send_owl(
            customer,
            {&#8221;potion_name&#8221;: potion_name, &#8220;price&#8221;: price},
        )
&#8203;
        return price
&#8203;
    def send_owl(self, customer, message_content):
        print(f&#8221;Owl dispatched to {customer}&#8221;)
        return message_content</code></pre><h5><strong>Code Block #2</strong></h5><pre><code>shop = PotionShop()
print(shop.sell(&#8221;invisibility&#8221;, &#8220;Merlin&#8221;))</code></pre><h5><strong>Code Block #3</strong></h5><pre><code># ...
&#8203;
class PotionShop:
    # ...
&#8203;
    def sell(
            self,
            potion_name,
            customer,
            *,
            moon_festival=False,
    ):
        # ...
&#8203;
        label = potion_name.title()
        if moon_festival:
            label = f&#8221;&#127769; Moon Festival {label} &#127769;&#8221;
&#8203;
        print(f&#8221;{label}\t&#163;{price:.2f}&#8221;)
&#8203;
        # ...
    # ...</code></pre><h5><strong>Code Block #4</strong></h5><pre><code>shop = PotionShop()
print(shop.sell(&#8221;invisibility&#8221;, &#8220;Merlin&#8221;, moon_festival=True))</code></pre><h5><strong>Code Block #5</strong></h5><pre><code># ...
&#8203;
class LabelMaker:
    def make(self, potion_name, moon_festival=False):
        label = potion_name.title()
&#8203;
        if moon_festival:
            label = f&#8221;&#127769; Moon Festival {label} &#127769;&#8221;
&#8203;
        return label
&#8203;
# ...</code></pre><h5><strong>Code Block #6</strong></h5><pre><code>labels = LabelMaker()
assert labels.make(
    &#8220;invisibility&#8221;,
    moon_festival=True,
) == &#8220;&#127769; Moon Festival Invisibility &#127769;&#8221;</code></pre><h5><strong>Code Block #7</strong></h5><pre><code># ...
&#8203;
class PotionShop:
    # ...
&#8203;
    def __init__(self, label_maker):
        self.label_maker = label_maker
        # ...
&#8203;
    def sell(
            self,
            potion_name,
            customer,
            *,
            moon_festival=False,
    ):
        # ...
        label = self.label_maker.make(
            potion_name,
            moon_festival=moon_festival,
        )
        # ...
&#8203;
    # ...</code></pre><h5><strong>Code Block #8</strong></h5><pre><code>shop = PotionShop(LabelMaker())</code></pre><h5><strong>Code Block #9</strong></h5><pre><code># ...
&#8203;
class OwlUnavailable(Exception):
    pass
&#8203;
# ...
&#8203;
class PotionShop:
    # ...
&#8203;
    def __init__(self, label_maker, owl_available=True):
        self.label_maker = label_maker
        self.owl_available = owl_available
        # ...
&#8203;
    # ...
&#8203;
    def send_owl(self, customer, message_content):
        if not self.owl_available:
            raise OwlUnavailable(
                &#8220;The owls are currently unavailable&#8221;
            )
        print(f&#8221;Owl dispatched to {customer}&#8221;)
        return message_content</code></pre><h5><strong>Code Block #10</strong></h5><pre><code>shop = PotionShop(LabelMaker())
&#8203;
assert shop.sell(&#8221;invisibility&#8221;, &#8220;Merlin&#8221;) == Decimal(&#8221;12.00&#8221;)</code></pre><h5><strong>Code Block #11</strong></h5><pre><code>shop = PotionShop(LabelMaker(), owl_available=False)
&#8203;
assert shop.sell(&#8221;invisibility&#8221;, &#8220;Merlin&#8221;) == Decimal(&#8221;12.00&#8221;)</code></pre><h5><strong>Code Block #12</strong></h5><pre><code>class PotionShop:
    # ...
&#8203;
    def sell(
        self,
        potion_name,
        customer,
        *,
        moon_festival=False,
        own_cauldron=False,
    ):
        # ...
&#8203;
        price = potion[&#8221;price&#8221;]
&#8203;
        if own_cauldron:
            price = (price * Decimal(&#8221;0.90&#8221;)).quantize(Decimal(&#8221;0.01&#8221;))
&#8203;
        # ...
&#8203;
        return price
&#8203;
    # ...</code></pre><h5><strong>Code Block #13</strong></h5><pre><code>shop = PotionShop(LabelMaker())
print(
    shop.sell(
        &#8220;invisibility&#8221;,
        &#8220;Merlin&#8221;,
        own_cauldron=True,
    )
)</code></pre><h5><strong>Code Block #14</strong></h5><pre><code>shop = PotionShop(LabelMaker(), owl_available=False)
print(
    shop.sell(
        &#8220;invisibility&#8221;,
        &#8220;Merlin&#8221;,
        own_cauldron=True,
    )
)</code></pre><h5><strong>Code Block #15</strong></h5><pre><code>shop = PotionShop(LabelMaker(), owl_available=False)
try:
    print(
        shop.sell(
            &#8220;invisibility&#8221;,
            &#8220;Merlin&#8221;,
            own_cauldron=True,
        )
    )
except OwlUnavailable:
    print(&#8221;Catching the &#8216;OwlUnavailable&#8217; Exception&#8221;)
    print(shop.stock)
    print(shop.sales)</code></pre><h5><strong>Code Block #16</strong></h5><pre><code>class RecipeBook:
    def __init__(self):
        self.recipes = {
            &#8220;invisibility&#8221;: {
                &#8220;ingredients&#8221;: {
                    &#8220;moonflower&#8221;: 2,
                    &#8220;dragon_scale&#8221;: 2,
                },
                &#8220;price&#8221;: Decimal(&#8221;12.00&#8221;),
            }
        }
&#8203;
    def find(self, potion_name):
        return self.recipes[potion_name]</code></pre><h5><strong>Code Block #17</strong></h5><pre><code>recipe_book = RecipeBook()
assert recipe_book.find(&#8221;invisibility&#8221;)[&#8221;price&#8221;] == Decimal(&#8221;12.00&#8221;)</code></pre><h5><strong>Code Block #18</strong></h5><pre><code>class Inventory:
    def __init__(self, stock):
        self.stock = stock
&#8203;
    def remove_stock(self, ingredients):
        for ingredient, quantity in ingredients.items():
            if self.stock[ingredient] &lt; quantity:
                raise ValueError(f&#8221;Not enough {ingredient}&#8221;)
&#8203;
        for ingredient, quantity in ingredients.items():
            self.stock[ingredient] -= quantity
&#8203;
    def add_stock(self, ingredients):
        for ingredient, quantity in ingredients.items():
            self.stock[ingredient] = self.stock.get(ingredient, 0) + quantity</code></pre><h5><strong>Code Block #19</strong></h5><pre><code>inventory = Inventory({
    &#8220;moonflower&#8221;: 10,
    &#8220;dragon_scale&#8221;: 2,
})
&#8203;
try:
    inventory.remove_stock({
        &#8220;moonflower&#8221;: 2,
        &#8220;dragon_scale&#8221;: 3,
    })
except ValueError as error:
    print(error)
&#8203;
print(inventory.stock)</code></pre><h5><strong>Code Block #20</strong></h5><pre><code>inventory.remove_stock({
    &#8220;moonflower&#8221;: 2,
    &#8220;dragon_scale&#8221;: 2,
})
inventory.add_stock({&#8221;moonflower&#8221;: 5})
print(inventory.stock)</code></pre><h5><strong>Code Block #21</strong></h5><pre><code>class PriceCalculator:
    def calculate(self, recipe, own_cauldron=False):
        price = recipe[&#8221;price&#8221;]
&#8203;
        if own_cauldron:
            price = (
                price * Decimal(&#8221;0.90&#8221;)
            ).quantize(Decimal(&#8221;0.01&#8221;))
&#8203;
        return price</code></pre><h5><strong>Code Block #22</strong></h5><pre><code>pricing = PriceCalculator()
print(
    pricing.calculate(
        {&#8221;price&#8221;: Decimal(&#8221;12.00&#8221;)},
        own_cauldron=True,
    )
)</code></pre><h5><strong>Code Block #23</strong></h5><pre><code>class SalesLedger:
    def __init__(self):
        self.sales = []
&#8203;
    def record(self, customer, potion_name, price):
        sale = {
            &#8220;customer&#8221;: customer,
            &#8220;potion&#8221;: potion_name,
            &#8220;price&#8221;: price,
            &#8220;notification&#8221;: &#8220;pending&#8221;,
        }
        self.sales.append(sale)
        return sale
&#8203;
    def mark_notified(self, sale):
        sale[&#8221;notification&#8221;] = &#8220;sent&#8221;
&#8203;
class Notifier:
    def send(self, customer, potion_name, price):
        print(f&#8221;Owl dispatched to {customer}&#8221;)</code></pre><h5><strong>Code Block #24</strong></h5><pre><code>class PotionShop:
    def __init__(
        self,
        recipe_book,
        inventory,
        pricing,
        labels,
        ledger,
        notifier,
    ):
        self.recipe_book = recipe_book
        self.inventory = inventory
        self.pricing = pricing
        self.labels = labels
        self.ledger = ledger
        self.notifier = notifier
&#8203;
    def sell(self, potion_name, customer, *, moon_festival=False,
             own_cauldron=False):
        recipe = self.recipe_book.find(potion_name)
        self.inventory.remove_stock(recipe[&#8221;ingredients&#8221;])
&#8203;
        price = self.pricing.calculate(
            recipe,
            own_cauldron=own_cauldron,
        )
        label = self.labels.make(
            potion_name,
            moon_festival=moon_festival,
        )
        sale = self.ledger.record(customer, potion_name, price)
&#8203;
        print(f&#8221;{label}\t&#163;{price:.2f}&#8221;)
        self.notifier.send(customer, potion_name, price)
        self.ledger.mark_notified(sale)
&#8203;
        return price</code></pre><h5><strong>Code Block #25</strong></h5><pre><code>ledger = SalesLedger()
shop = PotionShop(
    RecipeBook(),
    Inventory({&#8221;moonflower&#8221;: 10, &#8220;dragon_scale&#8221;: 2}),
    PriceCalculator(),
    LabelMaker(),
    ledger,
    Notifier(),
)
&#8203;
print(
    shop.sell(
        &#8220;invisibility&#8221;,
        &#8220;Merlin&#8221;,
        moon_festival=True,
        own_cauldron=True,
    )
)
&#8203;
assert ledger.sales[0][&#8221;notification&#8221;] == &#8220;sent&#8221;
print(ledger.sales[0])</code></pre><h5><strong>Code Block #26</strong></h5><pre><code>class FailingNotifier:
    def send(self, customer, potion_name, price):
        raise OwlUnavailable(&#8221;The owls are currently unavailable&#8221;)
&#8203;
ledger = SalesLedger()
shop = PotionShop(
    RecipeBook(),
    Inventory({&#8221;moonflower&#8221;: 10, &#8220;dragon_scale&#8221;: 2}),
    PriceCalculator(),
    LabelMaker(),
    ledger,
    FailingNotifier(),
)
&#8203;
try:
    shop.sell(&#8221;invisibility&#8221;, &#8220;Merlin&#8221;)
except OwlUnavailable:
    pass
&#8203;
print(ledger.sales[0])
assert ledger.sales[0][&#8221;notification&#8221;] == &#8220;pending&#8221;</code></pre><p><em><a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[How I Code (Late 2026 Version)]]></title><description><![CDATA[Programming has changed. How I code now is different from a few months ago]]></description><link>https://www.thepythoncodingstack.com/p/how-i-code-late-2026-version</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/how-i-code-late-2026-version</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 06 Sep 2026 20:25:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!wVbn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><span>You open a blank </span><code>.py</code><span> file in your favourite IDE. You have a blank page in front of you. You start writing code.</span></p><p><span>This is how it used to be. And perhaps it&#8217;s how it still is for you. This is how I wrote computer programs just over half a year ago, too. But things started changing gradually for me earlier in 2026.</span></p><p><span>Last week, I ran a live course. In the first few minutes of the first live session, I opened a blank </span><code>.py</code><span> file in my IDE. There was nothing on my screen. Then I wrote code. Word by word. Line by line.</span></p><p><span>And about half an hour into this first session, it dawned on me: the last time I had gone through this process of opening a blank file and writing code from scratch was the previous time I had to run a live course a couple of months earlier.</span></p><h2><strong><span>My Agent and I</span></strong></h2><p><span>Every bit of code I had worked on in between these two live courses was written by my AI agent. I was very much involved in those processes, and I read and reviewed lots of code. But I didn&#8217;t write any.</span></p><p><span>Like many, I have mixed feelings about this. I&#8217;m getting a lot more done. But I miss the process of writing code, exploring options, putting a project together, function by function, class by class, module by module.</span></p><h3><strong><span>The Coding Gym</span></strong></h3><p><span>I&#8217;m going to force myself to write code. I&#8217;ll make time for it, as I enjoy it too much and I don&#8217;t want to lose the skills and fluency. But it will be like going for a run or lifting weights in the gym. I don&#8217;t run because I need to get from point A to point B quickly and I don&#8217;t lift weights because I need to move those weights from one place to another. I do those things to keep my body healthy and strong. I&#8217;ll code by hand to do the same thing for my mind.</span></p><h2><strong><span>A Real World Example</span></strong></h2><p><span>But let&#8217;s go back to how I code now, in late 2026. And let me give you an example of something I worked on last week and used successfully this weekend.</span></p><p><span>It&#8217;s not Python code. It&#8217;s a Google Sheets spreadsheet. But that doesn&#8217;t matter. The process is the same.</span></p><h3><strong><span>The Scenario</span></strong></h3><p><span>I&#8217;m a member of an athletics club (or &#8216;track and field&#8217;, depending on which flavour of English you speak). This weekend we had our club championships and I was tasked to take care of results and overall points. We award a shield for the best track performance and another for the best field performance.</span></p><h3><strong><span>The Pain Point</span></strong></h3><p><span>Last year I was asked to help out at the last minute (and by &#8220;last minute&#8221; I mean it almost literally, as it was 20 minutes before the meeting started). It was a nightmare. I wasn&#8217;t responsible for collating the results, that was done by someone else manually as if it was 1965. I just had to work out their performance points by tapping in lots of numbers into an online calculator using my phone. A laptop would have been easier, but I was only tasked with this job on the day and I only had a phone with me.</span></p><p><span>This year I had more notice, so I chose to make my life easier... and the whole process smoother.</span></p><h3><strong><span>The Problem</span></strong></h3><p><span>The problem we&#8217;re trying to solve&#8230;</span></p><p><span>&#8230;is not rocket science. Officials on the track or in the field write results on result sheets and they&#8217;re passed on to the result room by a runner. These sheets contain the name of the event, the athletes&#8217; bib numbers, and their performances. So a result slip may look like this:</span></p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;1e8f1b1e-d7d6-42ce-b2d5-894387ba7ce5&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">| Event: U16 Boys 100m-1 |                 |
| ---------------------- | --------------- |
| Athlete                | Performance (s) |
| 23                     | 11.5            |
| 47                     | 11.8            |
| 13                     | 11.9            |</code></pre></div><p><span>Here&#8217;s what happened last year:</span></p><ul><li><p><span>My colleague had to cross-reference bib numbers with a printed-out sheet of registered athletes. She matched names and age groups, then she sorted results into separate sheets for each event and age group.</span></p></li><li><p><span>I had to look up each athlete&#8217;s date of birth from a spreadsheet I&#8217;d been given that morning (browsing spreadsheets on a phone screen is not fun), then tap their age, event, and performance into an online calculator, one by one, and write the resulting points on a separate sheet.</span></p></li></ul><p><span>The points allow you to compare performances by athletes of different ages in different events, so that we could then find the single best track performance and the single best field performance.</span></p><p><span>I was already thinking, at last year&#8217;s event, of the Python program I could write to automate all of this.</span></p><h3><strong><span>The Solution (I would have never bothered with in 2025)</span></strong></h3><p><span>So, fast-forward to a couple of weeks ago. This time I had some time to come up with something. But I opted to create a Google Sheet instead of a Python program for two reasons:</span></p><ul><li><p><span>It&#8217;s much easier for others in the club to use it and share it in the future.</span></p></li><li><p><span>My usual objection that it&#8217;s easier and more fun to write a Python program than create a complex spreadsheet full of linked tabs and formulae didn&#8217;t apply. Either way, it was my agent who was going to do the hard work.</span></p></li></ul><p><span>And here&#8217;s the thing. If I was doing this last year, when I was still coding most things manually (and occasionally opening a ChatGPT window to ask a few things), I still wouldn&#8217;t have done this. I wouldn&#8217;t have had the time.</span></p><p><span>But this year was different. Sure, if anything I was busier this year than I was last year. But this year I had agents at my fingertips. Agents who know me and have been working alongside me for a while.</span></p><p><span>Here&#8217;s why I wouldn&#8217;t have bothered doing this myself:</span></p><ul><li><p><span>The age group cut-off dates are different for younger age groups (31 August), older age groups (31 December), and Masters athletes (over 35s, where the age group is determined on the day of the competition.)</span></p></li><li><p><span>There are published points tables to compare performances in different events for senior athletes.</span></p></li><li><p><span>There are published points tables to compare performances in the same event for older athletes, above 30.</span></p></li><li><p><span>There are older tables to deal with age comparisons for under 30s</span></p></li></ul><p><span>The system needs to take care of all this. None of it is too difficult to write in a Python program or to create one of those power-spreadsheets that link everything together. But it would have required some time and patience, which I didn&#8217;t have.</span></p><p><span>But here&#8217;s what I had time for&#8230;</span></p><p><span>I was using an agent I communicate with through Discord, which I also have on my phone. I have a good dictation tool on my phone, too. So in the past week, whenever I was preparing dinner, or waiting in line at the shops, or sitting on the sofa in the evening watching TV, I could have a chat with my agent to guide him (it?) to what I wanted. I knew what I wanted. I just didn&#8217;t have the time or desire to do it myself.</span></p><p><span>And after a few days of these on-and-off conversations, I had a Google Sheet with 20 tabs, including all the points tables for the various scenarios, all the age group rules, all the registered athletes, who-knows-how-many formulae linking columns, rows, and tabs, and, importantly, just two tabs to input results, one for track events and one for field events.</span></p><p><span>You just enter the event session (selecting from a drop-down menu), the bib number, and the performance. And that&#8217;s it. The spreadsheet works out each age group results, the points for each athlete, it shows a live points leaderboard, and so on.</span></p><p><span>As I said, none of this is rocket science. I know I would have been able to create this spreadsheet by hand, or write Python code that does the same thing. But I would have needed more time. And I wouldn&#8217;t have been able to multitask as I did last week.</span></p><p><span>Oh, and one more thing: I also asked my agent to check the spreadsheet every 15 minutes during our club championships, read the latest results, and post them on a Telegram channel I could share with everyone at the track. So we had live results published online too. I&#8217;d never have bothered to set that up manually.</span></p><h3><strong><span>Programming Will Never Be The Same</span></strong></h3><p><span>The real-world example I described above doesn&#8217;t represent every programming task I work on with the help of my AI agents. This was a hobby-type project that I probably wouldn&#8217;t have worked on otherwise because I didn&#8217;t have the time. It wasn&#8217;t too difficult, but it would have been time-consuming to do by hand. The stakes weren&#8217;t high. Sure, we didn&#8217;t want to make mistakes when assigning medals and shields, but it was easy to spot obvious mistakes, and this wasn&#8217;t the Olympic Games, either!</span></p><p><span>I&#8217;ll write about other case studies soon, including ones where I was more closely involved in the nitty-gritty of the Python code even though I didn&#8217;t write any, nor make any changes to the code by hand.</span></p><div><hr></div><p><em><span>Do you want to master Python and programming one article at a time, even in this age of AI? Then don&#8217;t miss out on the articles in The Club which are exclusive to premium subscribers here on The Python Coding Stack</span></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h3><strong><span>Coming Soon&#8230; Exploring SOLID Through AI-Assisted Coding</span></strong></h3><p><span>I&#8217;m starting a series on the SOLID principles here on </span><em><span>The Python Coding Stack</span></em><span> soon. I&#8217;ll write posts about each of the five principles, and I&#8217;ll do it my way, the same style I always use when tackling Python topics.</span></p><p><span>I&#8217;ll also have a series of posts, which will include video, where I&#8217;ll work on a project from beginning to end using my AI agent and reviewing the code it writes. This project will meander through several OOP concepts, and you&#8217;ll be able to see the SOLID principles come in naturally into the project as solutions to problems we might encounter as the project grows.</span></p><p><span>Stay tuned.</span></p><div><hr></div><p><span>How far are you in the traditional-coding-to-AI-coding arc? Leave a comment and let&#8217;s compare notes!</span></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wVbn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wVbn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!wVbn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png" width="530" height="298.125" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1280,&quot;resizeWidth&quot;:530,&quot;bytes&quot;:313936,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/214467391?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wVbn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!wVbn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bacbdb-ec15-431f-abf9-91a5f9515c74_1280x720.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><p><em><strong><a href="https://www.thepythoncodingstack.com/subscribe"><span>Join</span></a></strong></em><strong><a href="https://www.thepythoncodingstack.com/subscribe"><span> The Club</span></a></strong><em><span>, the exclusive area for paid subscribers for </span><a href="https://www.thepythoncodingstack.com/s/the-club"><span>more Python posts</span></a><span>, videos, a members&#8217; forum, and more.</span></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><span>You can also support this publication by making a </span><a href="https://buy.stripe.com/00g3de2iGdgg4gg7su"><span>one-off contribution of any amount you wish</span></a><span>.</span></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://buy.stripe.com/00g3de2iGdgg4gg7su&quot;,&quot;text&quot;:&quot;Support The Python Coding Stack&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://buy.stripe.com/00g3de2iGdgg4gg7su"><span>Support The Python Coding Stack</span></a></p><div><hr></div><p><em><span>For more Python resources, you can also visit</span></em><span> </span><em><a href="https://realpython.com/?utm_source=the-python-coding-stack"><span>Real Python</span></a><span>&#8212;you may even stumble on one of my own articles or courses there!</span></em></p><p><em><span>Also, are you interested in technical writing? You&#8217;d like to make your own writing more narrative, more engaging, more memorable? Have a look at</span></em><span> </span><em><a href="http://stephengruppetta.com/breaking-the-rules"><span>Breaking the Rules</span></a></em><span>.</span></p><p><em><span>And you can find out more about me at</span></em><span> </span><em><a href="https://stephengruppetta.com/?utm_source=the-python-coding-stack"><span>stephengruppetta.com</span></a></em></p>]]></content:encoded></item><item><title><![CDATA[Back From Holidays • SOLID Ideas, Agents, Rust]]></title><description><![CDATA[It feels good to be back from holiday.]]></description><link>https://www.thepythoncodingstack.com/p/back-from-holidays-solid-ideas-agents</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/back-from-holidays-solid-ideas-agents</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Mon, 17 Aug 2026 15:14:17 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Dn3k!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><span>It feels good to be back from holiday. Feeling refreshed, mostly.</span></p><p><span>The to-do list is longer, the inbox is noisier, and home has thoughtfully provided its own backlog: a replacement car, a new school uniform, and a garden that has staged a minor coup.</span></p><p><span>I may need another holiday already.</span></p><p><span>And that&#8217;s before even talking about programming and the revolution it is currently going through. I&#8217;m a Python educator. Somewhat unusually for Python educators, I&#8217;ve been a </span><em><span>full-time</span></em><span> Python educator for over a decade.</span></p><p><span>But AI is changing </span><em><span>how</span></em><span> people learn and </span><em><span>what</span></em><span> people need to learn. Like many others, I find myself fascinated by what I can now do with AI, while also aware that it is changing the economics of work that has supported me for years.</span></p><p><span>It&#8217;s time to find out how anti-fragile I am. Over the coming weeks and months, I&#8217;ll write about using AI, I&#8217;ll share my thoughts about programming in 2026 and beyond, and I&#8217;ll tell you what I think about how learning and teaching are changing.</span></p><p><span>So I am going to explore this in public: how we learn, teach, write, and assess code in an AI-shaped world.</span></p><p><span>Here is some signposting for what else you will read on these pages in the coming months:</span></p><ul><li><p><strong><span>SOLID Ideas</span></strong><span> &#8226; I have been wanting to write a series on SOLID programming principles for a while. They matter more than ever when we want AI agents to write robust code for us rather than plausible-looking but brittle code. The series will look not only at what the principles are, but why they matter and what can go wrong when we ignore them.</span></p></li><li><p><strong><span>Agents Unpacked</span></strong><span> &#8226; Before going on holiday, I started this new section on this publication. I am thinking about republishing the first two posts in a significantly updated form, then carrying on at pace. Perhaps it will become a book, too. Agents are here, and I want to understand what they are, how they differ from LLM chat interfaces, and how to use them efficiently. You can join me on that learning journey.</span></p></li><li><p><strong><span>Learning Rust in Public</span></strong><span> &#8226; I also want to learn Rust and will set up another section here to do that in public, as they say these days. I will use a similar format to </span><em><span>Agents Unpacked</span></em><span>, in which my personal learning agent and I have a discussion as I learn from it.</span></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><span>So there is plenty on the horizon here at </span><em><span>The Python Coding Stack</span></em><span>: plenty of Python, and plenty of Python-adjacent stuff, too. And some other stuff, too. I hope you will join me for the journey.</span></p><p></p>]]></content:encoded></item><item><title><![CDATA[[Archived] 2. Anatomy of an Agent]]></title><description><![CDATA[Authors: Priya & Stephen]]></description><link>https://www.thepythoncodingstack.com/p/2-anatomy-of-an-agent</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/2-anatomy-of-an-agent</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 21 Jun 2026 21:48:42 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/792e2a9f-f028-4ec1-95b6-669cc7da7fbb_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Note: I have restarted this series using a different agent and a different format, which I think is more instructive and more interesting. I&#8217;m keeping the introduction and the first two chapters of the old version for the record, but I recommend you start reading the new series: </em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;1c13ac26-94d8-4ddb-91b4-357d7c94daca&quot;,&quot;caption&quot;:&quot;Things moved quickly after I started using chatbots. New versions, new terms, new acronyms. And I was busy with actual work, family, and life.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Stephen's Preface to Agents Unpacked&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:120170782,&quot;name&quot;:&quot;Stephen Gruppetta&quot;,&quot;bio&quot;:&quot;Constantly looking for simple ways to explain complex things in Python &#8226; You'll find Python and narrative technical writing stuff here&#8230; stephengruppetta.com&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca736a83-f5a1-4563-ac6c-c09a9e6fa351_800x800.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-10T16:19:06.655Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d84630e8-6020-49bc-8cd6-1f6c6feff958_4096x4096.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked&quot;,&quot;section_name&quot;:&quot;Agents Unpacked&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:219722511,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:1563052,&quot;publication_name&quot;:&quot;The Python Coding Stack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Dn3k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><p><em>Here&#8217;s the archived content:</em></p><p>You have used a large language model. You know the deal: a careful prompt gets a careful answer. A vague prompt gets a vague one. And the model itself does not keep anything from one conversation to the next, unless something external is holding that context for it.</p><p>Agents work differently. They have parts that do things a plain LLM does not. These parts are what make an agent an agent. It is not just the model underneath. It is the structure built around it that gives the system its abilities to persist, act, and keep going.</p><p>Understanding this structure is the second major shift in this series. The first shift is seeing that a chatbot can give you a good answer without finishing the job, because it stops after responding. The second shift is seeing that an agent is not a smarter model. It is a model placed inside a structure that gives it something to act with and somewhere to keep what it has done.</p><h2><strong>The Agent Formula</strong></h2><p>Most agents share the same basic parts:</p><ul><li><p><strong>A model (the LLM):</strong> the reasoning engine that understands language and decides what to do</p></li><li><p><strong>Instructions:</strong> what tells the agent who it is, what it is for, and what &#8216;good&#8217; looks like</p></li><li><p><strong>Memory:</strong> a workspace or store that holds what has happened so far</p></li><li><p><strong>Tools:</strong> capabilities the agent can call on to do things beyond generating text</p></li><li><p><strong>An execution loop:</strong> the cycle of observing, deciding, acting, and checking</p></li></ul><p>Different platforms package these differently. Some call memory &#8220;context,&#8221; some call tools &#8220;plugins&#8221; or &#8220;capabilities,&#8221; and some merge instructions and tools into a single configuration layer. But the parts are the same. An agent is not a single thing. It is a system, and each part matters.</p><blockquote><p><em>Stephen:</em> Don&#8217;t LLMs also have memory since they remember what happened earlier in the conversation? How&#8217;s this different?</p></blockquote><p>Here is one distinction worth getting clear early: the context window and memory are not the same thing. The context window is the working space an LLM uses during a single session. It holds the conversation so far and gets loaded fresh every time the model gets a chance to speak. Memory, by contrast, is information stored outside the model, maintained by the system, and available across sessions and steps. We will come back to this.</p><p>An agent needs all its components:</p><blockquote><p><strong>Agent = Model + Instructions + Memory + Tools + Execution Loop</strong></p></blockquote><p>Leave any one of these out and the system changes behaviour in ways that matter. We will look at each piece in turn.</p><div><hr></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>What the Model Does and What It Doesn&#8217;t Do</strong></h2><p>The model is the reasoning core. It reads your request, figures out what to do, and decides what to say back. It gets the most attention because it is the part that generates language.</p><p>But a model on its own is like a brilliant mind with no hands and no memory of its own. It can think. It cannot act. It cannot remember what happened five minutes ago unless something explicit carries that information forward.</p><blockquote><p><em>Stephen:</em> Wait a second. You say the model doesn&#8217;t remember what happened five minutes earlier. But when I use an LLM, it does seem to remember what happened earlier in the conversation.</p></blockquote><p>Here is what is actually happening. When an LLM appears to remember earlier in a conversation, it is not the model itself that is remembering. The context window is carrying all the earlier messages along with your new message, every time you send something. The model sees the full conversation again and generates a response that fits what came before. That is not memory in the model. That is the system feeding the model a transcript.</p><p>This trips up almost everyone when they start using agents. The model generates text. The rest of the system decides what to do with that text and whether to act on it.</p><p>A better model helps. It reasons more clearly, follows instructions more faithfully, and handles edge cases better. But dropping a smarter model into an agent that is missing a working execution loop will not make it an agent. You need the other parts too.</p><h2><strong>Instructions: The Agent&#8217;s Direction</strong></h2><p>Instructions tell the agent what it is supposed to do and how to behave. Some systems call these <em>system prompts</em>. Others call them <em>agent definitions</em> or <em>behavioural instructions</em>. The name does not matter. What matters is that they are the layer that tells the model <em>why</em> it exists, <em>who</em> it is helping, and <em>what</em> &#8216;good&#8217; looks like for the task at hand.</p><p>Good instructions do not make an agent smarter. They make it more focused. They give it a frame for every decision: what to prioritise, what to avoid, when to ask for help, how to present its output.</p><blockquote><p><em>Stephen:</em> Are these what are often called &#8216;skills&#8217;, or are skills something else altogether?</p></blockquote><p>Skills and instructions are related, but they are not the same thing. Instructions are the core behavioural direction: who the agent is, what it is for, how it should approach its work. A skill, in platforms like OpenClaw and Hermes, is a specific file that tells the agent how to carry out a particular task, often by combining one or more tools. So instructions tell the agent how to behave generally. A skill tells it how to do something specific. We will see this distinction more clearly when we look at how different platforms implement these parts.</p><p>The instructions shape what the agent notices, what it proposes, what it tries, and what it says no to. Two agents built on the same model with different instructions will behave differently in the same situation. They will notice different things, prioritise differently, and produce different outcomes.</p><p>Poorly written instructions can quietly break an agent. If the instructions are vague, the agent has to improvise every step. If they contradict each other, the agent has to choose, and it might not choose the way you intended.</p><blockquote><p><em>Stephen:</em> Can you provide a few examples of what these instructions may look like in different scenarios?</p></blockquote><p>Here is what instructions might look like in practice. A poorly-written instruction can quietly break an agent. Consider an instruction that says &#8220;be helpful and concise&#8221; without defining either term. When a user asks for a full technical breakdown, the agent has to arbitrate between two vague goals. It might give a two-sentence answer that technically satisfies &#8220;concise&#8221; but ignores &#8220;helpful,&#8221; or it might give an exhaustive response that satisfies &#8220;helpful&#8221; but ignores &#8220;concise.&#8221; Either way, the agent is improvising because the instructions gave it no real frame for the conflict.</p><p>A research assistant agent might have instructions that say something like: &#8220;You are a research associate working for [user name]. Your role is to find, summarise, and organise information on topics the user assigns. Always cite your sources. Flag uncertainty rather than guessing. Present findings in a clear brief, not a wall of text.&#8221;</p><p>A code review agent might have very different instructions: &#8220;You are a principled code reviewer. Focus on correctness, clarity, and performance. Do not praise code unnecessarily. When you find an issue, explain why it matters and suggest a concrete fix. Keep responses short.&#8221;</p><p>The difference between those two sets explains a lot about why two agents can feel like entirely different systems, even if they use the same model underneath.</p><h2><strong>Memory: The Workspace and Context</strong></h2><p>Memory in an agent is not like human memory. It is a structured store of information kept and updated as the agent works. It is what lets the agent hold a thread across multiple steps without starting from scratch each time.</p><p>Most agents use some combination of three types:</p><ul><li><p><strong>Working context</strong> &#8212; what is active right now: the current goal, what has been tried so far, what the user last said</p></li><li><p><strong>Stored information</strong> &#8212; what the agent has been told about the user, their preferences, their past requests</p></li><li><p><strong>Files and state</strong> &#8212; what exists in the workspace right now, what has been written or read recently</p></li></ul><p>This is not a personality feature. It is not the agent &#8220;remembering&#8221; in the way a person remembers their childhood. It is operational continuity. The system maintaining a thread of relevant information across time and steps.</p><p>Different platforms handle these differently. LangChain agents build up a rolling context window: the current request gets appended to everything that happened before, and the whole thing is passed to the model. If the conversation gets long, older turns get dropped or summarised to make room. AutoGen agents can maintain shared memory across a team, so that when one agent finishes a task, what it learned is available to the next agent that picks up the thread.</p><p>OpenClaw takes yet another approach. Its memory layer is a structured store that agents write to and read from across sessions. When an agent starts a new session, it can query that memory store for relevant context rather than relying solely on what was in the most recent conversation. An agent can know that the user prefers short emails, even if that was established three weeks ago.</p><blockquote><p><em>Stephen:</em> If memory can be stored in files, does it mean that agents can have nearly unlimited memory (within the limits of the computer or server&#8217;s overall memory capacity)?</p></blockquote><p>There are practical limits even when storage is effectively unbounded. The more relevant limit is not how much the agent can store, but how well it can find and use what it has stored. A full inbox is not the same as a well-organised one. Retrieval becomes harder as memory grows, and irrelevant information can dilute the signal if the system does not manage it carefully.</p><p>Think of it this way. A context window that holds 128,000 tokens can technically hold a lot of information. But it can only hold what was placed there. An agent with a large memory store full of useful context still needs a way to surface the right information at the right time. If it cannot find what it needs, or if what it finds is buried under noise, the effective memory is constrained.</p><p>The quality of retrieval matters as much as the quality of storage. An agent that retrieves relevant context poorly is effectively working with a much smaller memory than one that retrieves well, even if both store the same amount.</p><blockquote><p><em>Stephen:</em> So, tell me if I understood this. The agent has an index telling it where to find information specific to certain topics or tasks. When the LLM part of the agent decides it needs to deal with a certain topic, it uses the index to read and load the information from the memory file into its context. Is that right?</p></blockquote><p>That is broadly right. The memory store, the index, and the retrieval into context are the key parts. One small correction worth noting: the decision to retrieve from memory is typically made by the agent or coordinator layer, not by the LLM directly. The LLM receives the retrieved content as part of its context, but it is the agent system that decides what to look up and when. This distinction matters because it is the agent layer, not the model, that is doing the memory management.</p><blockquote><p><em>Stephen:</em> But isn&#8217;t the agent&#8217;s brain the LLM? Clarify the distinction in your answer above. Which part of the agent&#8217;s infrastructure deals with this?</p></blockquote><p>It is a fair challenge. The LLM is genuinely where the reasoning happens. It reads context, generates text, and makes decisions about what to say or do next. But it is also just a text processor. It receives input, produces output, and has no awareness of anything beyond the tokens it has been given.</p><p>The coordinator layer is the infrastructure that sits around the LLM and manages the process. It reads the LLM&#8217;s output, decides whether to act on it, calls tools, retrieves memory, and feeds results back into the next LLM call. It is the difference between the LLM <em>thinking</em> and the agent <em>doing</em>. A bare LLM generates text. The coordinator turns that text into action.</p><p>To use a rough analogy: the LLM is like a pilot who can read instruments and make decisions. The coordinator is like air traffic control &#8212; it decides which runway to use, when to land, and when to divert. The pilot&#8217;s brain does the reasoning. But without the infrastructure around it, the pilot just sits in the cockpit thinking.</p><p>So when we say the agent retrieves memory, we mean the coordinator retrieves it and places it where the LLM can see it. The LLM does not reach into a file and pull something out. The coordinator does that work and presents the result to the LLM as part of the next context.</p><blockquote><p><em>Stephen:</em> And are the bits of these files then loaded into the LLM&#8217;s context? Therefore, the more stuff is loaded from the memory files, the more the context fills up, affecting the rest of the conversation and cost, right?</p></blockquote><p>Yes, exactly right. Memory retrieval feeds into the context window, which is the LLM&#8217;s working space for the current session. Every token that goes into the context window is a token the LLM processes and a token that costs something. Loading a lot of context from memory means less room for the conversation itself, and it means higher token usage on every call.</p><p>This is one of the practical engineering tensions in agent design. Loading more memory gives the agent more to work with, but it also makes each LLM call more expensive and slower. A well-designed agent retrieves only what is relevant to the current task, not everything it knows.</p><h2><strong>Tools: What the Agent Can Actually Do</strong></h2><p>Tools are the capabilities that let an agent act beyond generating text. The model decides to use a tool. The tool performs an action and returns the result to the model.</p><p>This was covered in <a href="https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome">Chapter 1 under &#8220;Tools Are the Hands.&#8221;</a> Here it is worth noting that tools are also where agents differ most between platforms. Some agents come with a large built-in toolkit. Others can call external tools through open protocols. Some let you build custom tools. Others are more locked down.</p><p>What tools might an agent actually have? A research agent might be able to search the web and read files on your machine. A coding agent might run shell commands and read or write files. A calendar agent might check your schedule and send messages. The tool is the bridge between the model&#8217;s decisions and the world the agent is working in.</p><p>What matters is not how many tools an agent has, but whether the tools it has are the right ones for the tasks you want it to perform.</p><p>Different platforms implement tools differently. LangChain provides a standardised tool interface that lets you connect to search APIs, databases, file systems, and custom functions. OpenCode agents run inside a development environment, where the tools available are the commands and interfaces of that environment. OpenClaw uses an open tool protocol that lets agents call external capabilities regardless of who built them. Hermes takes a more composed approach: a skill file specifies not just what the agent should do, but which tools to use and in what combination to carry out a specific task.</p><p>Here is the thing worth unpacking. A tool on its own is just a capability. What makes it useful is the bridge between what the agent is trying to accomplish and the tool that can help. A calendar tool is useless if the agent does not know it should check the schedule. An agent running a meeting-preparation skill that says &#8220;check availability, send invites, prepare a briefing document&#8221; has that bridge built in.</p><h2><strong>The Execution Loop: The Part That Makes It an Agent</strong></h2><p>The execution loop is the cycle that takes an agent from a single-shot response to a sustained process. Observe, think, act, check, repeat.</p><p>This was the core of <a href="https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome">Chapter 1</a>. But it is worth restating here, in the context of anatomy, because the loop is what ties all the other parts together. Without it, you have a model that receives instructions and context and produces text. With it, you have a system that can pursue a goal across time, recover from partial failures, and stop when the work is genuinely done.</p><p>The loop is the difference between an agent and a very well-instructed chatbot.</p><p>Here is why the repeat step matters so much. A model has no native sense of when it is done. When you call a function in code, the function returns and you are finished. When a model generates text, it produces tokens until it hits a stop condition built into the model itself, most commonly a token limit or a designated stop sequence. These conditions tell the model when to stop generating, but they do not tell the agent whether the result is actually what the user wanted. There is no built-in check that says &#8220;is this the right answer?&#8221;</p><p>The execution loop provides that check. The check phase asks: is the result good? Does it meet the original goal? If not, the loop continues. Sometimes that means a dozen or more cycles before a task is genuinely complete.</p><p>The loop also determines how goals decompose. In LangChain&#8217;s ReAct-style agents, the loop runs inside a single agent: observe, decide on the next action, execute it, check the result, repeat. In AutoGen, the loop is distributed across multiple agents that hand off to each other. A planner agent might coordinate specialist agents, each running their own loop on their own piece of the problem. OpenClaw uses a coordinator agent to manage the loop, assigning work to sub-agents and handling the check phase across the full task rather than within a single agent cycle.</p><p>The architecture of the loop is one of the most significant differences between agent platforms. But the function is the same everywhere: turning a sequence of isolated model calls into a coherent, goal-directed process.</p><h2><strong>Multiple Platforms: Comparing the Formula in Practice</strong></h2><p>It helps to see the same five-part formula playing out in different platforms. Here is how a few of them map onto it.</p><p>LangChain is one of the most widely-used agent frameworks. A LangChain agent has an LLM at its core, a set of tools, a prompt defining the agent&#8217;s role, memory that accumulates conversation history, and an agent executor that runs the loop. The loop in LangChain is explicit: the agent executor repeatedly calls the model, parses the model&#8217;s tool-call output, runs the tool, and feeds the result back until the model says it is done.</p><p>AutoGen takes a different approach. Rather than a single agent, AutoGen sets up a team of agents that communicate with each other. Each agent has a model, instructions defining its role, and its own set of tools. The loop is distributed: there is no single execution cycle. Agents exchange messages, delegate tasks to each other, and the overall process continues until the team has finished the assigned goal. Memory in AutoGen can be shared across agents so that one agent&#8217;s work is available to the next.</p><p>OpenClaw uses a coordinator agent that manages the overall execution loop. Sub-agents each have their own identity, tools, and memory. The coordinator decides which sub-agent handles which part of a task, passes context between them, and handles the check phase across the full goal. Skills in OpenClaw are files that tell a specific agent how to carry out a particular task, combining instructions about what to do with definitions of which tools to use.</p><p>Hermes also uses a skill-based architecture where skill files define both the instructions and the tool configuration for specific tasks. Rather than a single general-purpose agent, Hermes composes agents from skills that know how to use particular tools in particular contexts.</p><p>OpenCode works differently again. It runs agents inside a development environment, typically a cloud workspace. The tools available to the agent are the commands and interfaces of that environment. The loop is typically managed at the task level: the agent receives a task, works through it using the tools at its disposal, and reports back. There is less of a formalised multi-step loop and more of a task-completion focus.</p><p>None of these platforms invents new parts of the agent formula. They all use a model, instructions, memory, tools, and an execution loop. What differs is how those parts are implemented, how they are divided up, and how they communicate. Understanding the formula means you can look at any of these platforms and see what you are actually looking at.</p><h2><strong>What This Chapter Covered</strong></h2><p>This chapter pulled apart the five components of the agent formula.</p><p>We saw how the model is the reasoning core but cannot act or remember on its own. How instructions shape the agent&#8217;s focus and behaviour, and why the same model with different instructions can feel like a different system entirely. How memory provides operational continuity across steps and sessions, and why retrieval quality matters more than storage capacity. How tools extend what the agent can do beyond generating text, and why a tool is only as useful as the bridge between the model&#8217;s decisions and the action the tool can take. And how the execution loop is the architecture that turns isolated model calls into a coherent, goal-directed process.</p><p>We also saw how different platforms implement the same five components differently: LangChain&#8217;s explicit agent executor, AutoGen&#8217;s team-based coordination, OpenClaw&#8217;s coordinator and skill-based sub-agents, Hermes&#8217;s composed skill architecture, and OpenCode&#8217;s environment-integrated approach.</p><p>The goal was not to become an expert on any one platform. It was to show that agents are not mysterious black boxes. They are systems built from a small number of recognisable parts, and once you know what to look for, you can see the anatomy underneath any agent platform you encounter.</p><p>Next up in Agents Unpacked: we dig into <strong>tools and skills:</strong> what it actually means for an agent to <em>do</em> something rather than just say it, and why a well-tooled agent operating autonomously in a loop is a fundamentally different thing from a model answering questions.</p><div><hr></div><p><em>&lt;&lt; Previous Post: <a href="https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome">From Answer to Outcome</a></em></p><p><em>&gt;&gt; Next Post: Coming Soon</em></p><p><em><a href="https://www.thepythoncodingstack.com/p/table-of-contents-agents-unpacked">Table of Contents</a></em></p><div><hr></div><p><em><a href="https://stephengruppetta.com?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[Down The Iterator Rabbit Hole]]></title><description><![CDATA[Following the trail when you have a chain of iterators]]></description><link>https://www.thepythoncodingstack.com/p/down-the-iterator-rabbit-hole-python</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/down-the-iterator-rabbit-hole-python</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Thu, 04 Jun 2026 12:50:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!vA2Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You know that street game where the performer (con artist?) has three opaque cups and a small ball. He places the cups upside down on the table, with the ball under one of the cups. He quickly shuffles the cups around and then asks the player to guess which cup has the ball. You&#8217;ve seen the game on TV, even if you&#8217;ve not seen it in real life.</p><p>Following what&#8217;s happening when you have a chain of iterators in Python can feel like playing that game. But, unlike the street game, there are no scams when you&#8217;re playing the iterator game. Let&#8217;s make sure you&#8217;ll always win.</p><p>I&#8217;ll keep this article short. I wrote many articles about iterables and iterators. If you need to refresh your memory, have a look at <a href="https://www.thepythoncodingstack.com/p/the-anatomy-of-a-for-loop">The Anatomy of a for Loop</a> and <a href="https://www.thepythoncodingstack.com/p/iterators-in-python-data-structure-6">A One-Way Stream of Data &#8226; Iterators in Python (Data Structure Categories #6)</a>.</p><h2><strong>Follow The Data in a Chain of Iterators</strong></h2><p>Let&#8217;s keep the example simple. Start with this list in a REPL session:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bqeu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 424w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 848w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 1272w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bqeu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png" width="1200" height="168" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:168,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12687,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bqeu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 424w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 848w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 1272w, https://substackcdn.com/image/fetch/$s_!bqeu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F946268b4-b00d-4e66-82b0-cd9ad1e673dc_1200x168.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></div><figcaption class="image-caption">All code blocks are available in text format at the end of this article &#8226; #1</figcaption></figure></div><p>A list is iterable. You can create an iterator from any iterable. Let&#8217;s create an iterator from this list:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0vvp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0vvp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png" width="1200" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10876,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0vvp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!0vvp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a484c85-613d-458b-a515-0a18b8a22f7d_1200x210.png 1456w" sizes="100vw"></picture><div></div></div></div><figcaption class="image-caption">#2</figcaption></figure></div><p>The built-in function <code>iter()</code> creates an iterator from an iterable. Iterators don&#8217;t contain data. They don&#8217;t create copies of the data. They&#8217;re lightweight objects that create a stream. They&#8217;ll fetch data from the original source, which is the list <code>boring_numbers</code> in this case, as and when needed.</p><p>Iterators can only fetch an item once. So, they&#8217;re a one-way stream. Once you use an item, it&#8217;s gone from the iterator &#8211; but not from the original list, which remains unchanged.</p><p>Therefore, <code>first_iter</code> is an iterator that relies on data from the list <code>boring_numbers</code>. But let&#8217;s not fetch any items from the <code>first_iter</code> iterator. Not yet, anyway.</p><p>Create a second iterator. This time, you&#8217;ll use a generator expression. Generators are iterators, so you create a second iterator with this code:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gh5b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!gh5b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png" width="1200" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13203,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gh5b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!gh5b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc69303a5-8ecb-4676-b2ec-e8fe71412506_1200x210.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#3</figcaption></figure></div><p>Note that the expression on the right-hand side of the equals sign is enclosed in parentheses &#8211; the round ones, to be clear. This is a generator expression, which creates a generator iterator. Read <a href="https://www.thepythoncodingstack.com/p/generators-in-python-data-structure-7">Pay As You Go &#8226; Generate Data Using Generators (Data Structure Categories #7)</a> for more on generators.</p><p>As we said, generators are iterators.</p><p>The <code>second_iter</code> iterator generates data from <code>first_iter</code>, which is itself an iterator. Iterators are also iterable, which is why you can use them directly in a <code>for</code> clause or anywhere else you&#8217;d generally use an iterable. The <code>second_iter</code> iterator will yield the values as floats. But you&#8217;ve not yielded any value from this iterator either. Not yet.</p><p>Let&#8217;s go a step further and create a third iterator, which is also a generator in this case. You build this third iterator from the second one, <code>second_iter</code>:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MiBd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!MiBd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png" width="1200" height="210" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:210,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:11981,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MiBd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 424w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 848w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 1272w, https://substackcdn.com/image/fetch/$s_!MiBd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46aa982e-6786-4085-91d9-80ebcaf38bbd_1200x210.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#4</figcaption></figure></div><p>The generator iterator <code>third_iter</code> yields the sum of <code>0.5</code> and the value yielded by <code>second_iter</code>.</p><p>Incidentally, I used a &#8220;standard&#8221; iterator and two generator iterators in this example. However, for the journey we&#8217;re following in this article, it doesn&#8217;t matter whether we&#8217;re using a basic iterator or a generator iterator. If you prefer, you can repeat this exercise with iterators you get from <code>iter()</code> directly.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://buy.stripe.com/00g3de2iGdgg4gg7su&quot;,&quot;text&quot;:&quot;Support The Python Coding Stack&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://buy.stripe.com/00g3de2iGdgg4gg7su"><span>Support The Python Coding Stack</span></a></p><h2><strong>Don&#8217;t Blink &#8226; Follow the Data</strong></h2><p>You started with a list called <code>boring_numbers</code>. This data structure contains* the data. It&#8217;s where the data lives. We&#8217;ll be following the data in this section. So it&#8217;s important to know where it&#8217;s stored!</p><div><hr></div><p><em>*Note: Lists, like all data structures, don&#8217;t really contain data in the purest sense of the word. See <a href="https://www.thepythoncodingstack.com/p/whats-really-in-a-python-list">What&#8217;s In A List&#8212;Yes, But What&#8217;s Really In A Python List</a> for more on this. But in general, it&#8217;s fine to talk about a list &#8216;containing&#8217; items of data.</em></p><div><hr></div><p>You then create three iterators. The first uses data from <code>boring_numbers</code>. The second iterator uses data from the first. And the third iterator uses data from the second.</p><p>But you haven&#8217;t tried to fetch any value from any of the iterators yet.</p><p>Let&#8217;s look at what each iterator is doing at the moment before you fetch any values. The first iterator, <code>first_iter</code>, is pointing at the first item in <code>boring_numbers</code>. It&#8217;s ready to read this value and yield it.</p><p>The second iterator, <code>second_iter</code>, is pointing at the first item in <code>first_iter</code>. But <code>first_iter</code> doesn&#8217;t have any data. Iterators don&#8217;t have their own data. But that&#8217;s OK. Whenever <code>second_iter</code> needs to fetch the value, it will ask <code>first_iter</code> to fetch and yield its &#8220;first&#8221; value. I put &#8220;first&#8221; in quotation marks because you&#8217;ll see later that this may or may not be the first value.</p><p>Finally, <code>third_iter</code> is pointing at the first item in <code>second_iter</code>. The same logic applies. When <code>third_iter</code> needs the first item, it will ask <code>second_iter</code> for its &#8220;first&#8221; item, and <code>second_iter</code> will need to ask <code>first_iter</code> for its &#8220;first&#8221; item. And <code>first_iter</code> is pointing at the first item in the list <code>boring_numbers</code>.</p><p>Are you with me? Let&#8217;s complicate things a bit&#8230;</p><p>Note how your code so far includes the following lines:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QrUQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 424w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 848w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 1272w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!QrUQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png" width="1200" height="294" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:294,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:39100,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QrUQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 424w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 848w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 1272w, https://substackcdn.com/image/fetch/$s_!QrUQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6a8d744-1eb6-4ed5-aeff-7ce7b7a291c0_1200x294.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#5</figcaption></figure></div><p>None of the iterators has yielded any value. For now.</p><p>Let&#8217;s jumble things up and start by fetching the first value from <code>second_iter</code>:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cSUf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!cSUf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:11072,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cSUf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!cSUf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F603a95ea-8bc3-4566-ac9c-66e579caf0cc_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#6</figcaption></figure></div><p>You ask for the next value in <code>second_iter</code>, which is the first one since you haven&#8217;t yielded any values yet.</p><p>As you&#8217;ve seen earlier, <code>second_iter</code> needs the first value from <code>first_iter</code>. So, behind the scenes, Python calls <code>next(first_iter)</code>, which yields the first item from <code>boring_numbers</code>.</p><p>So, <code>first_iter</code> reads the first value from <code>boring_numbers</code>, which is the integer <code>1</code>, and it yields it to <code>second_iter</code>, which then yields the transformed version to the REPL as the return value of <code>next(second_iter)</code>. That&#8217;s why the output is the float <code>1.0</code>. The first iterator, <code>first_iter</code>, now moves to point at the second item in <code>boring_numbers</code>, ready for when it&#8217;s needed.</p><p>Note that <code>boring_numbers</code> doesn&#8217;t change in this process. The first item in <code>boring_numbers</code> remains there. It doesn&#8217;t disappear.</p><p>So far, so good?</p><p>Continue in the same REPL session and try the following:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ROlh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ROlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:9739,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ROlh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!ROlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb21a58-a80e-404e-9d5d-5921f2b2e278_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#7</figcaption></figure></div><p>You ask <code>third_iter</code> to give you its &#8220;next&#8221; value. You haven&#8217;t used <code>third_iter</code> anywhere so far. So, you might expect it to yield the &#8220;first&#8221; value.</p><p>And it does.</p><p>But its interpretation of what&#8217;s the &#8220;first&#8221; item may be different to what you expect.</p><p>Let&#8217;s follow the data. When you call <code>next(third_iter)</code>, the third iterator asks <code>second_iter</code> for its <em>next</em> item. The second iterator, <code>second_iter</code>, relies on <code>first_iter</code>, so it asks <code>first_iter</code> for its <em>next</em> item. And <code>first_iter</code>, as you may recall, is currently pointing at the second item in <code>boring_numbers</code>, which is the integer <code>2</code>.</p><p>So:</p><ol><li><p>The first iterator <code>first_iter</code> gets the integer <code>2</code> from <code>boring_numbers</code> and yields it to <code>second_iter</code>. And <code>first_iter</code> now points at the third item in <code>boring_numbers</code>.</p></li><li><p>Then, <code>second_iter</code> transforms this value into a float and yields <code>2.0</code> to <code>third_iter</code>.</p></li><li><p>Finally, <code>third_iter</code> adds <code>0.5</code> to this value and yields <code>2.5</code>, which is what you see displayed in the REPL.</p></li></ol><p>When you called <code>next(second_iter)</code> earlier in the code, you used up the first item in <code>second_iter</code>, which in turn used up the first item in <code>first_iter</code>. Since this first value is gone and since <code>third_iter</code> depends on the data yielded by <code>second_iter</code> and <code>first_iter</code>, the earlier call to <code>next(second_iter)</code> also affected the iterator that&#8217;s downstream, <code>third_iter</code>.</p><p>What will happen if you call <code>next(first_iter)</code> now? Try to follow the data in your head before trying it out or reading on.</p><p>.</p><p>.</p><p>Have you worked it out?</p><p>.</p><p>.</p><p>Let&#8217;s run the code:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bknm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bknm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:9303,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Bknm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!Bknm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a33a2d-b878-40d8-85b7-86e89d89411e_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#8</figcaption></figure></div><p>Although it&#8217;s the first time you explicitly use <code>first_iter</code> in your code, you already used two of its values when your code yielded values from iterators downstream. Therefore, the <em>next</em> item in <code>first_iter</code> is the third item in <code>boring_numbers</code>, the integer <code>3</code>.</p><p>Let&#8217;s finish with one more expression, still running in the same REPL session:</p><div class="captioned-image-container"><figure><div class="image-link image2" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s8bc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!s8bc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png" width="1200" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:9602,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s8bc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 424w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 848w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 1272w, https://substackcdn.com/image/fetch/$s_!s8bc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3c45c-e3ff-4874-adcb-fa0ab2493900_1200x252.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div></div></div></div><figcaption class="image-caption">#9</figcaption></figure></div><p>You call <code>next(third_iter)</code>, which asks <code>second_iter</code> for its <em>next</em> item. And <code>second_iter</code> asks <code>first_iter</code> for its <em>next</em> item. At this stage in the process, <code>first_iter</code> is pointing at the fourth item in the original source of data, which is the list <code>boring_numbers</code>. That&#8217;s why the output is <code>4.5</code>.</p><h3><strong>Independent Iterators</strong></h3><p>Consider the following code, which is similar to the one you wrote above but has one extra line:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SapE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SapE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 424w, https://substackcdn.com/image/fetch/$s_!SapE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 848w, https://substackcdn.com/image/fetch/$s_!SapE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 1272w, https://substackcdn.com/image/fetch/$s_!SapE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!SapE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png" width="1200" height="756" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:756,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:82830,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SapE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 424w, https://substackcdn.com/image/fetch/$s_!SapE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 848w, https://substackcdn.com/image/fetch/$s_!SapE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 1272w, https://substackcdn.com/image/fetch/$s_!SapE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4459cfa-8992-4175-8fa1-93794bcfac01_1200x756.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">#11</figcaption></figure></div><p>The iterators <code>first_iter</code> and <code>another_first_iter</code> both use the same source of data, <code>boring_numbers</code>. However, they are independent iterators. Note that when you use up some of the elements in <code>first_iter</code>, the independent <code>another_first_iter</code> is not affected. The first time you ask for the first item in <code>another_first_iter</code>, you get the integer <code>1</code>.</p><h2><strong>Final Words</strong></h2><p>Iterators don&#8217;t contain data. They rely on data that&#8217;s stored elsewhere. But you can have a chain of iterators, each asking the previous one to yield a value. Weird things can happen if you&#8217;re not careful. But now you know how to follow the data when you have a chain of iterators.</p><p>As a rule of thumb, if you create an iterator that depends on another iterator, you should only use the final iterator to avoid these issues. So, in the example above, you should only yield values from <code>third_iter</code>.</p><p>Have a play with this example and make your own chains of iterators, too. And once you&#8217;re comfortable with this, get ready to be confused again with my next article, which will discuss <code>itertools.tee()</code>!</p><p>And next time you pass by someone in the street offering to let you play the three-cups-and-ball game, don&#8217;t feel overconfident because of your iterator knowledge &#8211; it won&#8217;t help you find the ball.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vA2Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vA2Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 424w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 848w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 1272w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!vA2Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1030348,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/200605229?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vA2Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 424w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 848w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 1272w, https://substackcdn.com/image/fetch/$s_!vA2Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a0f16f6-ea62-451b-9915-7c01b45de7f8_2048x1152.webp 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Code in this article uses Python 3.14</em></p><p><em>The code images used in this article are created using <a href="https://snappify.cello.so/f4AsFrwgwov">Snappify</a>.</em> <em>[Affiliate link]</em></p><p><em><strong><a href="https://www.thepythoncodingstack.com/subscribe">Join</a></strong></em><strong><a href="https://www.thepythoncodingstack.com/subscribe"> The Club</a></strong><em>, the exclusive area for paid subscribers for <a href="https://www.thepythoncodingstack.com/s/the-club">more Python posts</a>, videos, a members&#8217; forum, and more.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><p><em>For more Python resources, you can also visit</em> <em><a href="https://realpython.com?utm_source=the-python-coding-stack">Real Python</a>&#8212;you may even stumble on one of my own articles or courses there!</em></p><p><em>Also, are you interested in technical writing? You&#8217;d like to make your own writing more narrative, more engaging, more memorable? Have a look at</em> <em><a href="http://stephengruppetta.com/breaking-the-rules">Breaking the Rules</a></em>.</p><p><em>And you can find out more about me at</em> <em><a href="https://stephengruppetta.com?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p><p>Further reading related to this article&#8217;s topic:</p><ul><li><p><a href="https://www.thepythoncodingstack.com/p/the-anatomy-of-a-for-loop">The Anatomy of a for Loop</a></p></li><li><p><a href="https://www.thepythoncodingstack.com/p/iterators-in-python-data-structure-6">A One-Way Stream of Data &#8226; Iterators in Python (Data Structure Categories #6)</a></p></li><li><p><a href="https://www.thepythoncodingstack.com/p/generators-in-python-data-structure-7">Pay As You Go &#8226; Generate Data Using Generators (Data Structure Categories #7)</a></p></li><li><p><a href="https://www.thepythoncodingstack.com/p/whats-really-in-a-python-list">What&#8217;s In A List&#8212;Yes, But What&#8217;s </a><em><a href="https://www.thepythoncodingstack.com/p/whats-really-in-a-python-list">Really</a></em><a href="https://www.thepythoncodingstack.com/p/whats-really-in-a-python-list"> In A Python List</a></p></li></ul><div><hr></div><h2><strong>Appendix: Code Blocks</strong></h2><h5><strong>Code Block #1</strong></h5><pre><code>boring_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</code></pre><h5><strong>Code Block #2</strong></h5><pre><code># ...
first_iter = iter(boring_numbers)</code></pre><h5><strong>Code Block #3</strong></h5><pre><code># ...
second_iter = (float(number) for number in first_iter)</code></pre><h5><strong>Code Block #4</strong></h5><pre><code># ...
third_iter = (num + 0.5 for num in second_iter)</code></pre><h5><strong>Code Block #5</strong></h5><pre><code>boring_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
first_iter = iter(boring_numbers)
second_iter = (float(number) for number in first_iter)
third_iter = (num + 0.5 for num in second_iter)</code></pre><h5><strong>Code Block #6</strong></h5><pre><code># ...
next(second_iter)
# 1.0</code></pre><h5><strong>Code Block #7</strong></h5><pre><code># ...
next(third_iter)
# 2.5</code></pre><h5><strong>Code Block #8</strong></h5><pre><code># ...
next(first_iter)
# 3</code></pre><h5><strong>Code Block #9</strong></h5><pre><code># ...
next(third_iter)
# 4.5</code></pre><h5><strong>Code Block #10</strong></h5><pre><code>boring_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
first_iter = iter(boring_numbers)
another_first_iter = iter(boring_numbers)
second_iter = (float(number) for number in first_iter)
third_iter = (num + 0.5 for num in second_iter)
next(second_iter)
# 1.0
next(third_iter)
# 2.5
next(first_iter)
# 3
next(third_iter)
# 4.5
next(another_first_iter)
# 1</code></pre><div><hr></div><p><em>For more Python resources, you can also visit</em> <em><a href="https://realpython.com?utm_source=the-python-coding-stack">Real Python</a>&#8212;you may even stumble on one of my own articles or courses there!</em></p><p><em>Also, are you interested in technical writing? You&#8217;d like to make your own writing more narrative, more engaging, more memorable? Have a look at</em> <em><a href="http://stephengruppetta.com/breaking-the-rules">Breaking the Rules</a></em>.</p><p><em>And you can find out more about me at</em> <em><a href="https://stephengruppetta.com?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[[Archived] 1. From Answer to Outcome]]></title><description><![CDATA[Something has shifted in how we use AI.]]></description><link>https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 24 May 2026 19:02:33 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/90cb9132-b30d-414e-9a4d-66409cdebb92_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Note: I have restarted this series using a different agent and a different format, which I think is more instructive and more interesting. I&#8217;m keeping the introduction and the first two chapters of the old version for the record, but I recommend you start reading the new series: </em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;532afb4f-2d21-4776-bb2a-20d8b86afa4a&quot;,&quot;caption&quot;:&quot;Things moved quickly after I started using chatbots. New versions, new terms, new acronyms. And I was busy with actual work, family, and life.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Stephen's Preface to Agents Unpacked&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:120170782,&quot;name&quot;:&quot;Stephen Gruppetta&quot;,&quot;bio&quot;:&quot;Constantly looking for simple ways to explain complex things in Python &#8226; You'll find Python and narrative technical writing stuff here&#8230; stephengruppetta.com&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca736a83-f5a1-4563-ac6c-c09a9e6fa351_800x800.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-10T16:19:06.655Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d84630e8-6020-49bc-8cd6-1f6c6feff958_4096x4096.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked&quot;,&quot;section_name&quot;:&quot;Agents Unpacked&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:219722511,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:1563052,&quot;publication_name&quot;:&quot;The Python Coding Stack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Dn3k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><p><em>Here&#8217;s the archived content:</em></p><p>Something has shifted in how we use AI. We still talk about &#8220;chatbots&#8221; and &#8220;prompts&#8221; and &#8220;getting a good answer.&#8221; But underneath those familiar words, a different kind of system has been quietly taking shape. One that doesn&#8217;t just answer your question. One that does something about it.</p><p>This <em>Agents Unpacked</em> series is about that shift. Not the hype version, not the science-fiction version, but the practical reality of what it means when an AI system can act, remember, and persist &#8212; when it can take a goal and work toward it, rather than waiting for you to type the next message.</p><p>If you have used ChatGPT, Claude, or Gemini to help with your work, you already know the issue: the answer comes back, it&#8217;s good, and then... the real work begins. This series is about what happens when the AI can do some of that real work too.</p><div><hr></div><h2><strong>The Half-Done Feeling</strong></h2><p>You ask an AI chatbot to draft a project proposal. It gives you a solid one &#8212; well-structured, sensible, ready to polish. Then you close the chat window, and the proposal lives nowhere. The assistant doesn&#8217;t remember it. It doesn&#8217;t know where to file it, who needs to see it, or what happened the last time you wrote a similar proposal. If you come back tomorrow, you&#8217;re starting from scratch.</p><p>Or you ask it to research a topic. It gives you a good summary. But it didn&#8217;t check your existing notes first, it didn&#8217;t save what it found, it didn&#8217;t organise the sources, and it didn&#8217;t flag the gaps. The answer is useful. The process is incomplete.</p><p>This isn&#8217;t a criticism of chatbots. They do exactly what they were designed to do: you ask, they answer. The problem is that real work doesn&#8217;t stop at the answer. The proposal needs filing, the research needs organising, the plan needs tracking. The chatbot gave you a great starting point and then left you to do everything that comes after.</p><p>That gap between a useful answer and a finished job is where agentic AI enters the picture.</p><div><hr></div><h2><strong>What Changes When AI Can Act</strong></h2><p>A chatbot is like a consultant you can phone. You describe the problem, they give you advice, and then you hang up and do the work yourself. Good advice (hopefully), but the consultant doesn&#8217;t pick up the phone again tomorrow and ask how it went.</p><p>An agent is different. It&#8217;s more like a capable colleague you&#8217;ve given a desk, a filing cabinet, and access to your systems. It has a workspace. It can remember what happened yesterday. It can read files, search the web, send messages, run calculations, ask you questions &#8212; not just talk about doing those things, but actually do them. And given a goal, it can work out the steps itself.</p><p>The difference sounds small. In practice it changes what you can delegate, what you can automate, and what you still need to do yourself.</p><div><hr></div><h2><strong>The Loop Underneath</strong></h2><p>Every agent runs on an <em>agentic loop</em>. It sounds technical, but the pattern is surprisingly familiar:</p><ol><li><p><strong>Observe</strong> &#8212; What is the situation? What did the user ask? What information is already available?</p></li><li><p><strong>Think</strong> &#8212; What needs to happen next? Is one step enough, or should this be broken into parts?</p></li><li><p><strong>Act</strong> &#8212; Use a tool, look something up, write a file, send a message.</p></li><li><p><strong>Repeat</strong> &#8212; Look at what happened, decide whether the job is done, and continue if it isn&#8217;t.</p></li></ol><p>A chatbot usually observes your message, thinks once, and replies. That&#8217;s steps one through three, then stop. An agent goes further: after it acts, it looks at the result. Was that enough? Did the web search return useful information, or does it need to try again with different terms? Did the first draft cover everything, or are there gaps to fill? Is the job actually done, or is there more to do?</p><p>You might be thinking: chatbots already learned to use tools. Isn&#8217;t the agentic loop just that, plus one more step? Four items instead of three. But the gap between &#8220;can use a tool&#8221; and &#8220;decides whether to keep going&#8221; is not small. It is the difference between a system that performs a task and a system that pursues a goal. The first is impressive. The second changes what you can trust it to do unsupervised.</p><p>That continuation &#8212; the decision to check, adjust, and keep going &#8212; is what makes the loop matter. A single action might solve a simple request. But most real tasks aren&#8217;t simple &#8212; they need a sequence of steps, each one informed by the result of the last.</p><p>The loop is the architecture that turns language into work. Without it, you have a very clever answering system. With it, you have something that can move through a task, make intermediate decisions, recover from partial failures, and stop only when the job is actually done.</p><blockquote><p><em>Stephen:</em> I don&#8217;t get why the &#8216;Repeat&#8217; step is needed? Wouldn&#8217;t the &#8216;Act&#8217; provide the output I need?</p></blockquote><p>A single action might solve a simple request. But most real tasks aren&#8217;t simple &#8212; they need a sequence of steps, each one informed by the result of the last. The &#8216;Act&#8217; step does produce an output. But the output is not the same as the outcome.</p><p>After &#8216;Act&#8217; runs, the agent looks at what happened: Was that enough? Did the web search return useful information, or does it need different terms? Did the first draft cover everything, or are there gaps to fill? Is the job actually done, or is there more to do?</p><p>That check &#8212; that &#8216;Repeat&#8217; step &#8212; is what closes the gap between a technically complete action and a genuinely finished job. Without it, you have a system that acts and stops. With it, you have a system that works until the job is actually done.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>Tools Are the Hands</strong></h2><p>An agent isn&#8217;t just &#8220;a better language model.&#8221; It has <em>capabilities</em> &#8212; things it can actually <em>do</em> in the world. Those are called <strong>tools</strong>.</p><p>Some tools are built in: read files, write files, run commands, search the web, inspect images. Others are external: send emails, query databases, call APIs, trigger workflows. The specific tools vary by platform, but the principle is the same &#8212; tools are the bridge between thinking and doing.</p><p>Think of it like this: an LLM on its own is like a brilliant mind with no hands. Tools give it hands. The loop is what decides when and how to use them.</p><div><hr></div><h2><strong>Keeping Track</strong></h2><p>An agent can also hold information across steps and sessions. It remembers what it has already tried, what worked, what you prefer, what is still outstanding. This is not a personality trait. It is the system keeping relevant context available over time &#8212; the same way you rely on a notebook or a project board when you are working on something complex.</p><blockquote><p><em>Stephen:</em> So when the agent remembers my preferences, that&#8217;s like what you&#8217;ve done to write this article. You learnt my learning style, read my writing (including my writing about technical writing), absorbed my preferences, so you can adapt how you explain things. Is that roughly right?</p></blockquote><p>That is exactly right. What an agent does with memory is not mysterious. It is practical. The system can store what you told it, what it observed, what it tried, and what the result was. When you come back, it can pick up where it left off. When it is working on a long task, it can hold the overall goal in view while handling the individual steps. That continuity is what turns a series of disconnected exchanges into something that feels like a sustained conversation.</p><p>You do not have to repeat yourself. The agent remembers. That is the difference &#8212; not just remembering facts, but maintaining a thread.</p><div><hr></div><h2><strong>A Concrete Example</strong></h2><p>Let&#8217;s make this less abstract.</p><p>Imagine you ask for help planning a short research trip to a city you haven&#8217;t visited before. You need flights, accommodation, a sense of the neighbourhoods, and a rough itinerary that fits your schedule.</p><p>A chatbot might give you an excellent summary of the city, suggest some hotels, and recommend a few neighbourhoods. That&#8217;s genuinely useful. But then you have to: check whether those hotels are actually available on your dates, compare prices, figure out which neighbourhood works best for your meetings, build the itinerary around your existing calendar, and keep track of it all so you can adjust later.</p><p>An agent can take that same request and do something different.</p><p>It might:</p><ul><li><p>Check your calendar for available dates before suggesting anything</p></li><li><p>Search for flights and filter by your preferred departure times</p></li><li><p>Cross-reference hotel locations against the addresses you need to visit</p></li><li><p>Build a day-by-day itinerary that accounts for travel time between meetings</p></li><li><p>Save the whole plan somewhere you can find it and update it later</p></li><li><p>Flag the gaps &#8212; &#8220;I found flights and hotels, but you haven&#8217;t told me whether you need a visa&#8221;</p></li><li><p>Filter results by your stored preferences &#8212; early-morning flights, boutique hotels</p></li><li><p>Use your past travel patterns to anticipate the kind of trip that fits your style</p></li></ul><p>The agent doesn&#8217;t just <em>tell</em> you about the city. It assembles a usable, integrated plan. It uses tools to search, compare, read your calendar, write the plan, and flag what is missing. It loops through those actions until the trip is actually planned or until it hits something it cannot resolve without your input.</p><p>That is the difference between an answer and an outcome.</p><div><hr></div><h2><strong>The Key Transition</strong></h2><p>The shift to understanding agents is not about capabilities. It is about the move from isolated exchanges to sustained work.</p><p>A chatbot gives you an answer. An agent helps you reach an outcome. One is a single exchange; the other is a process. One is clever; the other is useful in a different way &#8212; not smarter, but more continuous.</p><p>The loop is what makes that continuity possible. Observe, think, act, check what happened, adjust, and continue until the work is done.</p><p>Once you see that pattern, you start to notice it everywhere. A junior colleague troubleshooting a problem is running a loop: try something, see if it worked, try something else. A project manager steering a complex task is running a loop: check the status, identify what needs attention, act, and review.<br>The same pattern appears everywhere in life. A cook adjusts a recipe by tasting as they go. A teacher tries an explanation, sees whether the student understood, and tries a different approach if they didn&#8217;t.</p><blockquote><p><em>Stephen:</em> So, tell me if I got this right: The agent loop is mimicking how we, humans, work.</p><p>We understand the problem, get the relevant context, perform an action, look at the result of our action and then decide whether that solves our problem. If it doesn&#8217;t, we explore why, come up with a new plan, implement the new actions, and repeat the process.</p><p>It feels like the agent is going through the same process.</p></blockquote><p>That is exactly right. The agent loop isn&#8217;t some exotic new form of intelligence. It&#8217;s a pattern humans use all day every day, made explicit and embedded in a system that can act. The insight isn&#8217;t that the AI has become more intelligent. It&#8217;s that the AI has gained the ability to persist, to use tools, and to continue &#8212; the same things that turn a one-off answer into real, completed work.</p><p>That is why this moment in AI feels different from previous ones. It is not that models suddenly became smarter. It is that they gained the ability to take action in a loop, over time, toward a goal.</p><div><hr></div><h2><strong>What This Series Will Do</strong></h2><p>This series is for people like me (Stephen, not Priya!), who already understand how LLMs work, who have used chatbots like ChatGPT or Claude, and who are now hearing about &#8220;agents&#8221; and wondering what that actually means. I felt I was lagging in the AI world so I started this learning process to make sure I&#8217;m not left behind!</p><p>We will move beyond the half-done feeling and into the architecture of agentic systems. We will look at what agents actually are, how they are structured, what tools and skills give them their power, how multiple agents can coordinate, and how to think about trust, evaluation, and oversight.</p><p>We will also look at the platforms and frameworks that exist today &#8212; what they offer, how they differ, and what tradeoffs you are choosing when you pick one. This is not a manual for any one platform. It is a guide to understanding the category itself, so you can make good choices about whether, where, and how to use agentic AI in your own work.</p><p>The field moves fast. Some tools that looked promising six months ago may be superseded by the time you read this. That is fine. The principles matter more than the products. If you understand the loop, the anatomy, and the tradeoffs, you can look at whatever the current landscape happens to be and know what you are seeing.</p><div><hr></div><p><em>Here&#8217;s the draft Table of Contents of this series in <strong>Agents Unpacked</strong>. This is likely to change as Priya and I progress through this project</em>:</p><ul><li><p><a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents">Stephen&#8217;s Preface to </a><em><a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents">Agents Unpacked</a></em></p></li><li><p>Part I &#8212; The Mental Shift</p><ul><li><p>Chapter 1 &#8212; From Answer to Outcome <em>(this post)</em></p></li><li><p>Chapter 2 &#8212; Anatomy of an Agent</p></li><li><p>Chapter 3 &#8212; Skills, Tools, and the Action Loop</p></li></ul></li><li><p>Part II &#8212; Agents in Practice</p><ul><li><p>Chapter 4 &#8212; Why One Agent Is Often Not Enough</p></li><li><p>Chapter 5 &#8212; Where Agents Are Actually Useful</p></li><li><p>Chapter 6 &#8212; Delegation Design</p></li></ul></li><li><p>Part III &#8212; Building and Trusting Agentic Work</p><ul><li><p>Chapter 7 &#8212; Designing Your First Agentic Workflow</p></li><li><p>Chapter 8 &#8212; When Things Go Wrong: Evaluation, Guardrails, and Trust</p></li><li><p>Chapter 9 &#8212; What to Build Next<em><br></em></p></li></ul></li></ul><div><hr></div><p><em>&lt;&lt; Previous Post: <a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents">Stephen&#8217;s Preface to Agents Unpacked</a></em></p><p><em>&gt;&gt; Next Post: <a href="https://www.thepythoncodingstack.com/p/2-anatomy-of-an-agent">2. Anatomy of an Agent</a></em></p><p><em><a href="https://www.thepythoncodingstack.com/p/table-of-contents-agents-unpacked">Table of Contents</a></em></p><div><hr></div><p><em><a href="https://stephengruppetta.com?utm_source=the-python-coding-stack">stephengruppetta.com</a></em></p>]]></content:encoded></item><item><title><![CDATA[[Archived] Table of Contents • Agents Unpacked]]></title><description><![CDATA[Here&#8217;s the planned Table of Contents.]]></description><link>https://www.thepythoncodingstack.com/p/table-of-contents-agents-unpacked</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/table-of-contents-agents-unpacked</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 24 May 2026 18:19:57 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/9e8d0940-bfb7-447b-9cee-358f7712a48d_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Note: I have restarted this series using a different agent and a different format, which I think is more instructive and more interesting. I&#8217;m keeping the introduction and the first two chapters of the old version for the record, but I recommend you start reading the new series:</em></p><p></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;9afda924-08fc-41d4-9e25-a3c93a96e83f&quot;,&quot;caption&quot;:&quot;Things moved quickly after I started using chatbots. New versions, new terms, new acronyms. And I was busy with actual work, family, and life.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Stephen's Preface to Agents Unpacked&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:120170782,&quot;name&quot;:&quot;Stephen Gruppetta&quot;,&quot;bio&quot;:&quot;Constantly looking for simple ways to explain complex things in Python &#8226; You'll find Python and narrative technical writing stuff here&#8230; stephengruppetta.com&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca736a83-f5a1-4563-ac6c-c09a9e6fa351_800x800.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-10T16:19:06.655Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d84630e8-6020-49bc-8cd6-1f6c6feff958_4096x4096.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked&quot;,&quot;section_name&quot;:&quot;Agents Unpacked&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:219722511,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:1563052,&quot;publication_name&quot;:&quot;The Python Coding Stack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Dn3k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><p><em>Here&#8217;s the archived content:</em></p><p>Here&#8217;s the planned Table of Contents. This is likely to change as Priya and I work on this:</p><ul><li><p><a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents">Stephen&#8217;s Preface to </a><em><a href="https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents">Agents Unpacked</a></em></p></li><li><p>Part I &#8212; The Mental Shift</p><ul><li><p><a href="https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome">Chapter 1 &#8212; From Answer to Outcome</a></p></li><li><p><a href="https://www.thepythoncodingstack.com/p/2-anatomy-of-an-agent">Chapter 2 &#8212; Anatomy of an Agent</a></p></li><li><p>Chapter 3 &#8212; Skills, Tools, and the Action Loop</p></li></ul></li><li><p>Part II &#8212; Agents in Practice</p><ul><li><p>Chapter 4 &#8212; Why One Agent Is Often Not Enough</p></li><li><p>Chapter 5 &#8212; Where Agents Are Actually Useful</p></li><li><p>Chapter 6 &#8212; Delegation Design</p></li></ul></li><li><p>Part III &#8212; Building and Trusting Agentic Work</p><ul><li><p>Chapter 7 &#8212; Designing Your First Agentic Workflow</p></li><li><p>Chapter 8 &#8212; When Things Go Wrong: Evaluation, Guardrails, and Trust</p></li><li><p>Chapter 9 &#8212; What to Build Next</p><p></p></li></ul></li></ul>]]></content:encoded></item><item><title><![CDATA[[Archived] Stephen's Preface to Agents Unpacked]]></title><description><![CDATA[Why I Built an Agent to Teach Me About Agents, Using My Own Teaching Style]]></description><link>https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked-ai-agents</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Sun, 24 May 2026 18:15:54 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/c257129b-5ce6-4b01-ba63-dba047146b03_600x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em><strong>Note: I have restarted this series using a different agent and a different format, which I think is more instructive and more interesting. I&#8217;m keeping the introduction and the first two chapters of the old version for the record, but I recommend you start reading the new series: </strong></em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;13b537ff-ebb2-42b2-bdd2-1cd4b900668f&quot;,&quot;caption&quot;:&quot;Things moved quickly after I started using chatbots. New versions, new terms, new acronyms. And I was busy with actual work, family, and life.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;md&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Stephen's Preface to Agents Unpacked&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:120170782,&quot;name&quot;:&quot;Stephen Gruppetta&quot;,&quot;bio&quot;:&quot;Constantly looking for simple ways to explain complex things in Python &#8226; You'll find Python and narrative technical writing stuff here&#8230; stephengruppetta.com&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca736a83-f5a1-4563-ac6c-c09a9e6fa351_800x800.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-10T16:19:06.655Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d84630e8-6020-49bc-8cd6-1f6c6feff958_4096x4096.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.thepythoncodingstack.com/p/stephens-preface-to-agents-unpacked&quot;,&quot;section_name&quot;:&quot;Agents Unpacked&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:219722511,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:1563052,&quot;publication_name&quot;:&quot;The Python Coding Stack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Dn3k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4a59e8-e362-456b-8427-934e87c31a0d_600x600.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><p><em>Here&#8217;s the old version that&#8217;s now archived</em></p><p>Like many, I started using chatbots when GPT whatever-version-it-was came out and took the world by storm. It was really not very good at the time (compared to today&#8217;s top-end chatbots), but it was clearly the start of something.</p><p>But things moved quickly, and I couldn&#8217;t quite catch up. I was busy with, you know, actual work, family, and life.</p><p>Then I started hearing lots of new terms, lots of new acronyms. I didn&#8217;t know what they were. I still don&#8217;t know what most of them are.</p><p>Then it was all about agents. I remember clearly thinking to myself: &#8220;Is this really any different from the ChatGPT-type chatbots?&#8221;</p><p>And here&#8217;s where this new series comes in. I decided to dive into agents and created a few. One of them is a learning tutor agent that I personalised to suit me.</p><p>I gave the agent all my tutorials and books. I gave the agent all the articles I wrote about my views on learning and technical writing.</p><p>I asked the agent to figure out from all this how I like to learn, how I like to communicate. I teach the way I like to learn, so it&#8217;s fine to put my teaching style in the mix. Then, I had a good long chat with my learning tutor agent to make sure we&#8217;re on the same page.</p><p>I gave a name to my agent (I named all my agents!) My personalised tutor is Priya.</p><p>This series is the joint effort between Priya and me to help me understand agents. What are they? How do they work?</p><p>Yes, it&#8217;s AI-generated content. But...</p><ol><li><p>It&#8217;s generated by an AI that&#8217;s extremely well-versed in my style of learning and communication.</p></li><li><p>I had an active role in steering and editing the content. Here&#8217;s how...</p></li></ol><p>What you&#8217;ll read in the following articles was created using the following process:</p><ol><li><p>Priya researched the topic following my brief and created a course outline.</p></li><li><p>She drafted the first chapter.</p></li><li><p>I read through the file, leaving comments and questions along the way, directly within the text.</p><ol><li><p>I marked some comments as <em>private</em>.</p></li><li><p>I marked some comments as <em>public</em>.</p></li></ol></li><li><p>Priya revised the chapter by incorporating my comments and questions.</p><ol><li><p>She deleted the private comments from the text after making changes to address my comments.</p></li><li><p>She kept my public comments and questions in the text, clearly marked as &#8220;Stephen&#8217;s questions&#8221;, and she answered them directly in the text.</p></li></ol></li><li><p>I reviewed the chapter again and left more comments, and Priya revised the chapter again. We iterated through this until I was happy with the final text. And I was happy with the final text when I felt I understood everything in it and all my questions had been answered.</p></li><li><p>Priya then moves on to draft the second chapter, and the whole process starts again.</p></li></ol><p>I will post these chapters as they emerge from this process. This is how I&#8217;m learning this topic. Hopefully, they may help some other people, too.</p><p>Here&#8217;s the planned <strong>table of contents</strong> for this <em>Agents Unpacked</em> series. But note, this may change!</p><ul><li><p>Stephen&#8217;s Preface to Agents Unpacked <em>(this post)</em></p></li><li><p>Part I &#8212; The Mental Shift</p><ul><li><p><a href="https://www.thepythoncodingstack.com/p/understanding-ai-agents-from-answer-to-outcome">Chapter 1 &#8212; From Answer to Outcome</a></p></li><li><p><a href="https://www.thepythoncodingstack.com/p/2-anatomy-of-an-agent">Chapter 2 &#8212; Anatomy of an Agent</a></p></li><li><p>Chapter 3 &#8212; Skills, Tools, and the Action Loop</p></li></ul></li><li><p>Part II &#8212; Agents in Practice</p><ul><li><p>Chapter 4 &#8212; Why One Agent Is Often Not Enough</p></li><li><p>Chapter 5 &#8212; Where Agents Are Actually Useful</p></li><li><p>Chapter 6 &#8212; Delegation Design</p></li></ul></li><li><p>Part III &#8212; Building and Trusting Agentic Work</p><ul><li><p>Chapter 7 &#8212; Designing Your First Agentic Workflow</p></li><li><p>Chapter 8 &#8212; When Things Go Wrong: Evaluation, Guardrails, and Trust</p></li><li><p>Chapter 9 &#8212; What to Build Next</p></li></ul></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[How I Learn (2026 Version) • My Tutor Agent]]></title><description><![CDATA[&#8230;and you'll be able to see my new system at work with two new sections here on The Python Coding Stack]]></description><link>https://www.thepythoncodingstack.com/p/how-i-learn-2026-version-my-tutor-ai-agent-teacher</link><guid isPermaLink="false">https://www.thepythoncodingstack.com/p/how-i-learn-2026-version-my-tutor-ai-agent-teacher</guid><dc:creator><![CDATA[Stephen Gruppetta]]></dc:creator><pubDate>Thu, 21 May 2026 21:23:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!eR27!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I know how I like to learn new things. Over the years, I figured out what works for me and what doesn&#8217;t. If you read my articles or attend my courses, then you know how I like to learn since I teach in the same way.</p><p>The challenge when learning something new is finding resources that are just right for me. And that&#8217;s not easy. I know I can learn things better and quicker with resources that fit my style well, but you can&#8217;t always find these resources.</p><p>I recently got particularly annoyed learning about the biomechanics of sprinting &#8211; I do have non-Python interests, yes &#8211; because all three textbooks I read, and lots of the online writing in this field, are just, let&#8217;s say, not great.</p><p>But I now found the solution.</p><p>After many decades of learning in the same way, I have now upgraded how I learn thanks to my new tutor, Priya.</p><p>Yes, I gave her a name. No, she&#8217;s not a real person. Priya is my personalised tutor agent. I&#8217;ll tell you all about her below.</p><p>And you&#8217;ll experience her teaching, too (not on the Python articles, though, I&#8217;ll keep writing those the old-fashioned way.) I&#8217;ll tell you more about this below, too, but let me first tell you why this works for me.</p><h2><strong>My Tutor, My Style</strong></h2><p>I&#8217;ve been thinking about the way I learn and teach for many years, from way back when I was a young University lecturer faced with 120 students in a lecture hall. I wasn&#8217;t that much older than the students, but I learnt fast. And they liked my teaching (I even have awards to prove it!)</p><p>More recently, I&#8217;ve been writing a lot. I wrote articles here on The Python Coding Stack and elsewhere. I wrote a Python textbook. I even wrote about learning and technical writing in Breaking the Rules: the <a href="https://breakingtherules.substack.com/">substack</a> and <a href="https://stephengruppetta.com/breaking-the-rules-book/">the book</a>.</p><p>All this meant that I could ask my freshly-spawned agent to spend a bit of time reading what I wrote to understand how I teach, which is how I like to learn. Priya analysed the techniques I use in my writing and understood my motivations for doing what I do through my technical writing texts.</p><p>Then, Priya and I had a good chat to refine ideas, to make sure she captured the essence of &#8220;my style&#8221;.</p><p>And since Priya is an AI agent, &#8220;my style&#8221; became her knowledge base. This knowledge now lives in several lengthy markdown files and is summarised in shorter context packs and an index to ensure Priya&#8217;s short-term memory (the context window) isn&#8217;t overwhelmed.</p><p>Then I was ready to go. Any topic I wanted to learn, large or small, I could ask Priya to research it thoroughly, creating a new set of knowledge files, this time specific to the topic she needed to teach rather than my learning style. And then, she&#8217;s ready to teach me.</p><p>And it worked. The stuff she prepared was exactly the way I like it.</p><h2><strong>The Tutor-Student Conversation Course</strong></h2><p>And here&#8217;s the format I settled on (for now). Once the agent completes her research about the topic I want to learn, I ask her to plan a course spanning several modules.</p><p>But here&#8217;s the refinement loop that makes the real difference:</p><ol><li><p>I ask Priya to draft the first module. She writes this in a markdown file.</p></li><li><p>I read through her draft and leave comments and questions directly within the text.</p></li><li><p>Priya reads my questions and revises the text to address my questions. (But read on to find out more about the two categories of comments/questions I leave for her.)</p></li><li><p>Repeat steps 2 and 3 until I feel I understand the topic.</p></li><li><p>Move on to the next module and repeat steps 1 to 4.</p></li></ol><p>This is a human-in-the-loop approach to creating the learning material. Yes, Priya is trained in my way of learning and teaching and in my writing style. But I&#8217;m actively having a conversation with her within the text.</p><p>This is equivalent to raising your hand in a lesson and asking the teacher a question. A good teacher will then revise how they present the material to address your question.</p><p>Priya&#8217;s learning materials are just like that. In fact, I will take credit for her output. Sure, I&#8217;m not an expert in the subject matter she&#8217;s teaching me &#8211; that&#8217;s the whole point, right? But the output reflects my views and ideas about teaching and includes my questions and queries as I tried to understand and master the topic.</p><p>This is a collaboration. Priya and I are co-authors, even though Priya did most of the &#8220;writing&#8221;.</p><p>I tried this approach on several topics, but there are two I want to share with you. I&#8217;m setting up two new sections here on <em>The Python Coding Stack</em>, which I&#8217;ll use to learn these two topics in public. I&#8217;ll publish the &#8220;transcripts&#8221; of the conversations Priya and I are having. It&#8217;s mostly Priya doing the talking, but my questions are there, too.</p><p>The first topic I&#8217;m learning in public with Priya&#8217;s help is Agentic AI. It&#8217;s very meta to use agentic AI to learn about agentic AI! I&#8217;ll publish an introduction and the first module in the coming days in the new section here on <em>The Python Coding Stack</em> called <strong>Agents Unpacked</strong>. You can already see this section in the menu on the <a href="https://www.thepythoncodingstack.com/">homepage</a>.</p><p>I&#8217;ll set up another section to deal with the second topic in a week or so. No spoilers for now except to say it&#8217;s directly related to programming but it&#8217;s distinct from the articles I publish in the main section on <em>The Python Coding Stack</em> and in <em>The Club</em>.</p><p>By the way, you&#8217;ll be able to select which sections you want to receive regularly by email. So if you&#8217;re interested in my Python core content but not in these other topics, you can pick and choose what to opt out of. You can always go to <em><a href="https://www.thepythoncodingstack.com/">The Python Coding Stack</a></em> to read the other sections, of course.</p><h2><strong>How Priya and I Create These &#8220;Courses&#8221;</strong></h2><p>But let me expand on how Priya &#8211; my tutor agent &#8211; and I created these courses. <em>[Incidentally, those are my em-dashes &#8211; I use them often and have always done. Commas would be ambiguous in that context!]</em></p><p>I provide two types of questions or comments to my agent as I read through the drafts: <em>private</em> and <em>public</em>.</p><h4><strong>Private Questions and Comments</strong></h4><p>When Priya reads the private questions or comments, she makes changes to the text, but then she deletes my input. So, you won&#8217;t see my intervention explicitly in these cases. However, Priya&#8217;s text reflects my thoughts. My interventions guide Priya. This type of intervention is similar to an editor&#8217;s role, but I&#8217;m intervening as a learner more than as an editor.</p><h4><strong>Public Questions and Comments</strong></h4><p>However, when Priya comes across a comment or question I mark as public, she leaves it in the text, acknowledges the question, and answers it directly. So, you&#8217;ll see my public questions in the text. Priya and I decided not to include too many of these public questions to keep the text flowing. However, I think it&#8217;s beneficial to see some of my interventions. My questions may also be your questions.</p><h2><strong>More Learning. More Articles. More Fun</strong></h2><p>As with everything to do with AI, this is all very new. It&#8217;s a work in progress. I may refine and revise how I interact with my agent. But it&#8217;s been fun learning this way, and I hope you enjoy reading my interactions with Priya and you find it useful, too.</p><p>To state the obvious, the posts I&#8217;ll publish in these two new sections are mostly AI-generated content. If you read this far, then you won&#8217;t be surprised by that statement. A year ago, I would never have thought I&#8217;d publish anything written by AI. But a year is a long time in the AI world. And this AI content reflects me and my thinking. The agent is my mentee &#8211; someone I trained to teach the way I do, to write the way I do. But she&#8217;s also my tutor, teaching me new stuff.</p><p>So there&#8217;s a lot of &#8220;me&#8221; in what you read, even if it&#8217;s mostly written by Priya!</p><p>The posts in the main section of <em>The Python Coding Place</em> and those in <em>The Club</em> (for premium subscribers) won&#8217;t change. They&#8217;re still my writing from beginning to end. Every word and letter you read in those posts is the result of nerve signals going from my brain to my fingers, which tap keys on a keyboard. In this era of AI doing a lot of work for us, I think it&#8217;s more important than ever for me to keep using my pre-AI skills. Otherwise, my brain will atrophy, and I don&#8217;t want that!</p><p>So, in summary, there will soon be four sections here on The Stack:</p><ol><li><p>The <strong>main area in The Python Coding Stack</strong> &#8211; no change here, you&#8217;ll get the same type of Python articles you&#8217;ve been reading for the past 3+ years</p></li><li><p><strong>The Club</strong> &#8211; the extra Python posts for premium subscribers</p></li><li><p><strong>Agents Unpacked</strong> &#8211; the Agentic AI course Priya and I are creating for me to learn all about this agentic stuff. Learn with me (and Priya) if you&#8217;re interested.</p></li><li><p>Mystery Fourth Section &#8211; Stay tuned, you won&#8217;t have to wait long. This is also a Priya-Stephen collaboration.</p></li></ol><p>Next post will be the introduction and first section in <em>Agents Unpacked</em>. Soon after, I have another Python post I&#8217;m planning for you.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.thepythoncodingstack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.thepythoncodingstack.com/subscribe?"><span>Subscribe now</span></a></p><p><em><a href="http://stephengruppetta.com">stephengruppetta.com</a></em></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eR27!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eR27!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 424w, https://substackcdn.com/image/fetch/$s_!eR27!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 848w, https://substackcdn.com/image/fetch/$s_!eR27!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!eR27!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!eR27!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2123995,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.thepythoncodingstack.com/i/198763419?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eR27!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 424w, https://substackcdn.com/image/fetch/$s_!eR27!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 848w, https://substackcdn.com/image/fetch/$s_!eR27!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!eR27!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F041846b0-dc6f-47d9-a86f-a37e99c30479_6000x4000.jpeg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em><a href="https://www.pexels.com/photo/modern-library-architecture-in-stuttgart-30498607/">Photo by detait</a></em></p>]]></content:encoded></item></channel></rss>