<?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[Aayush Ostwal]]></title><description><![CDATA[Gen AI Engineer | AI Agents | Building Scalable, event-driven, distributed applications for last 5 years]]></description><link>https://aayushostwal2.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!G_Ga!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31523f1d-7835-4378-a58f-229ec9fb014b_1280x1280.png</url><title>Aayush Ostwal</title><link>https://aayushostwal2.substack.com</link></image><generator>Substack</generator><lastBuildDate>Tue, 02 Jun 2026 22:03:28 GMT</lastBuildDate><atom:link href="https://aayushostwal2.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Aayush Ostwal]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[aayushostwal2@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[aayushostwal2@substack.com]]></itunes:email><itunes:name><![CDATA[Aayush Ostwal]]></itunes:name></itunes:owner><itunes:author><![CDATA[Aayush Ostwal]]></itunes:author><googleplay:owner><![CDATA[aayushostwal2@substack.com]]></googleplay:owner><googleplay:email><![CDATA[aayushostwal2@substack.com]]></googleplay:email><googleplay:author><![CDATA[Aayush Ostwal]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The 15 AI Agent Design Patterns Every Engineer Should Know (With Production Examples)]]></title><description><![CDATA[A field guide for engineers who want the right pattern, not the most impressive one.]]></description><link>https://aayushostwal2.substack.com/p/the-15-ai-agent-patterns-every-engineer</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/the-15-ai-agent-patterns-every-engineer</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Sat, 23 May 2026 09:32:00 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/0b7e2b60-3ad6-48c7-9192-ad81725f3835_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There is a predictable arc to how teams build <strong>agentic systems</strong>. It starts simply: <strong>one prompt, one loop, a few tools</strong>. Then reality intervenes &#8212; <strong>new requirements, more teams, compliance, harder workflows</strong>. Suddenly, one loop is carrying multiple concerns inside an oversized system prompt. The architecture debate begins: <strong>keep extending it, move to multi-agent systems, or introduce a framework?</strong> Usually, the team is split.</p><p>This guide is for the moment <strong>before that debate takes over</strong>. It covers the major patterns used in <strong>production agentic systems</strong>, <strong>when each one earns its place</strong>, and the <strong>trade-offs</strong> involved. The examples use <strong>class-based Python</strong> &#8212; code you would actually review in a pull request, not demo-grade snippets.</p><p>We will cover:</p><ol><li><p><strong>Pattern 1: Single-Agent</strong> <em>(Month 1)</em></p></li><li><p><strong>Pattern 2: Multi-Agent Sequential</strong> <em>(Month 3)</em></p></li><li><p><strong>Pattern 3: Multi-Agent Parallel</strong> <em>(Month 5)</em></p></li><li><p><strong>Pattern 4: Loop</strong> <em>(Month 6)</em></p></li><li><p><strong>Pattern 5: Review and Critique</strong></p></li><li><p><strong>Pattern 6: Iterative Refinement</strong></p></li><li><p><strong>Pattern 7: Coordinator</strong> <em>(Month 9)</em></p></li><li><p><strong>Pattern 8: Hierarchical Task Decomposition</strong> <em>(Month 11)</em></p></li><li><p><strong>Pattern 9: Swarm</strong> <em>(Month 12)</em></p></li><li><p><strong>Pattern 10: ReAct (Reason and Act)</strong> <em>(Month 13)</em></p></li><li><p><strong>Pattern 11: Human-in-the-Loop</strong> <em>(Month 14)</em></p></li><li><p><strong>Pattern 12: Plan-and-Execute</strong> <em>(Month 15)</em></p></li><li><p><strong>Pattern 13: Reflexion</strong> <em>(Month 16)</em></p></li><li><p><strong>Pattern 14: Custom Logic</strong> <em>(Month 18)</em></p></li><li><p><strong>Pattern 15: Event-Driven Agent</strong></p></li></ol><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>We will follow a single company: an e-commerce platform called <strong>Vend</strong>. Their AI platform team starts with <strong>one support agent</strong> and, over eighteen months, evolves into a system spanning multiple patterns. Each shift happened for a reason. <strong>Understanding the reason behind the decision matters more than memorizing the pattern itself.</strong></p><div><hr></div><h2>Before You Pick a Pattern</h2><p>A task justifies an <strong>agent</strong> when at least one of these is true:</p><ul><li><p>A <strong>single model call</strong> cannot produce a reliable result.</p></li><li><p>The model must <strong>choose between tools or data sources at runtime</strong>.</p></li><li><p>The task requires <strong>planning, validation, or iterative refinement</strong>.</p></li><li><p>The workflow contains <strong>uncertainty that cannot be expressed through static business logic</strong>.</p></li></ul><p>A task usually <strong>does not justify an agent</strong> when the input-to-output path is predictable. </p><blockquote><p><em>Tasks like <strong>summarization, classification, templated generation, and simple extraction</strong> are often <strong>faster, cheaper, and more reliable</strong> as direct model calls.</em> </p></blockquote><p>Wrapping them in an agent typically adds <strong>latency, failure points, and unnecessary complexity</strong> without delivering meaningful value.</p><div><hr></div><h2>Shared Infrastructure</h2><p>All examples use the following base structure. In production you would add retries, request IDs, structured logging, rate-limit handling, budget tracking, policy checks, and durable state.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
import os
import asyncio
from dataclasses import dataclass, field
from typing import Any
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
MODEL = "gpt-4o"

@dataclass
class AgentResult:
    content: str
    tool_calls: list[dict] = field(default_factory=list)
    metadata: dict = field(default_factory=dict)

class BaseLLMAgent:
    def __init__(self, model: str = MODEL):
        self.client = client
        self.model = model

    def _text(self, system: str, user: str) -&gt; str:
        response = self.client.responses.create(
            model=self.model,
            input=[
                {"role": "system", "content": system},
                {"role": "user", "content": user},
            ],
        )
        return response.output_text

    def _structured(self, system: str, user: str, schema: dict[str, Any]) -&gt; dict[str, Any]:
        response = self.client.responses.create(
            model=self.model,
            input=[
                {"role": "system", "content": system},
                {"role": "user", "content": user},
            ],
            text={"format": {"type": "json_schema", "name": "output", "schema": schema, "strict": True}},
        )
        return json.loads(response.output_text)
</code></pre></div><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Pattern 1: Single-Agent [Month 1]</h2><p>The AI team gets its first task: let customers ask questions about their orders <strong>without waiting for a human agent</strong>. The workflow is straightforward &#8212; <strong>look up an order, check shipping status, create a support ticket if needed</strong>. Three tools, one clear responsibility</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nSd3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nSd3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 424w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 848w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 1272w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nSd3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png" width="967" height="315" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:315,&quot;width&quot;:967,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34419,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.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_!nSd3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 424w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 848w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 1272w, https://substackcdn.com/image/fetch/$s_!nSd3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e4bb21d-7604-41f7-a157-1eb780526519_967x315.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>This is where most <strong>agentic systems should begin</strong>: <strong>one model, one system prompt, and a bounded set of tools</strong>. The model decides which tool to invoke, observes the result, and continues until it has enough context to respond. Simpler systems are easier to reason about, debug, and improve.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from openai import OpenAI
from dataclasses import dataclass

@dataclass
class OrderContext:
    order_id: str
    status: str
    carrier: str
    eta: str

@dataclass
class SupportTicket:
    ticket_id: str
    order_id: str
    reason: str

class CustomerSupportAgent(BaseLLMAgent):
    """Single-agent that handles order support by choosing its own tools."""

    SYSTEM_PROMPT = (
        "You are a customer support agent. Use tools when order data is needed. "
        "Do not invent order status. If the issue cannot be resolved from tools, create a ticket."
    )

    TOOLS = [
        {
            "type": "function",
            "name": "get_order",
            "description": "Fetch order status by order ID.",
            "parameters": {
                "type": "object",
                "properties": {"order_id": {"type": "string"}},
                "required": ["order_id"],
                "additionalProperties": False,
            },
        },
        {
            "type": "function",
            "name": "create_support_ticket",
            "description": "Create a support ticket when the issue cannot be answered from order data.",
            "parameters": {
                "type": "object",
                "properties": {
                    "order_id": {"type": "string"},
                    "reason": {"type": "string"},
                },
                "required": ["order_id", "reason"],
                "additionalProperties": False,
            },
        },
    ]

    def _get_order(self, order_id: str) -&gt; dict:
        # Replace with real DB/API call
        return {"order_id": order_id, "status": "shipped", "carrier": "DHL", "eta": "2026-06-01"}

    def _create_support_ticket(self, order_id: str, reason: str) -&gt; dict:
        return {"ticket_id": "SUP-1042", "order_id": order_id, "reason": reason}

    def _dispatch_tool(self, name: str, args: dict) -&gt; dict:
        if name == "get_order":
            return self._get_order(**args)
        if name == "create_support_ticket":
            return self._create_support_ticket(**args)
        return {"error": f"Unknown tool: {name}"}

    def run(self, user_message: str, max_turns: int = 4) -&gt; str:
        messages = [
            {"role": "system", "content": self.SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ]

        for _ in range(max_turns):
            response = self.client.responses.create(
                model=self.model, input=messages, tools=self.TOOLS
            )
            tool_calls = [item for item in response.output if item.type == "function_call"]

            if not tool_calls:
                return response.output_text

            messages += response.output
            for call in tool_calls:
                result = self._dispatch_tool(call.name, json.loads(call.arguments))
                messages.append({
                    "type": "function_call_output",
                    "call_id": call.call_id,
                    "output": json.dumps(result),
                })

        return "I could not complete the request safely within the tool budget."
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P0T7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P0T7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 424w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 848w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P0T7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png&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;:223109,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.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_!P0T7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 424w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 848w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!P0T7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa921d032-8e3c-400e-a569-3ede7ae4be4c_1864x1048.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 2: Multi-Agent Sequential [<strong>Month 3]</strong></h2><p>Legal operations receives <strong>vendor contracts</strong>, and the review process is well-defined: <strong>extract obligations, identify risk clauses, and draft a summary for the procurement manager</strong>. The sequence never changes, and each step produces exactly what the next step requires.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bt_j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bt_j!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 424w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 848w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 1272w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bt_j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png" width="974" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f571240d-2ead-4403-b69c-9d78654fe278_974x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:974,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20869,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.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_!bt_j!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 424w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 848w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 1272w, https://substackcdn.com/image/fetch/$s_!bt_j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff571240d-2ead-4403-b69c-9d78654fe278_974x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>The <strong>sequential pattern</strong> runs <strong>specialized agents in a fixed order</strong>. Each agent has a <strong>narrow prompt</strong> and a <strong>clear input/output contract</strong>. Orchestration is <strong>deterministic</strong> &#8212; reasoning happens <strong>within each stage</strong>, not in the routing between agents, making the process predictable and auditable.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from dataclasses import dataclass

@dataclass
class ContractAnalysis:
    obligations: str
    risks: str
    review_packet: str

class ContractIntakePipeline(BaseLLMAgent):
    """Sequential pipeline: extract &#8594; assess &#8594; draft."""

    def _extract_obligations(self, contract_text: str) -&gt; str:
        return self._text(
            "Extract concrete obligations from vendor contracts. "
            "Return only obligations with dates, parties, or deliverables.",
            contract_text,
        )

    def _assess_risks(self, obligations: str) -&gt; str:
        return self._text(
            "You are a contract risk reviewer. Identify operational, financial, and compliance risks. "
            "Do not provide legal advice.",
            obligations,
        )

    def _draft_review_packet(self, contract_text: str, obligations: str, risks: str) -&gt; str:
        return self._text(
            "Prepare a concise contract review packet for a procurement manager. "
            "Include obligations, risks, and questions for counsel.",
            f"Contract:\\\\n{contract_text}\\\\n\\\\nObligations:\\\\n{obligations}\\\\n\\\\nRisks:\\\\n{risks}",
        )

    def run(self, contract_text: str) -&gt; ContractAnalysis:
        obligations = self._extract_obligations(contract_text)
        risks = self._assess_risks(obligations)
        packet = self._draft_review_packet(contract_text, obligations, risks)
        return ContractAnalysis(obligations=obligations, risks=risks, review_packet=packet)
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_XNn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_XNn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 424w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 848w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 1272w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_XNn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png" width="1456" height="692" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:692,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!_XNn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 424w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 848w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 1272w, https://substackcdn.com/image/fetch/$s_!_XNn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55a7e617-e244-436f-bcab-16ab14c6120e_1868x888.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 3: Multi-Agent Parallel [<strong>Month 5]</strong></h2><p>The on-call team gets a <strong>midnight alert</strong>: checkout is failing. Three signals need immediate investigation &#8212; <strong>application logs, infrastructure metrics, and recent deployments</strong>. These are genuinely independent sources of information. Running them sequentially wastes the <strong>first few minutes that matter most during an incident</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CRD6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CRD6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 424w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 848w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 1272w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CRD6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png" width="976" height="521" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eb65c892-97af-4597-a4e1-debeb2a73219_976x521.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:521,&quot;width&quot;:976,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45746,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.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_!CRD6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 424w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 848w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 1272w, https://substackcdn.com/image/fetch/$s_!CRD6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb65c892-97af-4597-a4e1-debeb2a73219_976x521.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>The <strong>parallel pattern</strong> distributes <strong>independent subtasks across multiple agents simultaneously</strong> and combines their outputs into a single view. When tasks do not depend on one another, parallelism reduces latency and speeds up decision-making under pressure.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import asyncio
from dataclasses import dataclass

@dataclass
class IncidentReport:
    log_analysis: str
    metric_analysis: str
    deployment_analysis: str
    synthesis: str

class IncidentTriageAgent(BaseLLMAgent):
    """Parallelizes three specialist agents then synthesizes a root-cause hypothesis."""

    async def _ask_specialist(self, role_prompt: str, incident: str) -&gt; str:
        return await asyncio.to_thread(self._text, role_prompt, incident)

    async def run(self, incident_description: str) -&gt; IncidentReport:
        log_prompt = "You inspect application logs. Identify error patterns with timestamps and request IDs."
        metric_prompt = "You inspect metrics. Identify saturation, latency spikes, and traffic anomalies."
        deploy_prompt = "You inspect recent releases. Flag risky changes that align with the reported symptoms."

        log_view, metric_view, deploy_view = await asyncio.gather(
            self._ask_specialist(log_prompt, incident_description),
            self._ask_specialist(metric_prompt, incident_description),
            self._ask_specialist(deploy_prompt, incident_description),
        )

        synthesis = self._text(
            "You are the incident commander. Synthesize evidence from three specialist views. "
            "State confidence level and the single safest next action.",
            f"Logs:\\\\n{log_view}\\\\n\\\\nMetrics:\\\\n{metric_view}\\\\n\\\\nDeployments:\\\\n{deploy_view}",
        )

        return IncidentReport(
            log_analysis=log_view,
            metric_analysis=metric_view,
            deployment_analysis=deploy_view,
            synthesis=synthesis,
        )
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MF90!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MF90!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 424w, https://substackcdn.com/image/fetch/$s_!MF90!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 848w, https://substackcdn.com/image/fetch/$s_!MF90!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 1272w, https://substackcdn.com/image/fetch/$s_!MF90!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MF90!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png" width="1456" height="595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:595,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!MF90!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 424w, https://substackcdn.com/image/fetch/$s_!MF90!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 848w, https://substackcdn.com/image/fetch/$s_!MF90!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 1272w, https://substackcdn.com/image/fetch/$s_!MF90!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7c08224-ba90-4133-b4bd-428e0a96f0d6_1866x762.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 4: Loop [<strong>Month 6]</strong></h2><p>The data engineering team ingests <strong>CSV extracts from third-party suppliers</strong>, where data quality is often inconsistent. They need an agent that can <strong>profile the data, propose a cleaning strategy, validate it against quality checks, and retry when needed</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lItq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lItq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 424w, https://substackcdn.com/image/fetch/$s_!lItq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 848w, https://substackcdn.com/image/fetch/$s_!lItq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 1272w, https://substackcdn.com/image/fetch/$s_!lItq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lItq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png" width="974" height="151" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:151,&quot;width&quot;:974,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23693,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.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_!lItq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 424w, https://substackcdn.com/image/fetch/$s_!lItq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 848w, https://substackcdn.com/image/fetch/$s_!lItq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 1272w, https://substackcdn.com/image/fetch/$s_!lItq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89507769-5d3e-47d2-a61a-043dd1cacad2_974x151.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The <strong>loop pattern</strong> repeats a sequence of agent steps until an <strong>exit condition</strong> is satisfied. The challenge is not the loop itself &#8212; it is defining a <strong>reliable stopping condition</strong>. Without one, you end up with <strong>runaway costs, unpredictable behavior, and no guarantee of termination</strong>.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class CleaningResult:
    plan: str
    rounds_taken: int
    passed: bool

class DataQualityRepairAgent(BaseLLMAgent):
    """Iteratively proposes and judges cleaning plans until quality passes or budget is exhausted."""

    QUALITY_SCHEMA = {
        "type": "object",
        "properties": {
            "passes": {"type": "boolean"},
            "reason": {"type": "string"},
            "remaining_issues": {"type": "array", "items": {"type": "string"}},
        },
        "required": ["passes", "reason", "remaining_issues"],
        "additionalProperties": False,
    }

    def _profile(self, sample_rows: str) -&gt; str:
        return self._text(
            "Profile tabular data. Identify missing values, inconsistent formats, "
            "suspicious categories, and likely schema issues.",
            sample_rows,
        )

    def _propose_plan(self, profile: str, previous_plan: str | None) -&gt; str:
        return self._text(
            "Propose a safe pandas cleaning plan. Prefer reversible transformations. "
            "Do not drop columns unless explicitly justified.",
            f"Profile:\\\\n{profile}\\\\n\\\\nPrevious attempt:\\\\n{previous_plan or 'None'}",
        )

    def _judge(self, profile: str, plan: str) -&gt; dict:
        return self._structured(
            "Judge whether the cleaning plan addresses the data profile without unsafe assumptions.",
            f"Profile:\\\\n{profile}\\\\n\\\\nPlan:\\\\n{plan}",
            self.QUALITY_SCHEMA,
        )

    def run(self, sample_rows: str, max_rounds: int = 3) -&gt; CleaningResult:
        profile = self._profile(sample_rows)
        plan = None

        for round_num in range(1, max_rounds + 1):
            plan = self._propose_plan(profile, plan)
            verdict = self._judge(profile, plan)

            if verdict["passes"]:
                return CleaningResult(plan=plan, rounds_taken=round_num, passed=True)

            # Append reviewer feedback to the profile so the next proposal is informed
            profile += f"\\\\nReviewer feedback (round {round_num}):\\\\n{json.dumps(verdict)}"

        return CleaningResult(plan=plan, rounds_taken=max_rounds, passed=False)
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!npQ0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!npQ0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 424w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 848w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 1272w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!npQ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png" width="1456" height="614" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:614,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!npQ0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 424w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 848w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 1272w, https://substackcdn.com/image/fetch/$s_!npQ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e25df22-4196-4c9b-91c3-834161df85a9_1868x788.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><blockquote><p><em><strong>Note:</strong> This is a simplified example of using <strong>LLM-as-a-Judge</strong> to review and approve another model&#8217;s response.</em></p><p><em>In this example, the flow uses a <strong>loop with a boolean approval flag</strong>. In practice, there are many variations. Instead of a binary decision, the judge can return a <strong>score</strong>, or provide <strong>structured feedback</strong> that the generator uses to improve the next iteration. The design space here is broad, so I am intentionally keeping the implementation lightweight.</em></p><p><em><strong>&#9989; Pattern 5: Review and Critique</strong> &#8594; A judge agent <strong>reviews the output, critiques it, and provides actionable feedback</strong> on what should improve.</em></p><p><em><strong>&#9989; Pattern 6: Iterative Refinement</strong> &#8594; The system runs in a <strong>feedback loop with a score threshold</strong>. Until the response crosses the required quality bar, the generator continues refining the output.</em></p></blockquote><div><hr></div><h2>Pattern 7: Coordinator [<strong>Month 9]</strong></h2><p>Support has expanded into <strong>five distinct departments</strong>: <strong>billing, technical support, account management, shipping, and fraud</strong>. A single agent trying to handle all of them ends up relying on a <strong>3,000-word system prompt</strong>, eventually struggling with edge cases and conflicting instructions. At that point, the issue is no longer prompt quality &#8212; <strong>different request types genuinely require different context, tools, and decision-making logic</strong>.</p><p>The <strong>coordinator pattern</strong> introduces a <strong>central routing agent</strong> that directs incoming requests to <strong>specialized agents</strong>. Unlike <strong>sequential</strong> or <strong>parallel</strong> workflows, the execution path is <strong>determined dynamically at runtime</strong>, based on the nature of the request. This keeps individual agents focused, reduces prompt complexity, and improves reliability as the system grows.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W6dR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W6dR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 424w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 848w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 1272w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W6dR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png" width="973" height="334" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:334,&quot;width&quot;:973,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37416,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.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_!W6dR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 424w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 848w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 1272w, https://substackcdn.com/image/fetch/$s_!W6dR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F918278a6-0caa-4bd1-a829-80e8248971b2_973x334.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from dataclasses import dataclass

@dataclass
class RoutingDecision:
    specialist: str
    reason: str

class SupportCoordinator(BaseLLMAgent):
    """Routes support messages to the right specialist agent."""

    ROUTING_SCHEMA = {
        "type": "object",
        "properties": {
            "specialist": {
                "type": "string",
                "enum": ["billing", "technical", "account", "shipping", "fraud"],
            },
            "reason": {"type": "string"},
        },
        "required": ["specialist", "reason"],
        "additionalProperties": False,
    }

    SPECIALISTS: dict[str, str] = {
        "billing": "You handle billing support. Request invoice IDs when needed. Never quote prices from memory.",
        "technical": "You handle technical troubleshooting. Ask for logs and environment details when needed.",
        "account": "You handle account access issues. Never request passwords or raw secrets.",
        "shipping": "You handle delivery and tracking questions. Escalate customs issues to a human agent.",
        "fraud": "You handle suspected fraud reports. Collect evidence carefully. Never accuse the customer.",
    }

    def _route(self, message: str) -&gt; RoutingDecision:
        result = self._structured(
            "Route this support request to exactly one specialist based on the primary issue.",
            message,
            self.ROUTING_SCHEMA,
        )
        return RoutingDecision(**result)

    def _run_specialist(self, specialist_prompt: str, message: str) -&gt; str:
        return self._text(specialist_prompt, message)

    def run(self, message: str) -&gt; str:
        decision = self._route(message)
        specialist_prompt = self.SPECIALISTS[decision.specialist]
        return self._run_specialist(specialist_prompt, message)</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Yk-M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Yk-M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 424w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 848w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 1272w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Yk-M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png" width="1456" height="690" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:690,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164421,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.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_!Yk-M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 424w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 848w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 1272w, https://substackcdn.com/image/fetch/$s_!Yk-M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94d7d97-57cb-4a01-bb39-387c36d4ade9_1870x886.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 8: Hierarchical Task Decomposition [<strong>Month 11]</strong></h2><p>Strategy asks the AI platform team: <strong>&#8220;Which three countries should we expand into next year?&#8221;</strong> This is not a typical support task &#8212; it is a <strong>multi-dimensional research problem</strong>. No single agent can answer it reliably. The question needs to be broken down into <strong>competitive analysis, regulatory constraints, logistics feasibility, and market sizing</strong>, each requiring <strong>specialized context and reasoning</strong>.</p><p>The <strong>hierarchical decomposition pattern</strong> uses a <strong>root agent</strong> to break a complex objective into <strong>smaller, well-defined subgoals</strong>, which are then delegated to <strong>specialized worker agents</strong>. Once the work is complete, the root agent <strong>synthesizes the outputs into a coherent recommendation</strong>. This pattern works best when the problem is too broad for a single reasoning pass but can be decomposed into independent areas 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_!gxM5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gxM5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 424w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 848w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 1272w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gxM5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png" width="971" height="907" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/875f1762-5307-4141-b394-5d0cd6595f96_971x907.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:907,&quot;width&quot;:971,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57756,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.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_!gxM5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 424w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 848w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 1272w, https://substackcdn.com/image/fetch/$s_!gxM5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875f1762-5307-4141-b394-5d0cd6595f96_971x907.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class Workstream:
    name: str
    deliverable: str
    questions: list[str]

@dataclass
class ResearchBrief:
    goal: str
    workstreams: list[Workstream]
    reports: list[str]
    synthesis: str

class MarketExpansionResearchAgent(BaseLLMAgent):
    """Decomposes a research goal into workstreams, executes each, and synthesizes results."""

    PLAN_SCHEMA = {
        "type": "object",
        "properties": {
            "workstreams": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "deliverable": {"type": "string"},
                        "questions": {"type": "array", "items": {"type": "string"}},
                    },
                    "required": ["name", "deliverable", "questions"],
                    "additionalProperties": False,
                },
            }
        },
        "required": ["workstreams"],
        "additionalProperties": False,
    }

    def _plan(self, goal: str) -&gt; list[Workstream]:
        result = self._structured(
            "Break a market expansion research goal into 3 to 5 independent workstreams. "
            "Each workstream must have a clear deliverable and 2-4 focused questions.",
            goal,
            self.PLAN_SCHEMA,
        )
        return [Workstream(**ws) for ws in result["workstreams"]]

    def _execute_workstream(self, ws: Workstream) -&gt; str:
        return self._text(
            "You are a specialist research agent. Answer only the assigned workstream. "
            "List assumptions and evidence gaps separately. Be specific.",
            json.dumps({"name": ws.name, "deliverable": ws.deliverable, "questions": ws.questions}),
        )

    def _synthesize(self, goal: str, reports: list[str]) -&gt; str:
        combined = "\\\\n\\\\n".join(
            f"--- Workstream {i+1} ---\\\\n{r}" for i, r in enumerate(reports)
        )
        return self._text(
            "Synthesize specialist research reports into an executive brief. "
            "Highlight conflicts between workstreams, unsupported assumptions, and missing evidence.",
            f"Goal: {goal}\\\\n\\\\nWorkstream reports:\\\\n{combined}",
        )

    def run(self, goal: str) -&gt; ResearchBrief:
        workstreams = self._plan(goal)
        reports = [self._execute_workstream(ws) for ws in workstreams]
        synthesis = self._synthesize(goal, reports)
        return ResearchBrief(goal=goal, workstreams=workstreams, reports=reports, synthesis=synthesis)</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mo1b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mo1b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 424w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 848w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 1272w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mo1b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png" width="1456" height="699" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:699,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:166090,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.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_!mo1b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 424w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 848w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 1272w, https://substackcdn.com/image/fetch/$s_!mo1b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc99f8b72-959d-4e60-802a-7ef3daee4fb0_1862x894.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 9: Swarm [Month 12]</h2><p>The product team faces a contentious question: <strong>should they launch a subscription tier?</strong> Research suggests customers want it. Engineering estimates <strong>six months of billing infrastructure work</strong>. Finance questions whether the <strong>unit economics make sense</strong>, while Support expects a spike in <strong>customer confusion and ticket volume</strong>. Every perspective is valid, but the team needs a way to surface the trade-offs before leadership makes a decision.</p><p>The <strong>swarm pattern</strong> allows <strong>multiple specialized agents</strong> to contribute to a <strong>shared working context</strong>. Each agent brings a different perspective, challenges assumptions, and adds supporting evidence. Once enough signal has accumulated, a <strong>facilitator agent</strong> synthesizes the discussion into a recommendation. This pattern works best when the goal is not a single &#8220;correct&#8221; answer, but a <strong>well-reasoned decision shaped by competing viewpoints</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XlEt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XlEt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 424w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 848w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 1272w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XlEt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png" width="974" height="546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0581186-e2e5-489a-8215-097129972697_974x546.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:546,&quot;width&quot;:974,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45412,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.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_!XlEt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 424w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 848w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 1272w, https://substackcdn.com/image/fetch/$s_!XlEt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0581186-e2e5-489a-8215-097129972697_974x546.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from dataclasses import dataclass

@dataclass
class DebateResult:
    question: str
    transcript: str
    recommendation: str

class ProductDecisionSwarm(BaseLLMAgent):
    """Runs a structured debate across specialist perspectives before synthesizing a recommendation."""

    ROLES: dict[str, str] = {
        "research": "You represent user research. Cite evidence, customer segments, and unmet needs. Challenge unsupported claims.",
        "engineering": "You represent engineering. Assess feasibility, complexity, risks, and maintenance burden.",
        "finance": "You represent finance. Evaluate pricing, margin, cost, and opportunity cost.",
        "support": "You represent customer support. Assess operational burden, edge cases, and customer confusion risks.",
    }

    def run(self, question: str, rounds: int = 2) -&gt; DebateResult:
        transcript = f"Decision question: {question}\\\\n"

        for round_no in range(1, rounds + 1):
            for name, role_prompt in self.ROLES.items():
                contribution = self._text(
                    role_prompt + " Respond to the current transcript. "
                    "Add new evidence or challenge a specific weak claim. Be concise and specific.",
                    transcript,
                )
                transcript += f"\\\\n[{name}, round {round_no}]\\\\n{contribution}\\\\n"

        recommendation = self._text(
            "You are a neutral decision facilitator. Review the full debate. "
            "Summarize the strongest arguments, identify unresolved risks, and state a final recommendation. "
            "Do not add new claims &#8212; only synthesize what is already in the transcript.",
            transcript,
        )

        return DebateResult(question=question, transcript=transcript, recommendation=recommendation)</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MKvd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MKvd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 424w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 848w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 1272w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MKvd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png" width="1456" height="655" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:655,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:155227,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.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_!MKvd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 424w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 848w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 1272w, https://substackcdn.com/image/fetch/$s_!MKvd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccf7deb0-ffc3-4928-9cfd-35e0b75d1861_1984x892.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 10: ReAct (Reason and Act) [Month 13]</h2><p>The DevOps team builds an <strong>internal troubleshooting assistant</strong>. When an engineer reports that <strong>&#8220;the queue processor seems stuck,&#8221;</strong> the assistant should <strong>search documentation, check service health, correlate symptoms, and only then suggest a fix</strong>. The investigation path cannot be predefined &#8212; it depends entirely on what the system uncovers along the way.</p><p>The <strong>ReAct pattern</strong> alternates between <strong>reasoning and action</strong>: deciding what to investigate, invoking a tool, observing the result, and determining whether there is enough evidence to proceed or answer. The most valuable output is not the hidden reasoning itself &#8212; it is the <strong>action trace</strong>, which makes the investigation <strong>observable, debuggable, and easier to trust in production</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B9Bh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B9Bh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 424w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 848w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 1272w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B9Bh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png" width="978" height="307" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:307,&quot;width&quot;:978,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36267,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.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_!B9Bh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 424w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 848w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 1272w, https://substackcdn.com/image/fetch/$s_!B9Bh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689b0ae1-b111-4ea7-8f2f-7c37afbd2c8f_978x307.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class TroubleshootingResult:
    answer: str
    action_trace: list[dict]

class KnowledgeBaseTroubleshootingAgent(BaseLLMAgent):
    """Iteratively calls tools to gather evidence before stating a root cause."""

    SYSTEM_PROMPT = (
        "You are a troubleshooting agent. Use tools to gather evidence. "
        "Return the likely cause, your confidence level, and the next safe action. "
        "Do not speculate beyond what the tools returned."
    )

    TOOLS = [
        {
            "type": "function",
            "name": "search_docs",
            "description": "Search internal troubleshooting documentation by keyword.",
            "parameters": {
                "type": "object",
                "properties": {"query": {"type": "string"}},
                "required": ["query"],
                "additionalProperties": False,
            },
        },
        {
            "type": "function",
            "name": "get_service_status",
            "description": "Get current operational status and recent incidents for a service.",
            "parameters": {
                "type": "object",
                "properties": {"service": {"type": "string"}},
                "required": ["service"],
                "additionalProperties": False,
            },
        },
    ]

    def _search_docs(self, query: str) -&gt; dict:
        return {"matches": ["Restart workers after QUEUE_URL change", "Check IAM permission sqs:SendMessage"]}

    def _get_service_status(self, service: str) -&gt; dict:
        return {"service": service, "status": "degraded", "since": "2026-05-21T09:20:00Z"}

    def _dispatch_tool(self, name: str, args: dict) -&gt; dict:
        if name == "search_docs":
            return self._search_docs(**args)
        if name == "get_service_status":
            return self._get_service_status(**args)
        return {"error": f"Unknown tool: {name}"}

    def run(self, problem: str, max_turns: int = 5) -&gt; TroubleshootingResult:
        messages = [
            {"role": "system", "content": self.SYSTEM_PROMPT},
            {"role": "user", "content": problem},
        ]
        action_trace = []

        for _ in range(max_turns):
            response = self.client.responses.create(
                model=self.model, input=messages, tools=self.TOOLS
            )
            calls = [item for item in response.output if item.type == "function_call"]

            if not calls:
                return TroubleshootingResult(answer=response.output_text, action_trace=action_trace)

            messages += response.output
            for call in calls:
                args = json.loads(call.arguments)
                result = self._dispatch_tool(call.name, args)
                action_trace.append({"tool": call.name, "args": args, "result": result})
                messages.append({
                    "type": "function_call_output",
                    "call_id": call.call_id,
                    "output": json.dumps(result),
                })

        return TroubleshootingResult(
            answer="Investigation limit reached without sufficient evidence.",
            action_trace=action_trace,
        )
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qvln!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qvln!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 424w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 848w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 1272w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qvln!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png" width="1456" height="654" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:654,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:161962,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.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_!Qvln!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 424w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 848w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 1272w, https://substackcdn.com/image/fetch/$s_!Qvln!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccaf3598-6d0c-4adf-b78c-7603c10a6513_1978x888.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 11: Human-in-the-Loop [<strong>Month 14]</strong></h2><p>The finance team wants to automate <strong>refund approvals</strong>, but only for <strong>low-risk, clear-cut cases</strong>. Requests involving <strong>high amounts, fraud signals, or policy exceptions</strong> still require <strong>human approval</strong>. The agent&#8217;s role is to <strong>investigate the case, gather context, and recommend an action</strong> &#8212; the final decision remains with a person.</p><p>This pattern is <strong>not just a UI workflow</strong> &#8212; it is an <strong>architectural decision</strong>. You need <strong>durable state, reviewer assignment, approval logs, timeout handling, escalation paths, and safe recovery mechanisms</strong>. The agent&#8217;s responsibility is to <strong>prepare evidence and hand off context</strong>, not pause indefinitely waiting for a human response.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QTRO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QTRO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 424w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 848w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 1272w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QTRO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png" width="979" height="62" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c86e301d-2c05-4e38-b119-31a858f90770_979x62.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:62,&quot;width&quot;:979,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17403,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.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_!QTRO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 424w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 848w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 1272w, https://substackcdn.com/image/fetch/$s_!QTRO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc86e301d-2c05-4e38-b119-31a858f90770_979x62.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class HumanApproval:
    approved: bool
    reviewer: str
    comment: str

@dataclass
class RefundOutcome:
    recommendation: str
    approval: HumanApproval
    customer_response: str

class RefundApprovalAgent(BaseLLMAgent):
    """Investigates refund request, prepares recommendation, pauses for human approval."""

    def _lookup_context(self, order_id: str) -&gt; dict:
        # Replace with real payment service call
        return {
            "order_id": order_id,
            "amount": 420.00,
            "days_since_purchase": 12,
            "prior_refunds": 0,
            "fraud_score": 0.02,
        }

    def _build_recommendation(self, customer_message: str, context: dict) -&gt; str:
        return self._text(
            "You are a refund operations agent. Recommend approve, deny, or request more information. "
            "Cite specific policy facts. Do not approve if fraud score exceeds 0.1.",
            f"Customer message:\\\\n{customer_message}\\\\n\\\\nOrder context:\\\\n{json.dumps(context)}",
        )

    def _request_human_approval(self, recommendation: str) -&gt; HumanApproval:
        # In production: create a review task in the ops queue (Slack, Jira, internal tool).
        # Block until approved or timed out. This stub simulates a reviewer response.
        return HumanApproval(
            approved=False,
            reviewer="ops-manager",
            comment="Ask customer for photos of the damaged item first.",
        )

    def _draft_customer_response(self, recommendation: str, approval: HumanApproval) -&gt; str:
        review_summary = json.dumps({"approved": approval.approved, "comment": approval.comment})
        return self._text(
            "Draft a customer-safe response based on the manager's review decision. "
            "Do not claim the refund is approved unless it is. Be empathetic but accurate.",
            f"Agent recommendation:\\\\n{recommendation}\\\\n\\\\nHuman review:\\\\n{review_summary}",
        )

    def run(self, order_id: str, customer_message: str) -&gt; RefundOutcome:
        context = self._lookup_context(order_id)
        recommendation = self._build_recommendation(customer_message, context)
        approval = self._request_human_approval(recommendation)
        customer_response = self._draft_customer_response(recommendation, approval)
        return RefundOutcome(
            recommendation=recommendation,
            approval=approval,
            customer_response=customer_response,
        )
</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qduk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qduk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 424w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 848w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 1272w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qduk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png" width="1456" height="656" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:656,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162034,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.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_!Qduk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 424w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 848w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 1272w, https://substackcdn.com/image/fetch/$s_!Qduk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a516a0d-35d7-49e8-ab86-8517e35265f2_1966x886.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 12: Plan-and-Execute [<strong>Month 15]</strong></h2><p>The DevOps team wants an agent that can handle <strong>multi-step infrastructure operations</strong> from a natural language request: <strong>&#8220;Resize the worker fleet from 10 to 20 instances, verify the queue drains, and update the runbook.&#8221;</strong> The objective is clear, but the exact execution path depends on <strong>what the system discovers at each step</strong>.</p><p>The <strong>Plan-and-Execute pattern</strong> separates <strong>planning from execution</strong>. A <strong>planner agent</strong> first reasons about the strategy and produces a <strong>structured task plan</strong> before any action is taken. This plan can be <strong>reviewed, modified, or approved by humans</strong>. An <strong>executor agent</strong> then carries out the steps one at a time, adapting as needed during execution.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UGm2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UGm2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 424w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 848w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 1272w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UGm2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png" width="975" height="153" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:153,&quot;width&quot;:975,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22318,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.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_!UGm2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 424w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 848w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 1272w, https://substackcdn.com/image/fetch/$s_!UGm2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe79c714f-edd6-4c61-92a1-67a5a60b459d_975x153.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><blockquote><p><em>This differs from <strong>hierarchical decomposition</strong>, where tasks are recursively broken into subgoals. Here, planning is <strong>a one-time decomposition into an execution plan</strong>. It also differs from <strong>ReAct</strong> &#8212; the <strong>entire plan is visible upfront</strong>, rather than emerging incrementally through action and observation.</em></p></blockquote><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class ExecutionStep:
    step_id: int
    action: str
    tool: str
    parameters: dict
    expected_outcome: str

@dataclass
class ExecutionPlan:
    goal: str
    steps: list[ExecutionStep]

@dataclass
class ExecutionResult:
    plan: ExecutionPlan
    step_results: list[dict]
    summary: str

class PlanAndExecuteAgent(BaseLLMAgent):
    """Generates a structured plan before taking any actions, then executes step by step."""

    PLAN_SCHEMA = {
        "type": "object",
        "properties": {
            "steps": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "step_id": {"type": "integer"},
                        "action": {"type": "string"},
                        "tool": {"type": "string", "enum": ["resize_fleet", "check_queue_depth", "update_runbook"]},
                        "parameters": {"type": "object", "additionalProperties": {"type": "string"}},
                        "expected_outcome": {"type": "string"},
                    },
                    "required": ["step_id", "action", "tool", "parameters", "expected_outcome"],
                    "additionalProperties": False,
                },
            }
        },
        "required": ["steps"],
        "additionalProperties": False,
    }

    def _plan(self, goal: str) -&gt; ExecutionPlan:
        result = self._structured(
            "Create a step-by-step execution plan for the given infrastructure task. "
            "Order steps by dependency. Use only available tools.",
            goal,
            self.PLAN_SCHEMA,
        )
        steps = [ExecutionStep(**s) for s in result["steps"]]
        return ExecutionPlan(goal=goal, steps=steps)

    def _execute_step(self, step: ExecutionStep) -&gt; dict:
        # Real implementation would dispatch to infrastructure APIs
        return {"step_id": step.step_id, "status": "completed", "output": f"Executed: {step.action}"}

    def _summarize(self, plan: ExecutionPlan, results: list[dict]) -&gt; str:
        return self._text(
            "Summarize the execution results. Flag any steps that did not complete as expected.",
            f"Goal: {plan.goal}\\\\n\\\\nResults:\\\\n{json.dumps(results, indent=2)}",
        )

    def run(self, goal: str) -&gt; ExecutionResult:
        plan = self._plan(goal)
        step_results = []

        for step in plan.steps:
            result = self._execute_step(step)
            step_results.append(result)
            # In production: halt here if the step failed; surface for human review
            if result.get("status") != "completed":
                break

        summary = self._summarize(plan, step_results)
        return ExecutionResult(plan=plan, step_results=step_results, summary=summary)</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qk7w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qk7w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 424w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 848w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 1272w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qk7w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png" width="1456" height="605" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:605,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Qk7w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 424w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 848w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 1272w, https://substackcdn.com/image/fetch/$s_!Qk7w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69422b60-f703-4378-879f-ebe4c477b7c0_1838x764.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 13: Reflexion [<strong>Month 16]</strong></h2><p>The data team asks the AI platform to generate <strong>Python scripts for one-off data transformations</strong>. The first attempt often <strong>compiles successfully but breaks at runtime</strong>, usually on edge cases or unexpected inputs. Instead of escalating failures to a human, the team wants the agent to <strong>analyze the error, understand what went wrong, and retry with a better approach</strong>.</p><p>The <strong>Reflexion pattern</strong> gives agents the ability to <strong>learn from their own failures</strong>. Unlike a standard <strong>loop pattern</strong>, where retries are driven by an external judge, the agent <strong>evaluates its own output, reflects on the failure, and records observations</strong> about what went wrong. That memory then <strong>directly influences the next attempt</strong>, improving performance over time rather than repeating the same mistake.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iepw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iepw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 424w, https://substackcdn.com/image/fetch/$s_!iepw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 848w, https://substackcdn.com/image/fetch/$s_!iepw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 1272w, https://substackcdn.com/image/fetch/$s_!iepw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iepw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png" width="976" height="218" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:218,&quot;width&quot;:976,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28623,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.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_!iepw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 424w, https://substackcdn.com/image/fetch/$s_!iepw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 848w, https://substackcdn.com/image/fetch/$s_!iepw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 1272w, https://substackcdn.com/image/fetch/$s_!iepw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F911fe5a0-e160-453d-bba7-6d28e1fd20c8_976x218.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import json
from dataclasses import dataclass

@dataclass
class ReflexionMemory:
    attempt: int
    output: str
    error: str | None
    reflection: str

@dataclass
class ReflexionResult:
    final_output: str
    memory: list[ReflexionMemory]
    succeeded: bool

class ReflexionCodingAgent(BaseLLMAgent):
    """Generates code, simulates execution, reflects on failures, and retries with accumulated memory."""

    REFLECTION_SCHEMA = {
        "type": "object",
        "properties": {
            "succeeded": {"type": "boolean"},
            "error_analysis": {"type": "string"},
            "what_to_fix": {"type": "string"},
        },
        "required": ["succeeded", "error_analysis", "what_to_fix"],
        "additionalProperties": False,
    }

    def _generate(self, task: str, memory: list[ReflexionMemory]) -&gt; str:
        memory_context = "\\\\n\\\\n".join(
            f"Attempt {m.attempt}: FAILED\\\\nError: {m.error}\\\\nReflection: {m.reflection}"
            for m in memory
            if m.error
        )
        return self._text(
            "Write a Python function for the given data transformation task. "
            "Handle edge cases explicitly. Learn from past failures.",
            f"Task:\\\\n{task}\\\\n\\\\nPast failures:\\\\n{memory_context or 'None yet'}",
        )

    def _execute_and_observe(self, code: str) -&gt; tuple[str | None, str | None]:
        """Returns (output, error). Replace with sandbox execution in production."""
        try:
            # Simulate execution &#8212; in production use a sandbox (e.g., subprocess, E2B)
            exec_globals: dict = {}
            exec(compile(code, "&lt;agent&gt;", "exec"), exec_globals)
            return "Executed successfully", None
        except Exception as e:
            return None, str(e)

    def _reflect(self, code: str, error: str) -&gt; str:
        result = self._structured(
            "Analyze why this code failed. Identify the root cause and what should change in the next attempt.",
            f"Code:\\\\n{code}\\\\n\\\\nError:\\\\n{error}",
            self.REFLECTION_SCHEMA,
        )
        return result["what_to_fix"]

    def run(self, task: str, max_attempts: int = 3) -&gt; ReflexionResult:
        memory: list[ReflexionMemory] = []

        for attempt in range(1, max_attempts + 1):
            code = self._generate(task, memory)
            output, error = self._execute_and_observe(code)

            if error is None:
                memory.append(ReflexionMemory(attempt=attempt, output=code, error=None, reflection="Succeeded"))
                return ReflexionResult(final_output=code, memory=memory, succeeded=True)

            reflection = self._reflect(code, error)
            memory.append(ReflexionMemory(attempt=attempt, output=code, error=error, reflection=reflection))

        return ReflexionResult(final_output=memory[-1].output, memory=memory, succeeded=False)</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!crIF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!crIF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 424w, https://substackcdn.com/image/fetch/$s_!crIF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 848w, https://substackcdn.com/image/fetch/$s_!crIF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 1272w, https://substackcdn.com/image/fetch/$s_!crIF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!crIF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png" width="1456" height="454" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:454,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:128191,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.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_!crIF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 424w, https://substackcdn.com/image/fetch/$s_!crIF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 848w, https://substackcdn.com/image/fetch/$s_!crIF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 1272w, https://substackcdn.com/image/fetch/$s_!crIF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57c4c52c-270d-4ae6-859f-a1c50b98c29c_1834x572.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 14: Custom Logic [<strong>Month 18]</strong></h2><p>The refund workflow has outgrown every <strong>clean architectural pattern</strong>. A <strong>high-value damaged-goods refund</strong> follows a different path than a standard return. <strong>Fraud signals</strong> route cases to specialists. Some checks can run <strong>in parallel</strong>, others require <strong>human approval</strong>, and certain situations call for <strong>store credit instead of a cash refund</strong>. At this stage, the business process contains <strong>real branching logic</strong>, and those branches often carry <strong>legal or financial consequences</strong>.</p><p>The <strong>custom logic pattern</strong> combines <strong>deterministic orchestration with agentic behavior</strong>. The challenge is deciding <strong>what belongs in code and what belongs in the model</strong>. <strong>Eligibility rules, permission checks, payment actions, and safety constraints</strong> should remain <strong>deterministic and auditable</strong>. Meanwhile, tasks involving <strong>interpretation, drafting, routing recommendations, and exception handling</strong> are often where the model adds the most value.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AV4q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AV4q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 424w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 848w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 1272w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AV4q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png" width="971" height="256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/724af54a-167d-445b-a319-d6845285b0e8_971x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:256,&quot;width&quot;:971,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37316,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.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_!AV4q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 424w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 848w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 1272w, https://substackcdn.com/image/fetch/$s_!AV4q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F724af54a-167d-445b-a319-d6845285b0e8_971x256.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import asyncio
import json
from dataclasses import dataclass

@dataclass
class PurchaseVerification:
    order_id: str
    purchased_by_user: bool
    amount: float

@dataclass
class RefundPolicy:
    within_window: bool
    damaged_item_reported: bool
    fraud_flag: bool
    requires_manual_review: bool

@dataclass
class WorkflowResult:
    path: str
    output: str

class RefundOrchestrator(BaseLLMAgent):
    """Custom workflow: parallel checks &#8594; deterministic routing &#8594; agentic response drafting."""

    async def _verify_purchase(self, order_id: str) -&gt; PurchaseVerification:
        # Replace with real payment service call
        return PurchaseVerification(order_id=order_id, purchased_by_user=True, amount=89.99)

    async def _evaluate_policy(self, order_id: str) -&gt; RefundPolicy:
        # Replace with real policy service call
        return RefundPolicy(
            within_window=False,
            damaged_item_reported=True,
            fraud_flag=False,
            requires_manual_review=True,
        )

    def _draft_manual_review_packet(self, context: dict) -&gt; str:
        return self._text(
            "Prepare a manual review packet for operations. "
            "Include the customer claim, policy status, decision points, and missing evidence.",
            json.dumps(context),
        )

    def _draft_refund_confirmation(self, context: dict) -&gt; str:
        return self._text(
            "Draft an internal refund processing note. Include only confirmed facts from context.",
            json.dumps(context),
        )

    def _draft_store_credit_offer(self, context: dict) -&gt; str:
        return self._text(
            "Draft a customer response offering store credit. "
            "Explain the policy reason clearly without being dismissive.",
            json.dumps(context),
        )

    async def run(self, order_id: str, customer_message: str) -&gt; WorkflowResult:
        # Run eligibility checks in parallel &#8212; they are independent
        purchase, policy = await asyncio.gather(
            self._verify_purchase(order_id),
            self._evaluate_policy(order_id),
        )

        context = {
            "customer_message": customer_message,
            "purchase": {"purchased_by_user": purchase.purchased_by_user, "amount": purchase.amount},
            "policy": {
                "within_window": policy.within_window,
                "damaged_item_reported": policy.damaged_item_reported,
                "fraud_flag": policy.fraud_flag,
            },
        }

        # Deterministic routing &#8212; these rules must not be delegated to the model
        if not purchase.purchased_by_user:
            return WorkflowResult(path="denied", output="Refund denied: requester is not the purchaser.")

        if policy.fraud_flag:
            return WorkflowResult(path="fraud_hold", output="Refund held: fraud flag active. Routing to fraud team.")

        if policy.requires_manual_review:
            return WorkflowResult(path="manual_review", output=self._draft_manual_review_packet(context))

        if policy.within_window:
            return WorkflowResult(path="approved", output=self._draft_refund_confirmation(context))

        return WorkflowResult(path="store_credit", output=self._draft_store_credit_offer(context))</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n0Rh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n0Rh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 424w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 848w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 1272w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n0Rh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png" width="1456" height="710" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:710,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:170277,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.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_!n0Rh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 424w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 848w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 1272w, https://substackcdn.com/image/fetch/$s_!n0Rh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5b24898-3c07-477b-94d7-e287ef9cce23_1838x896.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern 15: Event-Driven Agent</h2><p>The fraud team realizes their biggest challenge is not <strong>routing</strong>, but <strong>timing</strong>. By the time a support ticket highlights suspicious activity, the opportunity to <strong>block or intervene on the transaction</strong> has often already passed. They do not need agents that wait for instructions &#8212; they need agents that <strong>react the moment something important happens</strong>.</p><p>Most patterns discussed so far are <strong>request-driven</strong>: they begin when a user or system explicitly asks for something. The <strong>event-driven pattern</strong> works differently. It is <strong>asynchronous and reactive</strong>, subscribing to <strong>event streams</strong> such as a <strong>Kafka topic, webhook, or database change feed</strong>. When a predefined condition is triggered, the agent <strong>wakes up and acts autonomously</strong>, without waiting for a human request.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XABm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XABm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 424w, https://substackcdn.com/image/fetch/$s_!XABm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 848w, https://substackcdn.com/image/fetch/$s_!XABm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 1272w, https://substackcdn.com/image/fetch/$s_!XABm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XABm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png" width="979" height="63" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:63,&quot;width&quot;:979,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15230,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.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_!XABm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 424w, https://substackcdn.com/image/fetch/$s_!XABm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 848w, https://substackcdn.com/image/fetch/$s_!XABm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 1272w, https://substackcdn.com/image/fetch/$s_!XABm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4fc9c5-68c9-4c0f-8d4a-1650280986ed_979x63.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">import asyncio
import json
from dataclasses import dataclass
from datetime import datetime

@dataclass
class FraudEvent:
    event_id: str
    user_id: str
    amount: float
    merchant: str
    timestamp: str
    risk_signal: str  # e.g., "velocity_spike", "new_device", "geo_anomaly"

@dataclass
class FraudDecision:
    event_id: str
    action: str  # "block" | "flag" | "allow"
    reasoning: str
    triggered_at: str

class FraudDetectionAgent(BaseLLMAgent):
    """
    Reacts to real-time fraud events. In production, subscribe this to a Kafka consumer
    or webhook endpoint rather than calling run() directly.
    """

    DECISION_SCHEMA = {
        "type": "object",
        "properties": {
            "action": {"type": "string", "enum": ["block", "flag", "allow"]},
            "reasoning": {"type": "string"},
        },
        "required": ["action", "reasoning"],
        "additionalProperties": False,
    }

    async def _enrich_context(self, event: FraudEvent) -&gt; dict:
        """Fetch user history and merchant reputation &#8212; replace with real API calls."""
        return {
            "user_prior_disputes": 0,
            "merchant_risk_tier": "medium",
            "transaction_count_last_hour": 7,
        }

    def _decide(self, event: FraudEvent, context: dict) -&gt; dict:
        return self._structured(
            "You are a fraud risk analyst. Evaluate the transaction event and enriched context. "
            "Only block when evidence is strong. Flag when uncertain. Allow when risk is low.",
            f"Event:\\\\n{json.dumps(event.__dict__)}\\\\n\\\\nContext:\\\\n{json.dumps(context)}",
            self.DECISION_SCHEMA,
        )

    async def handle_event(self, event: FraudEvent) -&gt; FraudDecision:
        context = await self._enrich_context(event)
        decision = self._decide(event, context)
        return FraudDecision(
            event_id=event.event_id,
            action=decision["action"],
            reasoning=decision["reasoning"],
            triggered_at=datetime.utcnow().isoformat(),
        )

    async def run_consumer_loop(self, event_queue: asyncio.Queue) -&gt; None:
        """Consume events from an async queue &#8212; wire to Kafka/webhook in production."""
        while True:
            event = await event_queue.get()
            decision = await self.handle_event(event)
            # Publish decision back to event bus, audit log, or action service
            print(f"[{decision.triggered_at}] {decision.event_id}: {decision.action} &#8212; {decision.reasoning}")
            event_queue.task_done()</code></pre></div><h4>When to Use and When it Breaks:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_ghM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_ghM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 424w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 848w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 1272w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_ghM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png" width="1456" height="675" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:675,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:187374,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.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_!_ghM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 424w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 848w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 1272w, https://substackcdn.com/image/fetch/$s_!_ghM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb965e76e-c487-477a-8242-fd6f9f6e4108_1838x852.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Pattern Selection Summary</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m6ZL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m6ZL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 424w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 848w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 1272w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m6ZL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png" width="816" height="994" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf81875f-a658-438a-aecf-a73a0b80677b_816x994.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:994,&quot;width&quot;:816,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:250974,&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://aayushostwal2.substack.com/i/198715128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fecb080c3-0b5b-4bda-aea0-ae6adc5f4f63_816x994.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_!m6ZL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 424w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 848w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 1272w, https://substackcdn.com/image/fetch/$s_!m6ZL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf81875f-a658-438a-aecf-a73a0b80677b_816x994.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2>Ten Rules for Production Agentic Systems</h2><ol><li><p><strong>Start with the smallest pattern that works.</strong> A single agent with good tool contracts beats a multi-agent architecture with weak ones.</p></li><li><p><strong>Give every tool a narrow schema and an honest description.</strong> Tool descriptions are not documentation &#8212; they are the model&#8217;s only source of truth about what the tool does. Write them as you would write a contract.</p></li><li><p><strong>Cap iterations, tool calls, and total spend per request.</strong> An agent without budget limits is a liability waiting to appear in a bill review.</p></li><li><p><strong>Log the action trace.</strong> Model request ID, selected tool, arguments, output summary, and final decision. Without this, incident investigation is guesswork.</p></li><li><p><strong>Keep irreversible actions behind deterministic checks or human approval.</strong> A model should never be the only gate between a user input and a database write, a money movement, or a production change.</p></li><li><p><strong>Evaluate agents with real failure cases, not just happy-path prompts.</strong> An agent that handles the happy path correctly is a prototype. An agent that handles the edge cases correctly is a product.</p></li><li><p><strong>Separate prompts by responsibility before the system prompt becomes unreadable.</strong> When you catch yourself adding &#8220;but do not do X when Y&#8221; to a system prompt, that is a sign the agent is doing two jobs.</p></li><li><p><strong>Treat multi-agent systems as distributed systems.</strong> Partial failure, timeouts, retries, ownership, and observability are not optional. They are the cost of autonomy.</p></li><li><p><strong>Model review is not a substitute for deterministic validation.</strong> Use critics, judges, and reviewers to improve quality. Use tests, policy engines, permission checks, and database constraints to enforce correctness.</p></li><li><p><strong>Prefer the simpler pattern.</strong> Not because simpler is always better &#8212; but because the complexity budget you save on the orchestration layer can be spent on the thing that actually matters: better tools, better prompts, and better evaluation.</p></li></ol><div><hr></div><h2>The Right Shape</h2><p>Agent design patterns are not maturity levels. A swarm is not more sophisticated than a single-agent system if the task only needs one reliable tool-using agent. A hierarchical decomposition is not better than a sequential pipeline if the business process is already stable. Plan-and-Execute is not an upgrade from ReAct if the plan will be stale before the third step.</p><p>The right pattern is the one that matches the <strong>shape of uncertainty</strong> in the work:</p><ul><li><p>Uncertainty in <strong>tool choice</strong> &#8594; Single-Agent or ReAct</p></li><li><p>Uncertainty in <strong>routing</strong> &#8594; Coordinator</p></li><li><p>Uncertainty in <strong>quality</strong> &#8594; Review &amp; Critique or Iterative Refinement</p></li><li><p>Uncertainty in <strong>execution path</strong> &#8594; Plan-and-Execute or ReAct</p></li><li><p>Uncertainty in <strong>self-correction</strong> &#8594; Reflexion or Loop</p></li><li><p>Uncertainty in <strong>business risk</strong> &#8594; Human-in-the-Loop or Custom Logic</p></li><li><p>Uncertainty in <strong>problem structure</strong> &#8594; Hierarchical Decomposition or Swarm</p></li><li><p>Uncertainty in <strong>timing</strong> (cannot wait for a user request) &#8594; Event-Driven Agent</p></li><li><p>Uncertainty in <strong>output quality at scale</strong> &#8594; LLM-as-Judge</p></li></ul><p>The most reliable production systems are usually not the most autonomous ones. They are the ones that put autonomy exactly where it creates value and constrain it everywhere else.</p><div><hr></div><h2>References</h2><ul><li><p>Google Cloud Architecture Center, &#8220;Choose a design pattern for your agentic AI system&#8221;: <a href="https://cloud.google.com/architecture/choose-design-pattern-agentic-ai-system">https://cloud.google.com/architecture/choose-design-pattern-agentic-ai-system</a></p></li><li><p>Yao et al., &#8220;ReAct: Synergizing Reasoning and Acting in Language Models&#8221; (ICLR 2023)</p></li><li><p>Shinn et al., &#8220;Reflexion: Language Agents with Verbal Reinforcement Learning&#8221; (NeurIPS 2023)</p></li><li><p>Chase, &#8220;Plan-and-Solve Prompting&#8221; and LangGraph plan-and-execute documentation</p></li><li><p>Anthropic, &#8220;Building Effective AI Agents&#8221;: <a href="https://www.anthropic.com/research/building-effective-agents">https://www.anthropic.com/research/building-effective-agents</a></p></li><li><p>OpenAI API documentation, Responses API: <a href="https://platform.openai.com/docs/api-reference/responses">https://platform.openai.com/docs/api-reference/responses</a></p></li><li><p>OpenAI API documentation, Function calling guide: <a href="https://platform.openai.com/docs/guides/function-calling">https://platform.openai.com/docs/guides/function-calling</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[How I Actually Use Claude Code as a Senior Engineer]]></title><description><![CDATA[Persistent memory, MCPs, project-scoped context, skills, and the workflows that genuinely save me time.]]></description><link>https://aayushostwal2.substack.com/p/how-i-actually-use-claude-code-as</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/how-i-actually-use-claude-code-as</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Wed, 20 May 2026 13:13:33 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/3d9c3f88-8ecd-4996-81c2-c1e9fbaf45c1_1422x938.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>1. Root <code>CLAUDE.md</code></h2><p>Every time you type <code>claude</code> in your terminal, it starts with zero context. At this point, this is probably the millionth article saying the same thing.</p><p>But if you&#8217;ve already read that a hundred times, here&#8217;s the part most people skip: adding the <em>right</em> context.</p><p>One thing I strongly prefer is keeping it crisp. Claude has been trained on an immense amount of data. If you&#8217;re stuffing your context with things it already knows, you&#8217;re just wasting tokens.</p><p>Here&#8217;s what I&#8217;ve added to my root <code>claude.md</code> file:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown"># Global Context &amp; Instructions

## My Role
I am a Senior AI Engineer and Full Stack Software Engineer specializing in Large Language Models (LLMs), Retrieval-Augmented Generation (RAG) frameworks, and AI agent orchestration. My daily work bridges high-performance backend engineering and advanced AI research. 
---

## Preferences
When assisting me, please adhere to the following interaction and coding preferences:

**CONVERSATIONAL CHATBOT**
- When I am interacting with claude, make sure the response is very crisp. Always support markdown, table. Limit the output tokens are limited as possible, unless ask to elaborate more.

**PLANNING**
- Always use internet to verify things if you are working on tools like AWS, Bazel, Cloud Architecture.

**CODING PREFERENCES**

- Default to `Python 3.12`. Always use standard coding practices, design pattern, class based approach
- Add crisp and relevant comments in the code, do not add noise.

**CONTENT GENERATION** 
- When helping with Medium articles or YouTube content, provide SEO-optimized descriptions, engaging thumbnails/hooks, and highly structured outlines. Maintain a highly technical but accessible tone for Medium drafts.

**DEBUGGING**
- While debugging cloud related issue, always read latest aws documentation and use aws mcp to fetch details from cloud.
**SKILL USAGE**
- Wherever possible use skills
- Never use skills from `Atlasian`
</code></pre></div><p>First, yes, I&#8217;ve added a few repetitive things. </p><p>But later I optimized this file to store <em>my</em> personal coding preferences &#8212; the tools, MCPs, and workflows I want Claude to use.</p><p>The goal here is to optimize for how <em>I</em> code, not to create a perfectly organized, company-wide standard.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>2. Researching and Learning Like a Pro&#8230;</h2><p>Whenever I want to research or learn something new, the old approach was pretty straightforward &#8212; read 2&#8211;3 articles and then get hands-on.</p><p>Now, you can effectively read 50+ articles and condense them into a single, well-structured document.</p><p><strong>Here&#8217;s my workflow:</strong></p><ul><li><p>First, I go to Gemini and use Deep Research mode to generate a research canvas. Then I export it to a Google Doc.</p></li></ul><p>For example, I recently wanted to learn about LLM evaluation techniques. Gemini generated an 18-page document for me:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Aqzx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Aqzx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 424w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 848w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 1272w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Aqzx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png" width="1456" height="781" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:781,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:537527,&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://aayushostwal2.substack.com/i/198527039?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.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_!Aqzx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 424w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 848w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 1272w, https://substackcdn.com/image/fetch/$s_!Aqzx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb3717b7-9a92-4dac-a7cd-973fcd508d0a_2998x1608.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>It did make things a little complex and added some irrelevant details here and there. But overall, I&#8217;d say I got a pretty solid understanding of the topic I wanted to learn.</p><p>Over time, I started trying one more thing: giving the exact same prompt to different models.</p><ul><li><p><a href="https://www.deepseek.com?utm_source=chatgpt.com">DeepSeek</a></p></li><li><p><a href="https://claude.ai?utm_source=chatgpt.com">Claude</a></p></li><li><p><a href="https://gemini.google.com?utm_source=chatgpt.com">Gemini</a></p></li><li><p><a href="https://chatgpt.com?utm_source=chatgpt.com">ChatGPT</a></p></li><li><p><a href="https://grok.com?utm_source=chatgpt.com">Grok</a></p></li></ul><p>You&#8217;ll notice that each one gives noticeably different outputs. Some explain things better, some go deeper, and some are just easier to follow depending on the topic.</p><p>These are the free (or mostly free) alternatives I regularly use when I&#8217;m trying to learn something new.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>3. MCP Servers:</h2><p>I don&#8217;t know why people keep saying MCPs are dead. To me, they&#8217;re definitely not.</p><p>I&#8217;m a developer. On any given day, I&#8217;m writing code, managing AWS infrastructure, maintaining JIRA tickets, replying on Slack, and juggling everything else developers usually end up doing.</p><p>So if I want to connect all of these things into a single ecosystem, why <em>wouldn&#8217;t</em> I use MCPs?</p><p>The context switching becomes dramatically lower. Instead of jumping across ten tabs and tools, I can run a single command and work across multiple systems from one place.</p><p>Recently, I was debugging an issue in AWS, and I plugged in an AWS MCP. It genuinely made the process smoother.</p><p>It read the logs, fetched the required ARNs, and when I passed an ARN, it already understood what resource I was referring to and how it was configured. That level of context awareness removes a lot of friction when debugging.</p><p>Recently, while setting up a new AWS CDK stack, I needed multiple ARNs and endpoints from AWS. Instead of hopping across different AWS console pages, I pulled everything I needed with a single line:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qGJJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qGJJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 424w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 848w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 1272w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qGJJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png" width="982" height="209" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:209,&quot;width&quot;:982,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38193,&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://aayushostwal2.substack.com/i/198527039?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.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_!qGJJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 424w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 848w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 1272w, https://substackcdn.com/image/fetch/$s_!qGJJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b92d174-2b25-436c-85a1-0df3142b41c4_982x209.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><blockquote><p>Install your self: <a href="https://aws.amazon.com/blogs/aws/the-aws-mcp-server-is-now-generally-available/">AWS MCP</a>, highly recommended</p></blockquote><div><hr></div><h2>4. Skills:</h2><p>This is actually a pretty powerful concept.</p><p>Heavy models like Opus often cost more because of the extra thinking tokens they use. But what if the response you want can be achieved through a predictable chain of thought &#8212; one you can define upfront? In that case, the response becomes faster, cheaper, and far more consistent.</p><p>That&#8217;s where skills become useful.</p><p>You don&#8217;t always have to write skills from scratch either. There are plenty of community-built ones available on GitHub. Some examples I&#8217;ve tried:</p><ul><li><p><a href="https://github.com/wwwazzz/senior-pm-prompt">senior-pm-prompt</a></p></li><li><p><a href="https://github.com/emilkowalski/skill/tree/main">emilkowalski/skill</a></p></li><li><p><a href="https://github.com/aayushostwal/nexus/">aayushostwal/nexus</a></p></li><li><p><a href="https://github.com/obra/superpowers/">superpowers</a></p></li></ul><p>You can define in your root <code>claude.md</code> file which skills should always be loaded and what behaviors Claude should follow.</p><blockquote><p>One important thing to keep in mind: skills are not free from a context perspective. By default, Claude reserves only a small portion of the context window for them. So you can&#8217;t just keep adding skills endlessly &#8212; there&#8217;s a tradeoff between capability and available context.</p></blockquote><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>5. Persistent Memory of Agents and Git Worktrees:</h2><p>Since I work in a startup environment, it&#8217;s pretty common for me to juggle multiple tasks in the same repo.</p><p>That creates an annoying problem: either you keep your terminal session alive when switching tasks, or you end up rebuilding the entire context when you come back to an older one.</p><p>It&#8217;s frustrating &#8212; and honestly, expensive from a token perspective.</p><p>I ended up using two approaches to manage persistent memory for my agent.</p><p>The first one is a <code>/save-context</code> command that writes the current context to a file on disk. That way, when I start a new session, I can simply reload it instead of gathering everything again.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown"># Dump the current session context to a file so it can be resumed later.

Please create a context snapshot file that will let me resume this session from scratch.

## Steps

1. Determine a filename: `context-snapshot-&lt;YYYY-MM-DD-HHMM&gt;.md` using the current date and time.

2. Write the file to the project root (or current working directory if no project root is found). The file should contain the following sections:

---

### Section 1 &#8212; Session Goal
A 2&#8211;3 sentence summary of the overall goal or task we have been working on in this session.

### Section 2 &#8212; Current Status
What has been completed so far and what the current state is. Be specific: mention files created/modified, decisions made, and what was the last action taken.

### Section 3 &#8212; Pending Tasks
A prioritised numbered list of things still left to do to complete the goal.

### Section 4 &#8212; Key Decisions &amp; Context
Any important decisions, constraints, or background context that the next Claude session must know to continue correctly. Include things like: chosen libraries, architectural decisions, naming conventions, credentials locations, environment details, or anything non-obvious.

### Section 5 &#8212; Exact Resume Prompt
Write a ready-to-paste prompt (inside a markdown code block) that the user can drop at the start of a fresh Claude Code session to resume seamlessly. It should:
- Reference the snapshot file by name
- Ask Claude to read the file first
- State the immediate next step clearly

---

3. After writing the file, print the absolute path to the file and a one-line confirmation message.</code></pre></div><p>Recently, I started using <a href="https://github.com/rohitg00/agentmemory">agentmemory</a> &#8212; a dedicated repo for maintaining context across sessions.</p><p>Instead of relying on temporary terminal history or rebuilding context every time, I keep the important details in one place and let the agent pick things up from there.6.</p><div><hr></div><h2>6. Working on multiple Github Repo:</h2><p>If you work across multiple GitHub repos, you already know that every repo has its own nuances.</p><p>Different coding patterns, different deployment flows, different tooling, and sometimes even different engineering philosophies.</p><p>That&#8217;s exactly why you should stop treating every repository the same.</p><p>You can define repo-specific rules, skills, and MCP servers for each project. This isn&#8217;t a groundbreaking idea &#8212; chances are, you&#8217;ve already read about it before.</p><p>But the real question is: have you actually implemented it?</p><p>In practice, most people don&#8217;t.</p><p>If you&#8217;re working in a monorepo, this becomes even more useful. You can add a project-scoped <code>claude.md</code> file for different services or modules so Claude gets the right context much faster.</p><p>Instead of re-explaining architecture, conventions, or dependencies every single time, you can simply reference the relevant project context with something like this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown"># payments-service/claude.md

- This service handles payment orchestration and Stripe webhooks. 
- Prefer using Nexus for codebase navigation and AWS MCP for infra/log debugging. 
- Follow existing async patterns, avoid introducing sync calls, and reuse shared payment utilities before adding new abstractions.

# frontend/claude.md

- This is a Next.js frontend app. Always follow the existing component structure and design system. 
- Use shared UI components first, prefer server components where possible, and avoid adding new dependencies unless necessary.</code></pre></div><div><hr></div><p>At the end of the day, I don&#8217;t think agentic AI is about replacing engineers.</p><p>It&#8217;s about reducing friction.</p><p>Less context switching. Less repeating yourself. Less manually digging through dashboards, logs, docs, and codebases.</p><p>Most people are still using these tools like smarter chatbots. But the real unlock happens when you start building systems around them &#8212; persistent memory, MCPs, repo-specific context, skills, and workflows that match how <em>you</em> actually work.</p><p>None of this is perfect yet. Half of the time, I&#8217;m still experimenting.</p><p>But one thing is clear: the developers who learn how to orchestrate these tools will move much faster than the ones treating AI like autocomplete.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[CLAUDE.md — the configuration file that makes Claude Code actually yours]]></title><description><![CDATA[CLAUDE.md &#8212; the one file that makes Claude Code actually yours]]></description><link>https://aayushostwal2.substack.com/p/claudemd-the-configuration-file-that</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/claudemd-the-configuration-file-that</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Mon, 18 May 2026 13:45:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!G_Ga!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31523f1d-7835-4378-a58f-229ec9fb014b_1280x1280.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Every session, Claude starts fresh. No memory. No context. <code>CLAUDE.md</code> is how you fix that &#8212; permanently.</p><p>You open Claude Code. You start typing. And almost immediately you find yourself explaining &#8212; again &#8212; that your project uses App Router, not Pages Router. That you run <code>pnpm</code>, not <code>npm</code> That you want typed components only, please.</p><p>Claude doesn&#8217;t know. It can&#8217;t. Every session is a blank slate. You&#8217;re repeating yourself to one of the most capable tools you&#8217;ve ever used &#8212; and that&#8217;s just wasteful.</p><p><code>CLAUDE.md</code> is the fix. One markdown file. Loaded automatically. Every single time.</p><blockquote><p><em>Think of it like this: </em><code>CLAUDE.md</code><em> is onboarding documentation for your AI teammate &#8212; the briefing you&#8217;d give a brilliant new engineer on their first day, so they stop asking obvious questions and start shipping.</em></p></blockquote><h2><strong>What is CLAUDE.md, exactly?</strong></h2><p>CLAUDE.md is a plain markdown file that Claude Code reads at the start of every session. It becomes part of Claude&#8217;s context automatically &#8212; you don&#8217;t reference it, attach it, or paste it. It&#8217;s just there.</p><p>You can use it to document anything Claude can&#8217;t infer from your code alone: build commands, test workflows, project structure, naming conventions, architectural decisions, gotchas, and domain-specific terminology.</p><p>There&#8217;s no required format. Keep it short. Keep it human-readable. Every line should answer the question: <em>what would Claude get wrong without this?</em></p><h2><strong>The file hierarchy</strong></h2><p><code>CLAUDE.md</code> works in layers. More specific files override more general ones.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gwvL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gwvL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 424w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 848w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 1272w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gwvL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png" width="530" height="214" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:214,&quot;width&quot;:530,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!gwvL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 424w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 848w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 1272w, https://substackcdn.com/image/fetch/$s_!gwvL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4508d821-2d4b-45a7-bf8b-04cf7948ae82_530x214.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The project <code>CLAUDE.md</code> is where most of your leverage lives. Start there.</p><h2><strong>Getting started in 30 seconds</strong></h2><p>Don&#8217;t write it from scratch. Use the <code>/init</code> command. Claude Code will scan your project &#8212; package files, config, directory structure &#8212; and generate a starter CLAUDE.md tailored to what it finds.</p><pre><code># in your project directory
/init</code></pre><p>Then prune it ruthlessly. The generated file often includes things Claude already knows. Delete anything that isn&#8217;t genuinely project-specific. Shorter is better &#8212; every line competes for attention with your actual task.</p><h2><strong>What actually belongs in it</strong></h2><p>The single highest-impact instruction you can add: tell Claude how to verify its own work.</p><pre><code># CLAUDE.md:
# Verification
After making code changes, always run:
1. `pnpm lint`   &#8212; catch style issues
2. `pnpm test`   &#8212; verify nothing broke
3. `pnpm build`  &#8212; check for type errors</code></pre><p>When Claude knows how to check its own work, it catches mistakes before you ever see them. This one pattern measurably improves output quality across every task.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><h2><strong>What to leave out</strong></h2><p>This is just as important. Overloaded CLAUDE.md files actively hurt performance &#8212; when there are too many instructions, Claude doesn&#8217;t just ignore the new ones. It starts ignoring all of them uniformly.</p><blockquote><p>Frontier models can reliably follow roughly 150&#8211;200 instructions. Claude Code&#8217;s system prompt already uses ~50. That leaves you around 100&#8211;150 before things quietly start degrading.</p></blockquote><ul><li><p>&#10060; Code style rules &#8212; use a linter. LLMs are slow and expensive compared to ESLint.</p></li><li><p>&#10060; Things Claude already knows &#8212; TypeScript syntax, common frameworks, async/await.</p></li><li><p>&#10060; Credentials &#8212; use environment variables; reference them by name only.</p></li><li><p>&#10060; Rapidly-changing info &#8212; use session prompts for volatile context.</p></li><li><p>&#10060; Full documentation &#8212; link to docs, don&#8217;t reproduce them.</p></li></ul><h2><strong>Scaling for bigger projects</strong></h2><p>When a single file gets unwieldy, split it. Create a <code>.claude/rules/</code> directory and drop focused rule files inside:</p><pre><code>your-project/
&#9500;&#9472;&#9472; CLAUDE.md          # core project context
&#9492;&#9472;&#9472; .claude/
    &#9492;&#9472;&#9472; rules/
        &#9500;&#9472;&#9472; testing.md    # testing conventions
        &#9500;&#9472;&#9472; api-rules.md  # backend-specific rules
        &#9492;&#9472;&#9472; security.md   # security requirements</code></pre><p>Files in <code>.claude/rules/</code> with YAML frontmatter specifying <code>paths:</code> are lazy-loaded &#8212; they only enter context when Claude touches matching files. This is powerful: you can have detailed rules for your API layer that never clutter a UI-only task.</p><h2><strong>Five rules for a great CLAUDE.md</strong></h2><ol><li><p>Every line must earn its place. Ask: would Claude make a mistake without this? If no &#8212; delete it.</p></li><li><p>Use /init to generate, then prune. Deleting is always faster than writing from scratch.</p></li><li><p>Always include your verification commands. This single instruction has the highest return of anything you can add.</p></li><li><p>Keep it human-readable. If a new team member couldn&#8217;t scan it in two minutes, it&#8217;s too long.</p></li><li><p>Treat it as a living document. Add lines when Claude makes a mistake that a clear instruction would have prevented.</p></li></ol><h2><strong>The bottom line</strong></h2><p><code>CLAUDE.md</code> is one of the highest-leverage things you can configure in your entire development environment. A good one transforms Claude Code from a capable but context-blind assistant into something that actually knows your project &#8212; your commands, your architecture, your quirks.</p><p>Run <code>/init</code>. Delete the noise. Add your verification steps. Commit it. Then watch how much less you repeat yourself.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Your AGENTS.md File Is Making Your AI Coder only 3% better?]]></title><description><![CDATA[A rigorous new study from ETH Zurich and DeepMind shows that your carefully curated AGENTS.md file might be hurting your coding agent&#8217;s performance&#8212;and burning cash. Here&#8217;s what actually works.]]></description><link>https://aayushostwal2.substack.com/p/your-agentsmd-file-is-making-your</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/your-agentsmd-file-is-making-your</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Fri, 15 May 2026 06:32:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!G_Ga!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31523f1d-7835-4378-a58f-229ec9fb014b_1280x1280.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you&#8217;ve been around the AI-powered coding scene lately, you&#8217;ve undoubtedly heard the gospel of the <code>AGENTS.md</code> file. It&#8217;s been pitched as the ultimate cheat code: a simple, open-format file that gives your coding agent a map of your project, turning it from a lost tourist into a seasoned local guide. The narrative is compelling&#8212;give the agent more context, and it will do a better job.</p><p>But what if the map is actually a distraction? A recent, rigorous study from ETH Zurich and DeepMind has turned this assumption on its head, and the results are a wake-up call for anyone who has been meticulously curating these files.</p><h3><strong>The Great </strong><code>AGENTS.md</code><strong> Experiment</strong></h3><p>The paper, titled &#8220;Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents?&#8221; by Thibaud Gloaguen, Niels M&#252;ndler, Mark M&#252;ller, Veselin Raychev, and Martin Vechev, set out to answer a simple question that no one had yet rigorously tested: Do these context files <em>actually</em> help AI coding agents complete real-world tasks?</p><p>To find out, the researchers built a new benchmark called AGENTbench, consisting of 138 real-world software engineering tasks from 12 Python repositories that already use developer-written context files. They complemented this with the established SWE-bench Lite benchmark, which has 300 tasks from popular repositories, where they used LLMs to generate the context files.</p><p>They then set four popular coding agents loose on these tasks in three different modes: with no context file at all, with an LLM-generated context file, and with a human-written one. The results were nothing short of counterintuitive.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><p></p><h3><strong>The Surprising Results: A Marginal Affair</strong></h3><p>The researchers&#8217; findings directly contradict the prevailing &#8220;more context is better&#8221; wisdom. Here&#8217;s what they discovered:</p><ul><li><p><strong>LLM-Generated Files Hurt Performance:</strong> On average, automatically generated <code>AGENTS.md</code> files decreased task success rates by a staggering <strong>3%</strong>. Providing an AI with auto-generated instructions was worse than providing none at all.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!H37l!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!H37l!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 424w, https://substackcdn.com/image/fetch/$s_!H37l!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 848w, https://substackcdn.com/image/fetch/$s_!H37l!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 1272w, https://substackcdn.com/image/fetch/$s_!H37l!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!H37l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png" width="419" height="255" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:255,&quot;width&quot;:419,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Refer to caption&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Refer to caption" title="Refer to caption" srcset="https://substackcdn.com/image/fetch/$s_!H37l!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 424w, https://substackcdn.com/image/fetch/$s_!H37l!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 848w, https://substackcdn.com/image/fetch/$s_!H37l!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 1272w, https://substackcdn.com/image/fetch/$s_!H37l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0b11041-81a9-4158-b6ee-5b08c55cbae6_419x255.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><ul><li><p><strong>Human-Written Files Are... Just Okay:</strong> Developer-written context files provided only a marginal improvement, increasing success rates by an average of <strong>4%</strong>. This is a very small gain for what is often a significant documentation effort.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MfGL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MfGL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 424w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 848w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 1272w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MfGL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png" width="419" height="255" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:255,&quot;width&quot;:419,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Refer to caption&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Refer to caption" title="Refer to caption" srcset="https://substackcdn.com/image/fetch/$s_!MfGL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 424w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 848w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 1272w, https://substackcdn.com/image/fetch/$s_!MfGL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5590d870-f25c-4b74-b71a-865780c3b5ae_419x255.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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></li><li><p><strong>A Hefty Price Tag for Small Gains:</strong> Even when they &#8220;helped,&#8221; context files came with a significant cost. They consistently increased the inference cost of completing a task by <strong>over 20%</strong>. The agents required more steps, more tokens, and more thinking time to achieve barely better (or even worse) results.</p></li></ul><h3><strong>Why Does More Context Hurt Performance?</strong></h3><p>This is the critical question. If the agents are following the instructions, why aren&#8217;t they doing better? The study&#8217;s analysis of agent behavior traces provides some fascinating answers.</p><h4><strong>1. Agents Became Overzealous Rule-Followers</strong></h4><p>The good news is that the coding agents are excellent instruction-followers. The bad news is that this becomes a problem. When a context file instructs an agent to &#8220;thoroughly test all changes&#8221; or &#8220;use <code>uv</code> for package management,&#8221; the agent complies, even when it&#8217;s unnecessary for the simple bug fix at hand. This leads to:</p><ul><li><p><strong>Increased, Often Redundant, Testing:</strong> Agents ran more tests than needed, wasting time and compute.</p></li><li><p><strong>Unnecessary Exploration:</strong> They navigated through more files, performed more searches, and used more repository-specific tooling than required for the task.</p></li></ul><p>The result is a well-intentioned agent that spends a lot of its energy on meta-tasks, losing sight of the core goal: resolving the issue efficiently.'</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h4><strong>2. Context Files Are a Poor Man&#8217;s Codebase Overview</strong></h4><p>One of the primary promises of a context file is to provide a useful architectural overview, helping the agent quickly find the right files. The study found this promise to be largely unfulfilled. Agents with access to context files did not discover relevant files any faster than those without them. It turns out that the agents&#8217; built-in ability to explore and search a codebase is already quite good, and a static, often high-level map doesn&#8217;t add much value.</p><h4><strong>3. The &#8220;No Documentation&#8221; Trap</strong></h4><p>Interestingly, the researchers tested a scenario where all other documentation was removed, leaving the context file as the sole source of information. In this extreme case, LLM-generated context files <em>did</em> consistently improve performance, even outperforming human-written documentation. This explains why some developers anecdotally report success&#8212;their repositories likely had little to no documentation to begin with, so <em>any</em> documentation was a massive help. This is a crucial insight: the effectiveness of a context file is inversely proportional to the quality of your project&#8217;s existing documentation.</p><h3><strong>A Better Way Forward: The Principle of Minimal Instruction</strong></h3><p>So, should you throw your <code>AGENTS.md</code> file in the trash? Not necessarily, but the way you create them needs a fundamental rethink. The study&#8217;s core recommendation is a principle of <strong>minimalism</strong>.</p><blockquote><p>&#8220;We therefore suggest omitting LLM-generated context files for the time being, contrary to agent developers&#8217; recommendations, and including only minimal requirements (e.g., specific tooling to use with this repository).&#8221;</p></blockquote><p><strong>Here are some actionable takeaways based on the research:</strong></p><ul><li><p><strong>Stop Auto-Generating:</strong> For now, the evidence strongly suggests you should ditch the <code>/init</code> command and other automated tools for creating context files. The risk of them causing harm far outweighs the negligible benefit. Always hand-write your AGENTS.md based on real experience with the codebase.</p></li><li><p><strong>Start with an Empty File:</strong> A zero-length <code>AGENTS.md</code> is better than a verbose one. Build it iteratively, only adding instructions when you observe the agent consistently struggling with a specific, non-obvious aspect of your project.</p></li><li><p><strong>Focus on the &#8220;What,&#8221; Not the &#8220;How&#8221;:</strong> Your instructions should clarify <em>what</em> the agent needs to accomplish, not a step-by-step guide on <em>how</em> to do it. For example, &#8220;Use <code>uv</code> for package management&#8221; is a good, concise instruction. A paragraph on how to structure a loop is redundant and potentially harmful.</p></li><li><p><strong>Invest in Good Conventional Documentation:</strong> The study shows that agents are very capable of understanding standard documentation. A well-maintained <code>README.md</code>, clear code comments, and logical directory structures are likely a far better investment of your time than a dedicated, highly-curated agent file.</p></li></ul><h3><strong>Conclusion</strong></h3><p>The &#8220;Evaluating AGENTS.md&#8221; paper is a much-needed reality check in the fast-moving world of AI coding assistants. It reminds us that the intuitive solution is not always the right one. While the idea of a dedicated instruction file for our AI partners is elegant in theory, in practice, it&#8217;s a tool that is often misused, leading to distracting, costly, and self-sabotaging behavior.</p><p>The path forward is not about providing <em>more</em> context, but <em>better</em>, more precise context. The most effective <code>AGENTS.md</code> file you can have is likely the one that is almost empty, containing only the few critical details that your coding agent cannot discover on its own. Let&#8217;s stop building ornate maps that confuse the tourist and instead just point them in the right direction. I highly recommend reading the full paper for a deeper dive into the data. You can also check out the open-source code for their AGENTbench framework.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><strong>Sources:</strong></p><p>[1] https://arxiv.org/html/2602.11988v1</p>]]></content:encoded></item><item><title><![CDATA[Scaling Claude Code: How We Sync Custom AI Skills Across 100+ Repos]]></title><description><![CDATA[Github Submodules, Scripts, and NPM Package. See Implementation Now]]></description><link>https://aayushostwal2.substack.com/p/scaling-claude-code-how-we-sync-custom</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/scaling-claude-code-how-we-sync-custom</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Sun, 10 May 2026 11:58:45 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!R7W-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As organizations rapidly adopt AI tools, <strong>AI developer productivity</strong> has become a top priority for engineering leaders. Claude, with its advanced reasoning and coding capabilities, is a massive force multiplier.</p><p>However, as your team creates highly effective, context-aware &#8220;Claude Skills&#8221; (custom prompts, Model Context Protocol (MCP) servers, and project-specific instructions), a new challenge emerges:</p><p><strong>How do you scale and share these AI capabilities across dozens or hundreds of repositories?</strong></p><p>Without a centralized strategy, teams end up with fragmented prompt libraries, duplicated effort, and inconsistent AI outputs.</p><p>In this guide, we will explore three proven strategies for distributing and maintaining global Claude Skills across your organization to achieve seamless <strong>AI workflow automation</strong> and build powerful <strong>shared AI tooling</strong>.</p><h2><strong>1. Introduction: The Need for Shared AI Tooling</strong></h2><p>A &#8220;<strong>Claude Skill</strong>&#8221; in a modern engineering context typically consists of:</p><ul><li><p><strong>Custom Instructions:</strong> <code>./skills/skill.md</code> files that dictate how the AI interacts with your specific codebase.</p></li><li><p><strong>Prompt Templates:</strong> Standardized markdown files containing architectural guidelines, testing standards, or PR review checklists.</p></li><li><p><strong>MCP Servers:</strong> Scripts and configurations that allow Claude to interact with your internal APIs, databases, or cloud infrastructure.</p></li></ul><p>When you centralize these skills, you ensure that every developer &#8212; whether they are on the frontend, backend, or DevOps team &#8212; has access to the most optimized, up-to-date AI context. This reduces hallucination, enforces coding standards automatically, and accelerates onboarding.</p><h2><strong>The Centralized AI Tooling Architecture</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5O7f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5O7f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 424w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 848w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 1272w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5O7f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png" width="1456" height="794" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:794,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!5O7f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 424w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 848w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 1272w, https://substackcdn.com/image/fetch/$s_!5O7f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3613d49c-68c6-4fd9-86d8-fe056b85be2f_2000x1091.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Method 1: Git Submodules (Most Common Approach)</strong></h2><p>For many engineering teams, the simplest way to share code is through standard Git mechanisms. Git Submodules allow you to keep a dedicated repository of Claude Skills and embed it into any project.</p><h3><strong>Repository Structure</strong></h3><p>First, create a centralized repository named <code>org-claude-skills</code>:</p><pre><code>org-claude-skills/
&#9500;&#9472;&#9472; skills/
&#9474;   &#9500;&#9472;&#9472; code-review.md
&#9474;   &#9500;&#9472;&#9472; write-tests.md
&#9500;&#9472;&#9472; mcp-servers/
&#9474;   &#9500;&#9472;&#9472; internal-wiki-search/
&#9474;   &#9492;&#9472;&#9472; jira-integration/
&#9500;&#9472;&#9472; global-instructions.md
&#9492;&#9472;&#9472; README.md</code></pre><h3><strong>Setup Steps &amp; Example Commands</strong></h3><p>To add these skills to a target application repository, a developer simply adds the skills repo as a submodule.</p><pre><code># Navigate to your application repository
cd my-node-backend
# Add the centralized skills repository as a submodule
git submodule add https://github.com/your-org/org-claude-skills.git .claude-skills
# Initialize and update
git submodule update --init --recursive</code></pre><ul><li><p><strong>Pros:</strong> No new infrastructure required; strictly tied to Git versions.</p></li><li><p><strong>Cons:</strong> Submodules can be cumbersome for developers unfamiliar with updating them.</p></li></ul><h2><strong>Method 2: Install Skills via Script (Recommended for AI Teams)</strong></h2><p>For teams that want to automate the distribution of AI developer productivity tools without the overhead of Git submodules, an installation script is the perfect middle ground. This allows you to fetch the latest prompt templates and configurations dynamically.</p><h3><strong>Automation Workflow</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!R7W-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!R7W-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 424w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 848w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 1272w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!R7W-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png" width="1400" height="764" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:764,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!R7W-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 424w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 848w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 1272w, https://substackcdn.com/image/fetch/$s_!R7W-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07450ba-0c83-42c1-ad92-404dc384cc2e_1400x764.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Scripting Workflow</p><ol><li><p>Host your Claude Skills in a central repo or an S3 bucket.</p></li><li><p>Provide developers with a simple <code>curl</code> command.</p></li><li><p>The script downloads the relevant skills into a <code>.ai/</code> or <code>.claude/</code> directory in their local project.</p></li></ol><h3><strong>Install Script Example (</strong><code>install-skills.sh</code><strong>)</strong></h3><pre><code>#!/bin/bash
# install-skills.sh - Automate shared AI tooling distribution
SKILLS_REPO_URL=https://raw.githubusercontent.com/your-org/org-claude-skills/main)
TARGET_DIR=&#8221;.claude&#8221;
echo &#8220;Installing Global Claude Skills...&#8221;
mkdir -p $TARGET_DIR/prompts
# Download global coding standards
curl -s &#8220;$SKILLS_REPO_URL/prompts/frontend-standards.md&#8221; -o &#8220;$TARGET_DIR/prompts/frontend-standards.md&#8221;
curl -s &#8220;$SKILLS_REPO_URL/prompts/testing-guidelines.md&#8221; -o &#8220;$TARGET_DIR/prompts/testing-guidelines.md&#8221;
# Download MCP Config template
curl -s &#8220;$SKILLS_REPO_URL/mcp-config.json&#8221; -o &#8220;$TARGET_DIR/mcp-config.json&#8221;
echo &#8220;Claude Skills successfully installed in $TARGET_DIR/&#8221;</code></pre><h3><strong>CI/CD Usage</strong></h3><p>You can integrate this script into your CI/CD pipeline (e.g., GitHub Actions) to ensure that automated AI code reviewers always have the absolute latest prompt templates before analyzing a PR.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Method 3: NPM / Python Package (Best for Large Organizations)</strong></h2><p>For enterprise-scale platform engineering teams, packaging Claude Skills as reusable libraries via native package managers (NPM, PyPI) provides the ultimate level of version control and seamless integration.</p><h2><strong>Package Distribution Workflow</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cs9O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cs9O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cs9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png" width="1024" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!cs9O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!cs9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7c936d-c825-4007-a712-6bbcb83f31fa_1024x559.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2><strong>Package Structure</strong></h2><p>If your engineering org uses Node.js, you can create a package named <code>@myorg/claude-skills</code>.</p><pre><code>claude-skills-package/
&#9500;&#9472;&#9472; package.json
&#9500;&#9472;&#9472; index.js           # Exports paths to prompts and MCP tool definitions
&#9500;&#9472;&#9472; prompts/
&#9474;   &#9492;&#9472;&#9472; standard-react-component.md
&#9492;&#9472;&#9472; bin/
    &#9492;&#9472;&#9472; setup-claude.js # CLI tool to scaffold local AI configs</code></pre><h3><strong>Publishing Workflow &amp; Install Example</strong></h3><p>Publish the package to your private NPM registry:</p><pre><code>npm publish --access restricted</code></pre><p>Developers can now install the skills just like any other dependency:</p><pre><code>npm install @myorg/claude-skills --save-dev</code></pre><p>You can then provide an executable binary in the package to scaffold the AI context locally:</p><pre><code># Scaffolds the .claude.json or MCP settings using the package data
npx setup-claude-skills --type frontend</code></pre><ul><li><p><strong>Pros:</strong> Excellent version control, semantic releases, and a familiar developer workflow.</p></li><li><p><strong>Cons:</strong> Language-specific (NPM for JS, PyPI for Python), which might be an issue in polyglot organizations.</p></li></ul><h2><strong>Comparison Table</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Wkhq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Wkhq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 424w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 848w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 1272w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Wkhq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png" width="1400" height="764" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:764,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Wkhq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 424w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 848w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 1272w, https://substackcdn.com/image/fetch/$s_!Wkhq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3c9e6d3-5bed-4d61-b398-d7369b1cd75d_1400x764.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2><strong>Best Practices</strong></h2><p>Regardless of the distribution method you choose, adhere to these best practices when scaling AI developer productivity:</p><ul><li><p><strong>Versioning is Critical:</strong> AI models change, and so do effective prompting strategies. Always version your skills. If a prompt breaks due to a new Claude model update, you need the ability to roll back.</p></li><li><p><strong>Documentation for AI (and Humans):</strong> Write self-describing metadata for your skills. Use XML tags (e.g., <code>&lt;skill_description&gt;</code>) inside your prompt files so the AI understands <em>when</em> to use a specific skill.</p></li><li><p><strong>Security &amp; Secrets:</strong> <strong>Never</strong> hardcode API keys or internal secrets inside shared Claude Skills. Use environment variable placeholders (e.g., <code>{{JIRA_API_KEY}}</code>) and rely on local <code>.env</code> files or secure secret managers during runtime execution.</p></li></ul><h2><strong>Conclusion</strong></h2><p>Adding global Claude Skills across multiple repositories transforms how your organization leverages generative AI.</p><ul><li><p>If you are a <strong>small team</strong>, start with <strong>Git Submodules</strong>.</p></li><li><p>If you manage a <strong>polyglot environment</strong> with diverse languages, use an <strong>Install Script</strong>.</p></li><li><p>If you are a <strong>Platform Engineering team</strong> supporting hundreds of engineers, invest in <strong>Package Managers</strong> to distribute AI context as version-controlled code.</p></li></ul><p>By standardizing your AI tooling, you ensure that every prompt is highly engineered, secure, and ready to accelerate your software development lifecycle.</p><p>Hopefully, this saves you from the headache of managing 50 different <code>.claude</code> folders.</p><p>How are you handling skill distribution across your teams?</p><p>If you&#8217;ve found a cleaner way to sync these&#8212;or if you&#8217;ve run into any symlink quirks&#8212;drop a comment below. I&#8217;d love to see how others are tackling this!</p><p>Thank you :)</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Why Your AI “Agent” is Actually Just a Skill: Agent V/s Skill]]></title><description><![CDATA[Build BOTH. Together they create AI systems that are precise, purposeful, and powerful.]]></description><link>https://aayushostwal2.substack.com/p/why-your-ai-agent-is-actually-just</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/why-your-ai-agent-is-actually-just</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Fri, 08 May 2026 17:59:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!wRec!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the rapidly evolving world of Large Language Models (LLMs), terms like &#8220;Agents&#8221; and &#8220;Skills&#8221; are thrown around constantly. If you look under the hood of a framework like Claude or a custom DevOps AI, you might notice something confusing: the instructions for a <strong>Skill</strong> often look exactly like the instructions for an <strong>Agent</strong>. They both live in <code>.md</code> files, they both use structured natural language, and they both define behaviors.</p><p>So, why distinguish between them? Because while their &#8220;DNA&#8221; (Markdown) is similar, their &#8220;Biology&#8221; (how the AI pursues them) is entirely different.</p><h2><strong>1. The Skill: The &#8220;Atomic&#8221; Tool</strong></h2><p>A <strong>Skill</strong> is a discrete, bounded capability. Think of it as a specialized tool in a digital Swiss Army knife, designed to perform one specific task with high reliability.</p><ul><li><p><strong>Claude&#8217;s Perspective:</strong> When Claude sees a skill, it views it as a <strong>contract</strong>. This contract stipulates: &#8220;If I provide input X in this exact format, I am guaranteed to get output Y.&#8221; It is a technical handshake where the AI relinquishes creative control in favor of procedural accuracy.</p></li><li><p><strong>The Scope:</strong> A skill doesn&#8217;t think about the big picture or the ultimate &#8220;why&#8221; of a user&#8217;s request. For example, a <code>fetch_github_repo</code> skill doesn&#8217;t care if you are fetching the repo to debug a crash, audit security, or simply learn the syntax; its only responsibility is to navigate the API authentication, handle pagination, and return the raw code string. It is a servant of the process, not the goal.</p></li><li><p><strong>The Content:</strong> In a <code>skills.md</code> file, you focus on <strong>parameters, constraints, and schemas</strong>. The language here is often clinical and precise, defining the exact boundaries of what the tool can and cannot do. You are defining the <em>mechanics</em> of an action.</p></li></ul><p><strong>The Analogy:</strong> A Skill is a <strong>Hammer</strong>. It is excellent at hitting nails, but it has no opinion on whether you are building a bookshelf or a birdhouse, and it certainly won&#8217;t decide to start swinging on its own.</p><h2><strong>2. The Agent: The &#8220;Reasoning&#8221; Orchestrator</strong></h2><p>An <strong>Agent</strong> is an autonomous entity designed to achieve a high-level goal by managing its own thoughts, planning its own trajectory, and executing actions.</p><ul><li><p><strong>Claude&#8217;s Perspective:</strong> When Claude acts as an agent, it moves from &#8220;Execution Mode&#8221; to &#8220;Reasoning Mode.&#8221; It adopts a persona and maintains a stateful memory of the task&#8217;s progress. Most importantly, it possesses the <strong>authority to decide</strong> which skills to use, when to use them, and &#8212; crucially &#8212; when to stop because the goal has been met or the path is blocked.</p></li><li><p><strong>The Scope:</strong> An agent is <strong>goal-oriented</strong> and context-aware. It looks at a prompt like &#8220;Migrate this app to AWS,&#8221; realizes that this isn&#8217;t a single step, and begins a mental breakdown of the problem. It identifies that it must first analyze the local environment, then provision cloud resources, and finally deploy the code. It manages the transitions between these phases.</p></li><li><p><strong>The Content:</strong> In an <code>agents.md</code> file, you focus on <strong>Persona, Logic, and Chain of Thought</strong>. The instructions here are strategic, telling the AI how to think when it encounters an error or how to prioritize competing interests. You are defining the <em>intent</em> and the <em>judgment</em> of the entity.</p></li></ul><p><strong>The Analogy:</strong> An Agent is the <strong>Carpenter</strong>. They know how to use the hammer, the saw, and the drill. They look at a blueprint, manage the timeline, and adjust their technique if they hit a knot in the wood. They turn a collection of movements into a finished home.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><h2><strong>3. If They Are Interchangeable, Why Exist as Two Entities?</strong></h2><p>Technically, you <em>could</em> write a single massive Markdown file that combines everything. However, the separation into <strong>Agents</strong> and <strong>Skills</strong> is an architectural choice for <strong>Scale, Precision, and Context Management</strong>.</p><ol><li><p><strong>Context Window Efficiency:</strong> If you put every instruction into the primary Agent, the &#8220;Context Window&#8221; (the AI&#8217;s active memory) gets cluttered with irrelevant details. By keeping Skills separate, the Agent only &#8220;loads&#8221; the specific skill it needs at that exact moment. This prevents &#8220;Instruction Dilution,&#8221; where the AI starts ignoring rules because there are too many of them.</p></li><li><p><strong>Modular Scalability:</strong> You can write a &#8220;Security Auditor&#8221; Agent and a &#8220;DevOps Engineer&#8221; Agent. Both might need the same <code>read_file</code> skill. By separating them, you don&#8217;t have to duplicate the technical code for reading files in both places. You define the <strong>Capability</strong> once (Skill) and the <strong>Governance</strong> twice (Agents).</p></li><li><p><strong>Deterministic vs. Creative:</strong> Skills are meant to be <strong>Deterministic</strong> (predictable). You want a calculator to always return 4 when you add 2+2. Agents are meant to be <strong>Creative</strong> (adaptive). You want an agent to pivot if a deployment fails. Keeping them separate ensures that your tools remain reliable while your logic remains flexible.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-UYn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-UYn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 424w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 848w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 1272w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-UYn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png" width="1400" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!-UYn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 424w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 848w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 1272w, https://substackcdn.com/image/fetch/$s_!-UYn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F102af412-04a3-480b-8128-bff65bf7dd42_1400x630.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2><strong>4. Parallel Agent Processing: The Speed Boost</strong></h2><p>One of the most powerful reasons to separate these entities is the ability to run <strong>Parallel Agent Processing</strong>.</p><p>In a traditional &#8220;Sequential&#8221; setup, one Agent does everything one step at a time. If it needs to research five topics, it does them one by one. In a Multi-Agent architecture, the &#8220;Lead Agent&#8221; can delegate work to several &#8220;Sub-Agents&#8221; simultaneously.</p><ul><li><p><strong>How it works:</strong> A high-level goal like &#8220;Audit this 50-file repository for security flaws&#8221; is broken down. The Lead Agent identifies 10 key modules and spawns 10 Sub-Agents at once.</p></li><li><p><strong>The Latency Benefit:</strong> If one file takes 30 seconds to audit, a sequential agent takes 5 minutes (30s x 10). A parallel system can finish the entire job in roughly 40 seconds (including coordination time).</p></li><li><p><strong>Cross-Checking:</strong> Parallel agents can also act as &#8220;Reviewers.&#8221; While Agent A generates a solution, Agent B (running in parallel) can begin analyzing the draft for security risks, effectively &#8220;vibe-checking&#8221; the work in real-time before it&#8217;s even presented to the user.</p></li></ul><h2><strong>Summary Table</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wRec!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wRec!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 424w, https://substackcdn.com/image/fetch/$s_!wRec!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 848w, https://substackcdn.com/image/fetch/$s_!wRec!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 1272w, https://substackcdn.com/image/fetch/$s_!wRec!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wRec!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png" width="1416" height="698" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:698,&quot;width&quot;:1416,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!wRec!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 424w, https://substackcdn.com/image/fetch/$s_!wRec!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 848w, https://substackcdn.com/image/fetch/$s_!wRec!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 1272w, https://substackcdn.com/image/fetch/$s_!wRec!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53a64b4-26ce-4165-a906-2b0882d982c4_1416x698.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2><strong>Conclusion</strong></h2><p>If you are building an AI system, don&#8217;t just build a library of skills. Without an Agentic layer to manage them, your AI is just a powerful engine without a driver. Conversely, an Agent without Skills is a brilliant strategist with no hands.</p><p>To build truly &#8220;smart&#8221; systems, define your <strong>Skills</strong> for precision and your <strong>Agents</strong> for purpose. By separating the <em>how</em> from the <em>why</em>, you enable modular growth and high-speed parallel processing that a monolithic &#8220;all-in-one&#8221; prompt could never achieve.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[[Part 2] Context Engineering: Token & Memory Management in LLMs. Practical Guide for AI Engineers]]></title><description><![CDATA[What really happens inside an LLM after you hit &#8220;send&#8221;? From token explosions to context rot, uncover the unseen bottlenecks.]]></description><link>https://aayushostwal2.substack.com/p/part-2-context-engineering-token</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/part-2-context-engineering-token</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Thu, 07 May 2026 13:34:59 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2v4U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>About the Series</strong></h2><p>This is a 5-article series on <strong>Context Engineering</strong>:</p><ol><li><p>&#9989; <a href="https://aayushostwal2.substack.com/p/part-1-context-engineering-7-prompt">Prompt Engineering</a></p></li><li><p><strong>&#65039;&#10145;&#65039; Memory and Token Management</strong></p></li><li><p>AI Grounding Strategies and Advanced RAG</p></li><li><p>LLM Evaluation and Ensemble Methods</p></li></ol><blockquote><p><em>These series are completely organic and contain a lot of examples from my experiences. I want to refer to all those engineers who are starting their AI journey.</em></p></blockquote><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Token and memory management are critical aspects of <strong>context engineering</strong>. But before we dive into them, it&#8217;s important to understand <strong>how an LLM actually generates a response</strong>.</p><p>Let&#8217;s walk through a simple example.</p><pre><code>Input: 
Explain how airplanes fly

LLM Output: 
Airplanes fly because of lift created by the wings moving through air.</code></pre><p>Here is a detailed diagram that demonstrates what happens when you make an API call.</p><ul><li><p>The input prompt is first converted into <strong>tokens</strong> &#8212; essentially a sequence of integers.</p></li><li><p>These integers are then transformed into <strong>vectors</strong>, known as <strong>embeddings</strong>.</p></li><li><p>The embeddings are passed into the LLM, where the model performs <strong>inference</strong>.</p></li><li><p>As the model processes them, it produces a <strong>probabilistic distribution over the next possible tokens</strong>.</p></li><li><p>The most likely token is selected, converted back into text, and appended to the response.</p></li><li><p>This process repeats step by step, allowing the model to generate a <strong>continuous sequence of text</strong>.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2v4U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2v4U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 424w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 848w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 1272w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2v4U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png" width="724" height="407.612" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:563,&quot;width&quot;:1000,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!2v4U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 424w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 848w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 1272w, https://substackcdn.com/image/fetch/$s_!2v4U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6be79634-ff30-4460-970e-586d8bb02f8e_1000x563.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Now let&#8217;s dive deeper into each step and see what&#8217;s actually happening under the hood.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Tokenization:</strong></h2><p>Language models do not read text the way humans do. Before a model can process a sentence, the text is first <strong>tokenized</strong>, and each token is mapped to a <strong>discrete numeric ID</strong>.</p><p>One straightforward way to do this is to assign a unique ID to each <strong>character</strong> or <strong>word</strong>.</p><p>Character-level tokenization, however, produces very long sequences. Even a short sentence turns into a large array of tokens, which makes computation inefficient and expensive.</p><p>Word-level tokenization has the opposite problem. The vocabulary grows extremely large because every unique word needs its own ID. Managing such a massive vocabulary quickly becomes a bottleneck.</p><p>To balance these trade-offs, modern language models use <strong>subword tokenization</strong>. Instead of relying strictly on characters or full words, this method splits rare or unfamiliar words into smaller, meaningful pieces while keeping common words as single tokens. This approach keeps the vocabulary manageable while preventing sequences from becoming unnecessarily long.</p><p>If you want to see how many tokens your prompt consumes, you can use the code snippet below:</p><pre><code><code>import tiktoken
# Background highlight colors
HIGHLIGHTS = [
    &#8220;\033[41m&#8221;,  # red background
    &#8220;\033[42m&#8221;,  # green background
    &#8220;\033[43m&#8221;,  # yellow background
    &#8220;\033[44m&#8221;,  # blue background
    &#8220;\033[45m&#8221;,  # magenta background
    &#8220;\033[46m&#8221;,  # cyan background
]
RESET = &#8220;\033[0m&#8221;

def highlight_tokens(text: str, model: str = &#8220;gpt-4o&#8221;):
    try:
        encoding = tiktoken.encoding_for_model(model)
    except KeyError:
        encoding = tiktoken.get_encoding(&#8221;cl100k_base&#8221;)
    tokens = encoding.encode(text)
    print(f&#8221;Total tokens: {len(tokens)}\n&#8221;)
    for i, token in enumerate(tokens):
        piece = encoding.decode([token])
        highlight = HIGHLIGHTS[i % len(HIGHLIGHTS)]
        print(f&#8221;{highlight}{piece}{RESET}&#8221;, end=&#8221;&#8220;)
    print(&#8221;\n&#8221;)

prompt = &#8220;Hello, explain me about tokenization&#8221;

highlight_tokens(prompt)</code></code></pre><p>The output looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TO3I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TO3I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 424w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 848w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 1272w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TO3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png" width="642" height="140" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c82e4860-0479-4dc8-bfef-4631464d9944_642x140.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:140,&quot;width&quot;:642,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!TO3I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 424w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 848w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 1272w, https://substackcdn.com/image/fetch/$s_!TO3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc82e4860-0479-4dc8-bfef-4631464d9944_642x140.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>It&#8217;s evident now that one word can correspond to multiple tokens if required.</p><p>But what happens if the prompt contains spelling mistakes?<br>Consider the sentence: <strong>&#8220;Hello, explain me about toeknizatoin.&#8221;</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f-uB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f-uB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 424w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 848w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 1272w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f-uB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png" width="648" height="132" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:132,&quot;width&quot;:648,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!f-uB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 424w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 848w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 1272w, https://substackcdn.com/image/fetch/$s_!f-uB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9907af0c-9706-4f53-bff5-1876a0f5f15e_648x132.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Since <strong>&#8220;toeknizatoin&#8221;</strong> is not a known word, the tokenizer cannot match it to familiar subwords. Instead, it splits the word into multiple smaller fragments. This increases the <strong>total number of tokens</strong> compared to the correctly spelled word <strong>&#8220;tokenization.&#8221;</strong></p><p>Even small spelling mistakes can therefore <strong>increase token usage</strong>. To keep prompts efficient, ensure they are <strong>spelled correctly and clearly written</strong>.</p><h2><strong>Embedding</strong></h2><p>Computers cannot process words directly &#8212; text must first be converted into numbers. But if that&#8217;s the case, why aren&#8217;t <strong>tokens alone</strong> sufficient?</p><p>Each token is mapped to an <strong>integer ID</strong>, but integers by themselves carry no semantic meaning. The numbers <strong>42</strong> and <strong>913</strong> don&#8217;t inherently tell the model anything about the relationship between the words they represent.</p><p>This is where <strong>embeddings</strong> come in.</p><p>An <strong>embedding</strong> is a dense vector representation of a token or piece of text that captures its <strong>semantic meaning</strong>. For example:</p><pre><code>vector_dog &#8594; [0.91, -0.22, 0.55, 0.10]
vector_cat &#8594; [0.88, -0.25, 0.59, 0.09]
vector_car &#8594; [-0.44, 0.77, -0.12, 0.63]</code></pre><p>In high-dimensional space, semantically similar words tend to appear <strong>closer together</strong>.</p><pre><code>vector_dog &#8226; vector_cat &#8594; high similarity (dot product)
vector_dog &#8226; vector_car &#8594; low similarity (dot product)</code></pre><p>This allows the model to understand relationships between words &#8212; something that simple token IDs cannot capture.</p><h2><strong>Inferencing</strong></h2><p>LLMs are <strong>stateless</strong>. When an application communicates with an LLM, the model retains <strong>no memory of past conversations</strong>. To generate a coherent response, every API call must include the <strong>relevant context</strong> in the prompt.</p><p>This requirement introduces a significant engineering constraint driven by the <strong>Transformer architecture</strong>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Self-Attention Matrix</strong></h2><p>Transformers rely on a <strong>self-attention mechanism</strong> to determine how each token relates to every other token in the sequence. Because of this, every token must attend to every other token.</p><p>As a result, adding more tokens increases the computational complexity <strong>quadratically &#8212; O(n&#178;)</strong>.</p><p>For example, consider the following sentence (assuming one word equals one token):</p><p>Input = <code>[AI, will, change, world]</code></p><p>Attention Matrix Looks 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_!Bdxf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bdxf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 424w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 848w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 1272w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bdxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png" width="700" height="313" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:313,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Bdxf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 424w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 848w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 1272w, https://substackcdn.com/image/fetch/$s_!Bdxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4914c652-9d04-452f-a263-a2be9dca9f64_700x313.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Each cell represents how much <strong>one token attends to another token</strong>.</p><p>This means the model computes <strong>4 &#215; 4 = 16 attention relationships</strong> for just four tokens. As the number of tokens grows, the number of computations grows rapidly, which is why <strong>token and memory management become critical in LLM applications</strong>.</p><blockquote><p><em>Since we have computation constraints, &#8220;<strong>Context Window</strong>&#8221; comes into the picture to avoid system degradation.</em></p></blockquote><h2><strong>Context Window and Token Limits</strong></h2><p>Context window is the maximum number of tokens that LLM can hold in the working memory. Hence, this acts as a hard boundary for input and generated tokens.</p><p>Context limits of common LLMs:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5-OY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5-OY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 424w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 848w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 1272w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5-OY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png" width="724" height="294.77142857142854" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7db0838-8406-4389-92f7-c5805e4573e1_700x285.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:285,&quot;width&quot;:700,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!5-OY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 424w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 848w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 1272w, https://substackcdn.com/image/fetch/$s_!5-OY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7db0838-8406-4389-92f7-c5805e4573e1_700x285.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2><strong>Prompt Tokens vs. Completion Tokens</strong></h2><p>Now, what does a <strong>128K token limit</strong> actually mean?</p><p>Suppose your input prompt &#8212; including the role, task, constraints, and output structure &#8212; already consumes <strong>120K tokens</strong>. In that case, the LLM has only <strong>8K tokens remaining</strong> to generate the response before it reaches the context limit and memory is exhausted.</p><h2><strong>Context Rot</strong></h2><p>Most modern LLMs now support much larger context windows. However, relying on extremely large prompts is often an <strong>architectural anti-pattern</strong>. Large prompts tend to suffer from a phenomenon known as <strong>context rot</strong>.</p><p>The attention mechanism in transformers typically shows high precision at the <strong>very beginning of the prompt</strong> (the <em>primacy effect</em>, where system instructions usually live) and at the <strong>very end of the prompt</strong> (the <em>recency effect</em>, where the latest user query appears).</p><p>As a result, information placed in the <strong>middle of a long prompt gradually loses influence</strong> during generation. This degradation of attention to mid-prompt information is what we refer to as <strong>Context Rot</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dmLS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dmLS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 424w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 848w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 1272w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dmLS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png" width="700" height="582" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:582,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!dmLS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 424w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 848w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 1272w, https://substackcdn.com/image/fetch/$s_!dmLS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73168343-e3d7-4d97-a063-9e38eae2bbc1_700x582.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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><h2></h2><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Memory Types in LLM Applications</strong></h2><p>Since LLMs are inherently stateless, what we call &#8220;memory&#8221; is not built into the model itself &#8212; it&#8217;s a system-level abstraction created and managed by the surrounding software architecture.</p><p><strong>Short-Term Memory (Conversation History):</strong><br>This is session-scoped memory that captures the ongoing interaction. Typically, it is maintained as an ordered array of messages representing the back-and-forth between the user and the system.</p><p><strong>Long-Term Memory (Semantic &amp; Factual Store):</strong><br>This layer enables persistence beyond a single session. It stores structured or unstructured information such as user preferences, facts, and organizational knowledge, allowing the system to retain context over time without endlessly expanding the prompt.</p><p><strong>Working Memory:</strong><br>Working memory consists of the immediate tokens being processed during a single inference. It is constrained by the model&#8217;s context window and functions similarly to RAM &#8212; holding only what is necessary for generating the current response.</p><p>This is where the LLM process chain of thoughts.</p><p>Together, these layers of memory operate in coordination to produce context-aware, personalized responses for the user.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eq0B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eq0B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 424w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 848w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 1272w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eq0B!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png" width="1200" height="457.4175824175824" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:555,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-large" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!eq0B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 424w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 848w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 1272w, https://substackcdn.com/image/fetch/$s_!eq0B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e4768e1-fb2b-4dc0-8cb7-9dc4ac069abd_5398x2056.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>For AI Engineers, understanding memory in LLM systems is critical because the model itself does not retain any state between requests. This means that everything we call &#8220;memory&#8221; must be explicitly designed and managed at the system level.</p><p>Now, since we know about tokens and memory with regard to LLMs. Let&#8217;s talk about strategies to manage them.</p><h2><strong>Token Management Strategies</strong></h2><p>To keep prompts within the model&#8217;s context window, you need a few guardrails at the code level. The exact approach depends on the use case, but there are a couple of patterns that show up again and again.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Deterministic Token Counting:</strong></h2><p>Before sending any payload to an LLM, you should programmatically count the tokens to forecast costs and prevent context window overflow. Sample Code:</p><pre><code>import tiktoken
class TokenManager:
    &#8220;&#8221;&#8220;Manages token counting and truncation using deterministic BPE encoding.&#8221;&#8220;&#8221;
    
    def __init__(self, model_name: str = &#8220;gpt-4o&#8221;):
        # Load the exact BPE encoding used by the target model
        self.encoding = tiktoken.encoding_for_model(model_name)
    
    def count_tokens(self, text: str) -&gt; int:
        &#8220;&#8221;&#8220;Returns the exact number of tokens in a string.&#8221;&#8220;&#8221;
        return len(self.encoding.encode(text))
        
    def truncate_to_budget(self, text: str, max_tokens: int) -&gt; str:
        &#8220;&#8221;&#8220;Truncates a string to fit within a specific token limit.&#8221;&#8220;&#8221;
        tokens = self.encoding.encode(text)
        if len(tokens) &lt;= max_tokens:
            return text
        # Slice the token array and decode back to a string
        truncated_tokens = tokens[:max_tokens]
        return self.encoding.decode(truncated_tokens)
# Usage Example
manager = TokenManager()
budgeted_context = manager.truncate_to_budget(&#8221;A massive document payload...&#8221;, max_tokens=2000)</code></pre><h2><strong>Sliding Window</strong></h2><p>This is the simplest way to manage short-term conversational memory. You keep a fixed number of recent messages, and as new ones come in, the oldest ones are dropped from the prompt.</p><p><strong>When to use:</strong><br>Works well for short, task-driven interactions where older context stops being useful pretty quickly.</p><p><strong>Downside:</strong><br>Anything important mentioned early on &#8212; like a user&#8217;s name or a key constraint &#8212; gets lost once it falls out of the window. This is often referred to as &#8220;hard amnesia.&#8221;</p><h2><strong>Summarization</strong></h2><p>To deal with that loss of context, you can introduce a summary layer. Instead of keeping the full conversation, you compress older messages into a concise summary.</p><p>The prompt then typically looks like:<br><strong>System Prompt + Summary + Last N messages (verbatim)</strong></p><p><strong>When to use:</strong><br>Useful for longer conversations &#8212; think support bots, assistants, or any system where maintaining continuity matters but you can&#8217;t afford to send the entire history every time.</p><p>Below is an example of how you might combine both approaches in practice.</p><pre><code>class MemoryBufferManager:
    &#8220;&#8221;&#8220;Maintains conversation history, enforcing token limits via sliding window and summarization.&#8221;&#8220;&#8221;
    
    def __init__(self, max_history_tokens: int = 4000):
        self.messages =
        self.summary = &#8220;&#8221;
        self.max_history_tokens = max_history_tokens
    def add_message(self, role: str, content: str):
        &#8220;&#8221;&#8220;Appends a new message and ensures the budget is maintained.&#8221;&#8220;&#8221;
        self.messages.append({&#8221;role&#8221;: role, &#8220;content&#8221;: content})
        self._enforce_budget()
    def _enforce_budget(self):
        &#8220;&#8221;&#8220;Continually evicts oldest messages until under budget.&#8221;&#8220;&#8221;
        while self._calculate_total_tokens() &gt; self.max_history_tokens and len(self.messages) &gt; 1:
            evicted_msg = self.messages.pop(0)
            self._update_summary_async(evicted_msg) 
    def _update_summary_async(self, evicted_message: dict):
        &#8220;&#8221;&#8220;
        In a production environment, this triggers an asynchronous LLM call 
        to merge the evicted_message into self.summary, preventing pipeline blocking.
        &#8220;&#8221;&#8220;
        # Pseudo-logic: self.summary = async_llm_call(f&#8221;Summarize: {self.summary} + {evicted_message}&#8221;)
        pass
        
    def get_prompt_context(self) -&gt; list:
        &#8220;&#8221;&#8220;Assembles the final context payload for the LLM.&#8221;&#8220;&#8221;
        context =
        if self.summary:
            context.append({&#8221;role&#8221;: &#8220;system&#8221;, &#8220;content&#8221;: f&#8221;Prior Conversation Summary: {self.summary}&#8221;})
        context.extend(self.messages)
        return context</code></pre><h2><strong>Semantic Chunking for RAG</strong></h2><p>When you bring long-term memory into prompts using RAG, large documents can&#8217;t be sent as-is. They need to be broken down into smaller chunks first.</p><p>A common way to do this is <strong>recursive character chunking</strong>.</p><p>Instead of splitting text randomly, this method follows a hierarchy of separators &#8212; like paragraphs, then lines, then words. It typically uses something like <code>["\n\n", "\n", " ", ""]</code> to break the text step by step.</p><p>The idea is simple: keep related content together for as long as possible, so each chunk still makes sense on its own.</p><pre><code>from typing import List

class RecursiveTextSplitter:
    &#8220;&#8221;&#8220;Splits text hierarchically to preserve semantic boundaries.&#8221;&#8220;&#8221;
    
    def __init__(self, chunk_size: int):
        self.chunk_size = chunk_size
        # Hierarchy of semantic separators: Paragraph -&gt; Sentence -&gt; Word -&gt; Character
        self.separators = [&#8221;\n\n&#8221;, &#8220;\n&#8221;, &#8220;. &#8220;, &#8220; &#8220;, &#8220;&#8221;]
    def split_text(self, text: str) -&gt; List[str]:
        return self._split_recursive(text, self.separators)
    def _split_recursive(self, text: str, separators: List[str]) -&gt; List[str]:
        # Failsafe for characters if no separators remain
        if not separators:
            return [text[:self.chunk_size]] # Hard slice
        separator = separators
        next_separators = separators[1:]
        
        # Split by current highest-order separator
        splits = text.split(separator)
        
        final_chunks =
        current_chunk = &#8220;&#8221;
        for split in splits:
            # Reconstruct the text piece with its separator
            piece = split if not current_chunk else separator + split
            
            # If combining the piece keeps us under budget, aggregate it
            if self.token_manager.count_tokens(current_chunk + piece) &lt;= self.chunk_size:
                current_chunk += piece
            else:
                if current_chunk:
                    final_chunks.append(current_chunk)
                # If the individual split itself is too large, recurse deeper
                if self.token_manager.count_tokens(split) &gt; self.chunk_size:
                    final_chunks.extend(self._split_recursive(split, next_separators))
                    current_chunk = &#8220;&#8221;
                else:
                    current_chunk = split
                    
        if current_chunk:
            final_chunks.append(current_chunk)
            
        return final_chunks</code></pre><h2><strong>Summary:</strong></h2><p>Building LLM applications isn&#8217;t just about prompts &#8212; it&#8217;s about disciplined system design. Tokens, memory, and context are your real constraints, and how you manage them defines success.</p><p>I&#8217;d be curious to know what techniques you&#8217;re using in production and what challenges you&#8217;ve encountered along the way.</p><div><hr></div><p></p>]]></content:encoded></item><item><title><![CDATA[[Part 1] Context Engineering: 7 Prompt Engineering Methods]]></title><description><![CDATA[Reduced Hallucination, Get Accurate, Consistent, and Concise Results]]></description><link>https://aayushostwal2.substack.com/p/part-1-context-engineering-7-prompt</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/part-1-context-engineering-7-prompt</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Mon, 04 May 2026 13:38:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!NBSS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>About the Series</strong></h2><p>This is a 5-article series on Context Engineering:</p><ol><li><p><strong>&#10145;&#65039; Prompt Engineering</strong></p></li><li><p>&#9989; <a href="https://aayushostwal2.substack.com/p/part-2-context-engineering-token">Memory and Token Management</a></p></li><li><p>AI Grounding Strategies and Advanced RAG</p></li><li><p>LLM Evaluation and Ensemble Methods</p></li></ol><blockquote><p><em>These series are completely organic and contain a lot of examples from my experiences. I want to refer to all those engineers who are starting their AI journey.</em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NBSS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NBSS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 424w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 848w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 1272w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NBSS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png" width="1456" height="794" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:794,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!NBSS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 424w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 848w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.png 1272w, https://substackcdn.com/image/fetch/$s_!NBSS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc13e9c-4960-4e4e-a4d1-a32c255d169d_2000x1091.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"><svg role="img" 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"><g><title></title><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"><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"><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>In this article, I have gathered 7 techniques for prompt engineering.</p><ol><li><p>Chain of Thought Prompting</p></li><li><p>Role-based Prompting</p></li><li><p>Few-Shot Prompting</p></li><li><p>Constraint Prompting + Negative Prompting</p></li><li><p>Output Formatting Prompting</p></li><li><p>Critic + Generator Pattern</p></li><li><p>HTML-based Prompting</p></li></ol><h2><strong>Chain of Thought Prompting (CoT)</strong></h2><p>CoT is a technique where LLM uses the intermediate steps to generate a comprehensive context. Instead of mapping a prompt directly to an output  <code>Prompt -&gt; Answer</code>, CoT inserts a reasoning pathway <code>Prompt -&gt; Reasoning Steps -&gt; Answer</code></p><h3><strong>Why CoT?</strong></h3><p>LLMs are nothing but next token predictors. When you ask them to answer directly, they tend to do all the computation in a single call.</p><p>Whereas in CoT, you provide them with more computational space. Also, for the step they are working on, all other steps act as a context.</p><p>The AI reads its own reasoning, which heavily biases its next predictions toward the correct logical path.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7RBY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7RBY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 424w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 848w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 1272w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7RBY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png" width="1400" height="1026" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1026,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!7RBY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 424w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 848w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 1272w, https://substackcdn.com/image/fetch/$s_!7RBY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F560041ce-40f3-41d1-832e-b7b804b7d145_1400x1026.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>CoT using ChatGPT Free Tier Model</p><p>While most of the models do support step thinking for simple tasks, for your use case, you can define a comprehensive Chain of Thoughts.</p><h3><strong>Benefits of Using CoT:</strong></h3><ul><li><p><strong>Massive Accuracy Boost:</strong> On complex logic, math, and reasoning benchmarks, CoT has been shown to increase AI accuracy by 20% to over 50%.</p></li><li><p><strong>Explainability:</strong> You are no longer dealing with a &#8220;black box.&#8221; You can read the AI&#8217;s &#8220;mind&#8221; and see exactly how it arrived at its conclusion.</p></li><li><p><strong>Debuggability:</strong> If the AI gets the answer wrong, you can look at the chain of thought, find the exact step where the logic failed, and correct your prompt or provide a better example.</p></li></ul><p>While you can use CoT for complex tasks like Analysis, Debugging, PR Review, and Strategic Planning, you can avoid this for simple tasks, such as summarizations.</p><h2><strong>Role-Based Prompting</strong></h2><p>This method is where you define a persona or a role for your LLM above the prompt.</p><p>To do Role-based prompting, you need to define <strong>S.O.A.P:</strong></p><p>To move from &#8220;Basic&#8221; to &#8220;Advanced,&#8221; you need to go beyond just naming a job. Use the framework:</p><ul><li><p><strong>S</strong>pecificity: Add constraints or &#8220;vibe&#8221; (e.g., &#8220;Use data-driven arguments and avoid fluff&#8221;).</p></li><li><p><strong>O</strong>bjective: State the goal clearly.</p></li><li><p><strong>P</strong>ersona: Define the title (e.g., &#8220;You are a Senior Data Scientist&#8221;).</p></li><li><p><strong>A</strong>udience: Tell the AI who it is talking to (e.g., &#8220;Speaking to a board of directors&#8221;).</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MEBc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MEBc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 424w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 848w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 1272w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MEBc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png" width="1456" height="421" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:421,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!MEBc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 424w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 848w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 1272w, https://substackcdn.com/image/fetch/$s_!MEBc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F612d41fb-1d5d-4e67-a3fb-ee4f3f1b95cf_2000x578.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Role-Based Prompting</p><h3><strong>Why?</strong></h3><p>When we specify the role, we <strong>narrow the probabilistic distribution</strong> of word selection. It sets the proper <strong>context, filtering</strong>, tone calibration, and depth of reasoning.</p><p>Here are some small examples that you can use:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_lcn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_lcn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 424w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 848w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 1272w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_lcn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png" width="1456" height="219" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:219,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!_lcn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 424w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 848w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 1272w, https://substackcdn.com/image/fetch/$s_!_lcn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33bda187-b642-4537-861e-e74bebc0fe85_2000x301.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Methods for Role-Based Prompting.</p><h2><strong>Few-Shot Prompting</strong></h2><p>It is a method where we give some examples in the prompt itself. These examples, known as &#8220;<strong>shots</strong>,&#8221; act as a template for the AI to follow.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fh50!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fh50!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 424w, https://substackcdn.com/image/fetch/$s_!fh50!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 848w, https://substackcdn.com/image/fetch/$s_!fh50!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 1272w, https://substackcdn.com/image/fetch/$s_!fh50!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fh50!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png" width="1400" height="746" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:746,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!fh50!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 424w, https://substackcdn.com/image/fetch/$s_!fh50!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 848w, https://substackcdn.com/image/fetch/$s_!fh50!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 1272w, https://substackcdn.com/image/fetch/$s_!fh50!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b48b975-8cbe-4e1f-91e1-31135e591483_1400x746.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Few-Shot Prompting Example</p><h3><strong>Why?</strong></h3><p>When you are using the Few-Shot Method, you help LLMs to:</p><ul><li><p><strong>Recognize Patterns</strong>: Few-Shot prompting can help more accurately than a 500-word prompt. It helps AI to mimic rather than just calculate.</p></li><li><p><strong>Consistent Output</strong>: Since we have given a template, the output is also streamlined.</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Constraint Prompting</strong></h2><p>Here, we define clear boundaries, rules, or limitations for LLMs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8L9q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8L9q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 424w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 848w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 1272w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8L9q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png" width="1400" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!8L9q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 424w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 848w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 1272w, https://substackcdn.com/image/fetch/$s_!8L9q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3c3035-2e63-4c48-a299-75dd5c410952_1400x630.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Constraint Prompting</p><h3><strong>Why?</strong></h3><ul><li><p><strong>Precision:</strong> It eliminates &#8220;<strong>AI fluff</strong>&#8221; and hallucinations.</p></li><li><p><strong>Efficiency:</strong> You save time on editing because the first draft is already formatted for your needs.</p></li></ul><p>In constraint prompting, you can also define what things you don&#8217;t want. That&#8217;s called <strong>Negative Prompting</strong>.</p><p><strong>Negative Prompting </strong>is used for:</p><ul><li><p><strong>Anatomy &amp; Quality Control:</strong> To avoid the &#8220;uncanny valley&#8221; (extra fingers, fused limbs, distorted faces).</p></li><li><p><strong>Aesthetic Direction:</strong> To remove styles you dislike, such as &#8220;cartoonish&#8221; or &#8220;high contrast.&#8221;</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bA26!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bA26!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 424w, https://substackcdn.com/image/fetch/$s_!bA26!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 848w, https://substackcdn.com/image/fetch/$s_!bA26!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 1272w, https://substackcdn.com/image/fetch/$s_!bA26!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bA26!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png" width="1162" height="456" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:456,&quot;width&quot;:1162,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!bA26!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 424w, https://substackcdn.com/image/fetch/$s_!bA26!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 848w, https://substackcdn.com/image/fetch/$s_!bA26!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 1272w, https://substackcdn.com/image/fetch/$s_!bA26!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95b6766-7c6c-4219-b7ab-d4c9ca1faa53_1162x456.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Negative Prompting</p><h2><strong>Output Formatting Prompting</strong></h2><p>In this method, you clearly define the output structure. Instead of a model determining the structure, you provide a mold for output.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VD6p!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VD6p!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 424w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 848w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 1272w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VD6p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png" width="1400" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!VD6p!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 424w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 848w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 1272w, https://substackcdn.com/image/fetch/$s_!VD6p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c480f3-7b22-4545-96a3-42ee31a14047_1400x190.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Output Formatting Prompting</p><h3><strong>Why:</strong></h3><ul><li><p><strong>Automation Readiness</strong>: If you are building an app, the output structure matters when it comes to reliability and scalability.</p></li><li><p><strong>Consistency</strong>: You get a consistent output.</p></li></ul><h2><strong>Critic + Generator Pattern</strong></h2><p>In this pattern, we use two distinct roles or agents that work together to achieve a goal in a single prompt.</p><ul><li><p><strong>Generator</strong>: Which creates&#8230;</p></li><li><p><strong>Critic</strong>: Which evaluates&#8230;</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k6UG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k6UG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 424w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 848w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 1272w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k6UG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png" width="1400" height="703" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:703,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!k6UG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 424w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 848w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 1272w, https://substackcdn.com/image/fetch/$s_!k6UG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cedea19-de28-462a-bb93-cc5902cfd30e_1400x703.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Critic + Generator Pattern</p><h3><strong>Why?</strong></h3><ul><li><p><strong>Reduced Hallucinations</strong>: The Critic can catch factual errors that the Generator made.</p></li><li><p><strong>Higher Reasoning</strong>: By forcing the AI to &#8220;<strong>think twice</strong>,&#8221; you simulate another layer of reasoning which single-pass prompt often lacks.</p></li></ul><h2><strong>HTML-based Prompting</strong></h2><p>Using <strong>HTML tags in prompts</strong> can improve how LLMs understand structure and context.</p><p>While models don&#8217;t actually &#8220;render HTML,&#8221; they are trained on a huge amount of HTML from the web, so they naturally understand these patterns. Here are the main benefits.</p><h3><strong>Why?</strong></h3><ul><li><p>LLM understands which text belongs to which Instruction, which reduces instruction mixing.</p></li><li><p>Improves prompt readability</p></li><li><p>Helps in giving nested instructions as it understands HTML code.</p></li></ul><h2><strong>Ensembling Prompting Techniques: Pro Tip</strong></h2><p>When you&#8217;re designing a prompt for you production grade application, it&#8217;s very obvious to use a combination of the above techniques.</p><p>And this helps you to not only get correct output for the first time but also the 1000th time.</p><p>Here is a sample prompt template on how an engineer can apply all these techniques together:</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">&lt;prompt&gt;

&lt;!-- Role Based Prompting --&gt;
&lt;role&gt;
Senior Backend Engineer
&lt;/role&gt;

&lt;objective&gt;
Design a scalable user authentication system.
&lt;/objective&gt;

&lt;!-- Chain of Thoughts (CoT) --&gt;
&lt;instruction id="1"&gt;
&lt;title&gt;Architecture Exploration&lt;/title&gt;

&lt;tasks&gt;
1. Explore 3 architecture options
2. Compare the architectures based on scalability, security, and operational complexity
3. Select the best design
4. Provide a system architecture diagram
5. Provide sample API endpoints
&lt;/tasks&gt;

&lt;/instruction&gt;

&lt;!-- Critic + Generator Pattern --&gt;
&lt;instruction id="2"&gt;
&lt;title&gt;Code Review&lt;/title&gt;

Act as a senior code reviewer and critique the authentication implementation.

Check for:
- Password leaks
- Secure password hashing
- Token security
- Session hijacking protection
- Rate limiting
- Handling of authentication edge cases
&lt;/instruction&gt;

&lt;instruction id="3"&gt;
&lt;title&gt;Refinement&lt;/title&gt;

Improve the implementation based on the review feedback and produce the updated version.
&lt;/instruction&gt;

&lt;!-- Few Shot Prompting --&gt;
&lt;examples&gt;

&lt;example&gt;
&lt;title&gt;System Diagram&lt;/title&gt;

[Client] -&gt; [API Gateway / Middleware] -&gt; [Redis (Atomic Counter)] -&gt; [App Service]

&lt;/example&gt;

&lt;example&gt;
&lt;title&gt;API Endpoint&lt;/title&gt;

GET /v1/resource  
Returns **429 Too Many Requests** if the bucket is empty.

&lt;/example&gt;

&lt;/examples&gt;

&lt;!-- Constraint Prompting --&gt;
&lt;constraints&gt;

- Must support 1M users
- Use PostgreSQL as the primary database
- Use Redis for session storage
- Must support horizontal scaling

&lt;/constraints&gt;

&lt;!-- Output Formatting Prompting --&gt;
&lt;output_format&gt;

Return the response in **Structured Markdown** with the following sections:

1. Architecture Options
2. Architecture Comparison Table
3. Selected Architecture
4. System Diagram
5. API Endpoints
6. Security Review
7. Improved Implementation

&lt;/output_format&gt;

&lt;/prompt&gt;</code></pre></div><p>That&#8217;s the end of the article. Hope you have found valuable insights. The goal is no longer just to give the model the right answer &#8212; it is to build a system that knows exactly which part of its &#8220;world&#8221; to look at to find that answer itself.</p><p>Do share what different techniques you are using for writing optimal prompts.</p><p><strong>Stay tuned for Part 2, where we move from static prompts to dynamic, self-evolving context architectures.</strong></p>]]></content:encoded></item><item><title><![CDATA[Why “Just Coding” Will Get You Fired in 2026 (And What to Learn Instead)]]></title><description><![CDATA[What do Netflix, Meta, Amazon use? The tech bubble burst, and the rules changed. Here is the battle-tested, real-world roadmap to staying relevant in an age of AI and hyper-efficiency.]]></description><link>https://aayushostwal2.substack.com/p/why-just-coding-will-get-you-fired</link><guid isPermaLink="false">https://aayushostwal2.substack.com/p/why-just-coding-will-get-you-fired</guid><dc:creator><![CDATA[Aayush Ostwal]]></dc:creator><pubDate>Mon, 04 May 2026 02:34:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!CiK_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you&#8217;ve been paying attention to the market over the last few years, you know the game has fundamentally changed. The zero-interest-rate era of &#8220;growth at all costs&#8221; and massive, siloed engineering teams is over. We&#8217;ve entered an era obsessed with lean efficiency, profitability, and, above all, AI-driven productivity.</p><p>Today, engineering managers aren&#8217;t looking for &#8220;code monkeys&#8221; to mechanically translate Jira tickets into syntax. We are looking for <strong>Product Engineers</strong>. We want holistic developers who understand business value, user experience, and how to leverage AI to multiply their output.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Before I write a single line of code today, I have to ask: <em>&#8220;How does this feature impact our MRR? Is the cloud compute cost of this microservice justified by user engagement?&#8221;</em></p><p>If you want to be highly competitive in the current market, you don&#8217;t need to memorize every syntax quirk of every new framework. Instead, you must deeply understand the underlying <em>concepts</em>, the architectural trade-offs, and what happens when your code actually hits production at scale. You need a &#8220;T-shaped&#8221; skill set: deep expertise in one specific area, supported by a broad, working knowledge across the rest of the stack.</p><p>Here is my pragmatic, battle-tested roadmap for the 2026 software engineer, complete with how the big players are actually using this stuff in the real world.</p><h2><strong>1. The AI-Augmented Developer (The New Baseline)</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tSRt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tSRt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tSRt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png" width="700" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!tSRt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!tSRt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F288ae1cd-f937-4e1d-871f-5f87e2a7f9ad_700x382.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"><svg role="img" 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"><g><title></title><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"><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"><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>Let&#8217;s be real: writing every single line of boilerplate code from scratch isn&#8217;t a badge of honor anymore &#8212; it&#8217;s an inefficient use of company time. You must know how to build <em>with</em> AI (to speed up your workflow 5x) and build features <em>using</em> AI (to deliver smarter products).</p><h2><strong>Core Concepts in the Wild:</strong></h2><ul><li><p><strong>Retrieval-Augmented Generation (RAG):</strong> Foundational LLMs are useless for proprietary company knowledge. RAG is how we fetch relevant private data from our databases and inject it into the LLM&#8217;s prompt <em>before</em> it generates an answer. It&#8217;s vastly cheaper than fine-tuning and kills hallucinations.</p></li><li><p><strong>Agentic Workflows:</strong> We&#8217;ve moved beyond chatbots. Agents are autonomous systems given a goal and tools (like a Python interpreter or database access)</p></li><li><p><strong>Real-World Example:</strong> Look at <strong>Meta</strong>. They utilize multi-agent systems internally where &#8220;Planner Agents&#8221; delegate tasks to &#8220;Coder Agents&#8221; to automatically review PRs, find security vulnerabilities, and suggest architectural fixes before a human even looks at the code.</p></li><li><p><strong>Vector Embeddings:</strong> Transforming unstructured data (text, images) into mathematical vectors to search by <em>meaning</em>.</p></li><li><p><strong>Real-World Example:</strong> <strong>Netflix</strong> relies heavily on high-dimensional vector embeddings for its personalization engines. When you watch a movie, you aren&#8217;t just matching tags; your profile is mathematically clustered near similar content in a latent space, allowing their systems to surface exactly what you want to watch next.</p></li><li><p><strong>Token Economics:</strong> AI API usage is billed by the &#8220;token&#8221;. A senior engineer knows when to use a fast, cheap model (like Claude Haiku) for basic routing, and when to bring out the heavyweight models for reasoning.</p></li></ul><h2><strong>The Toolkit:</strong></h2><ul><li><p><strong>AI IDEs:</strong> <strong>Cursor</strong> is currently dominating our workflows. <strong>GitHub Copilot</strong> remains the enterprise standard.</p></li><li><p><strong>Orchestration:</strong> <strong>LangChain</strong> or <strong>LlamaIndex</strong> to build robust RAG pipelines.</p></li></ul><h2><strong>2. Backend Engineering &amp; System Architecture</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w2SG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w2SG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w2SG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png" width="700" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!w2SG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!w2SG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8698f2e-9c06-4097-b566-aefcc74ae515_700x382.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 backend isn&#8217;t just about simple CRUD endpoints anymore. It&#8217;s about high-performance microservices and event-driven systems capable of handling asynchronous, unpredictable AI workloads.</p><h2><strong>Core Concepts in the Wild:</strong></h2><ul><li><p><strong>API Architectures (REST vs GraphQL vs gRPC):</strong></p></li><li><p><strong>Real-World Example:</strong> <strong>Netflix</strong> is the poster child for microservices and <strong>gRPC</strong>. When you hit &#8220;play,&#8221; that request doesn&#8217;t go to a monolith; it fans out via gRPC (which uses ultra-fast, tightly compressed Protocol Buffers) to dozens of internal microservices to verify billing, fetch DRM licenses, and locate the nearest CDN node in milliseconds.</p></li><li><p><strong>Event-Driven Architecture &amp; Eventual Consistency:</strong> Moving away from synchronous requests where Service A waits idly for Service B.</p></li><li><p><strong>Real-World Example:</strong> <strong>LinkedIn</strong> literally invented <strong>Apache Kafka</strong> because their traditional databases couldn&#8217;t handle the sheer volume of profile views, messages, and feed updates. By moving to a Publisher/Subscriber (Pub/Sub) model, systems communicate asynchronously. It guarantees <em>eventual consistency</em> &#8212; your connection count might take a few seconds to update across the globe, but the system never goes down.</p></li><li><p><strong>Idempotency:</strong> An operation that produces the same result no matter how many times it&#8217;s executed. If a user&#8217;s network drops and they mash &#8220;Submit Payment&#8221; five times, your backend must recognize the duplicate request ID and charge them only once.</p></li></ul><h2><strong>The Toolkit:</strong></h2><ul><li><p><strong>Languages:</strong> <strong>Python</strong> (mandatory for AI/Data), <strong>Go</strong> (for high-performance concurrent cloud services), <strong>Node.js/TypeScript</strong>, and increasingly, <strong>Rust</strong>.</p></li><li><p><strong>Brokers &amp; Caching:</strong> <strong>Kafka</strong>, <strong>RabbitMQ</strong>, and <strong>Redis</strong>.</p></li></ul><h2><strong>3. Databases (Traditional &amp; Modern)</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dszO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dszO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!dszO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!dszO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!dszO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dszO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png" width="700" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d65f690-f094-4438-b305-2f7c2af35718_700x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!dszO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!dszO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!dszO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!dszO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d65f690-f094-4438-b305-2f7c2af35718_700x382.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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>Data is the foundation. The volume of unstructured data generated by AI has changed how we store information, but relational integrity is as crucial as ever.</p><h2><strong>Core Concepts in the Wild:</strong></h2><ul><li><p><strong>CAP Theorem vs. ACID Compliance:</strong> You can only guarantee two out of three: Consistency, Availability, and Partition tolerance</p></li><li><p><strong>Real-World Example:</strong> Think about <strong>Amazon on Prime Day</strong>. They use <strong>DynamoDB</strong> (NoSQL) for the shopping cart. Why? Because <em>Availability</em> is everything. If the database partition fails, Amazon would rather risk a momentary inconsistency (a slight delay in updating inventory numbers) than tell a user &#8220;Error: Cannot add to cart.&#8221; They chose Availability over strict Consistency to save millions in revenue per minute.</p></li><li><p><strong>Database Denormalization:</strong> While we learn 3rd Normal Form in school, at scale, we often deliberately <em>denormalize</em> (store duplicate data together) to avoid massive, database-locking <code>JOIN</code> operations.</p></li><li><p><strong>Real-World Example:</strong> <strong>Meta</strong> built TAO, a distributed data store, specifically to cache and serve their massively denormalized social graph because traditional SQL joins simply couldn&#8217;t scale to billions of daily active users fetching complex feeds.</p></li></ul><h2><strong>The Toolkit:</strong></h2><ul><li><p><strong>Relational:</strong> <strong>PostgreSQL</strong> is the absolute &#8220;Swiss Army Knife&#8221; of the industry right now.</p></li><li><p><strong>Vector DBs:</strong> <strong>pgvector</strong>, <strong>Pinecone</strong>, or <strong>Milvus</strong> for housing billions of AI embeddings.</p></li><li><p><strong>ORMs:</strong> <strong>Prisma</strong> or <strong>Drizzle</strong> for end-to-end type safety in TypeScript environments.</p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.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://aayushostwal2.substack.com/subscribe?"><span>Subscribe now</span></a></p><p></p><h2><strong>4. Frontend &amp; Web Development</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ka9K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ka9K!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ka9K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png" width="700" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a18b6606-31b4-4943-96bf-d450498abbdc_700x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ka9K!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!ka9K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa18b6606-31b4-4943-96bf-d450498abbdc_700x382.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 exhaustive &#8220;framework wars&#8221; of the 2010s have largely settled. Today, frontend engineering is obsessed with perceived performance, extreme accessibility, and shipping zero unnecessary JavaScript.</p><h2><strong>Core Concepts in the Wild:</strong></h2><ul><li><p><strong>Rendering Strategies (CSR, SSR, SSG, RSC):</strong> &gt; <strong>Real-World Example:</strong> <strong>Netflix</strong> famously removed client-side React from their landing pages. By shifting to Server-Side Rendering (SSR) and vanilla JS for their marketing pages, they drastically cut the Time-to-Interactive (TTI) for users on slow mobile connections.</p></li><li><p><strong>State Management Paradigm Shift:</strong> We&#8217;ve moved away from massive global stores (like legacy Redux) toward simpler local state, treating server data purely as a &#8220;cache.&#8221;</p></li><li><p><strong>Real-World Example:</strong> Look at how <strong>Meta</strong> rebuilt the modern Facebook.com web app. They relied heavily on Relay (GraphQL) to fetch <em>exactly</em> the data a component needs &#8212; nothing more, nothing less &#8212; drastically reducing the payload size sent to the user&#8217;s browser.</p></li><li><p><strong>Accessibility (a11y):</strong> Ensuring your application is natively usable by people with visual, auditory, or motor disabilities. This is no longer an afterthought; it is a strict legal requirement.</p></li></ul><h2><strong>The Toolkit:</strong></h2><ul><li><p><strong>The Non-Negotiable:</strong> <strong>TypeScript</strong>. Writing vanilla JS in enterprise apps is basically professional negligence today.</p></li><li><p><strong>Frameworks:</strong> <strong>React</strong> and <strong>Next.js</strong> (App Router) dominate. <strong>Vue/Nuxt</strong> is the strongest alternative.</p></li><li><p><strong>Styling &amp; Build:</strong> <strong>Tailwind CSS</strong> and <strong>Vite</strong>.</p></li></ul><h2><strong>5. Cloud, DevOps &amp; Security (Infrastructure)</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CiK_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CiK_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CiK_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png" width="700" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!CiK_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 424w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 848w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 1272w, https://substackcdn.com/image/fetch/$s_!CiK_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1094c6b0-49eb-43b7-91b9-37b91f0d459b_700x382.png 1456w" sizes="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"><svg role="img" 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"><g><title></title><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"><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"><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 historical wall between &#8220;developer&#8221; and &#8220;operations&#8221; is gone. The modern paradigm is <em>&#8220;you build it, you run it.&#8221;</em></p><h2><strong>Core Concepts in the Wild:</strong></h2><ul><li><p><strong>Deployment Strategies:</strong> Pushing updates without taking the system down</p></li><li><p><strong>Real-World Example:</strong> <strong>Amazon</strong> executes thousands of deployments a day without anyone noticing, using <strong>Canary Rollouts</strong>. They deploy a new feature to just 1% of users, monitor their observability dashboards for error spikes, and slowly ramp it up to 100% if metrics stay green.</p></li><li><p><strong>Observability (Logs, Metrics, Traces):</strong> Knowing exactly <em>why</em> your app is failing on the inside.</p></li><li><p><strong>Chaos Engineering:</strong> &gt; <strong>Real-World Example:</strong> <strong>Netflix</strong> pioneered &#8220;Chaos Monkey.&#8221; They literally run scripts that randomly kill production servers during business hours. Why? To force their engineers to build systems so resilient and decoupled that the destruction of a random node doesn&#8217;t impact the end user&#8217;s streaming experience.</p></li><li><p><strong>Infrastructure as Code (IaC):</strong> Writing declarative code (Terraform) to provision servers instead of clicking through a console.</p></li></ul><h2><strong>The Toolkit:</strong></h2><ul><li><p><strong>Containers:</strong> <strong>Docker</strong> and <strong>Kubernetes</strong> (K8s).</p></li><li><p><strong>Cloud &amp; CI/CD:</strong> <strong>AWS/GCP/Azure</strong>, provisioned via <strong>Terraform</strong>, automated through <strong>GitHub Actions</strong>.</p></li><li><p><strong>Observability:</strong> <strong>Datadog</strong> or <strong>Prometheus/Grafana</strong>.</p></li></ul><h2><strong>Final Thoughts</strong></h2><p>Don&#8217;t try to learn all of this in a weekend. The best engineers learn pragmatically. Build a real application, run into a scaling bottleneck, and <em>then</em> learn the tool that solves it.</p><p>The tech stack will change again by 2030, but an engineer who understands system trade-offs, business value, and how to adapt will always be in demand. Keep building.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aayushostwal2.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</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="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>