<?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"><channel><title><![CDATA[Generative Artificial intelligence]]></title><description><![CDATA[Generative Artificial intelligence]]></description><link>https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 19 Jun 2026 22:16:17 GMT</lastBuildDate><atom:link href="https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Deep Agents: What LangChain Quietly Built While Everyone Was Arguing About Prompts]]></title><description><![CDATA[The "Shallow Agent" Problem Nobody Talks About
If you've been following my previous articles on Prompt Engineering and Context Engineering, you know I've been going deeper and deeper into how LLMs act]]></description><link>https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/deep-agents-langchain-context-engineering-in-action</link><guid isPermaLink="true">https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/deep-agents-langchain-context-engineering-in-action</guid><category><![CDATA[deepagents]]></category><category><![CDATA[langchain]]></category><category><![CDATA[context engineering]]></category><category><![CDATA[generative ai]]></category><category><![CDATA[ai agents]]></category><category><![CDATA[langgraph]]></category><dc:creator><![CDATA[Pritam Chakroborty]]></dc:creator><pubDate>Fri, 17 Apr 2026 18:36:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/62b93a0592447c9aed5bb343/cfed4c85-346c-4ed6-9b52-65071d9a7ff6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The "Shallow Agent" Problem Nobody Talks About</h2>
<p>If you've been following my previous articles on <a href="https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompt-engineering-the-art-of-effective-ai-communication">Prompt Engineering</a> and <a href="https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/beyond-prompts-the-rise-of-context-engineering">Context Engineering</a>, you know I've been going deeper and deeper into how LLMs actually work under the hood.</p>
<p>This article is the natural next step. Because here's the thing —</p>
<p>We've all seen the basic agent architecture. An LLM running in a loop, calling tools, getting results, calling more tools. It's elegant. It's simple. And for basic tasks, it works great.</p>
<p>But try giving it a complex task — something like "research the top 5 competitors in the Indian EdTech space, compare their pricing models, and draft a strategy doc" — and watch it fall apart.</p>
<p>Why? Because the agent becomes <strong>shallow</strong>.</p>
<p>"Shallow" here means the agent can't plan over longer time horizons. It solves whatever is immediately in front of it rather than thinking about the bigger picture. After 15-20 tool calls, the original objective gets buried under thousands of tokens of intermediate results. The agent starts drifting, repeating work, or just... stopping early because it forgot there were more steps.</p>
<p>Sound familiar? It should. This is exactly the <strong>Context Distraction</strong> problem I wrote about in my Context Engineering article. The context grows so long that the model over-focuses on recent content and loses sight of the original goal.</p>
<p>So, what's the fix?</p>
<hr />
<h2>Enter Deep Agents</h2>
<p>LangChain noticed something interesting. Applications like <strong>Claude Code</strong>, <strong>Deep Research</strong>, and <strong>Manus</strong> — the agents that actually work on complex, long-running tasks — they all share four characteristics:</p>
<ol>
<li><p>A <strong>planning tool</strong></p>
</li>
<li><p><strong>Sub-agents</strong></p>
</li>
<li><p>Access to a <strong>file system</strong></p>
</li>
<li><p>A <strong>detailed system prompt</strong></p>
</li>
</ol>
<p>That's it. The core algorithm is the same — an LLM calling tools in a loop. The difference is <em>infrastructure around the loop</em>.</p>
<p>LangChain packaged these four primitives into an open-source library called <code>deepagents</code>. They call it an "agent harness" — not a new framework, not a new reasoning paradigm, just an opinionated wrapper that gives your agent the equipment it needs to go deep instead of staying shallow.</p>
<p>Think of it this way:</p>
<blockquote>
<p><strong>LangGraph gives you an engine and a transmission. Deep Agents gives you a car.</strong></p>
</blockquote>
<p>Install it with one line:</p>
<pre><code class="language-bash">pip install deepagents
</code></pre>
<p>And the simplest possible agent looks like this:</p>
<pre><code class="language-python">from deepagents import create_deep_agent

def get_weather(city: str) -&gt; str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_deep_agent(
    model="openai:gpt-4o",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

agent.invoke(
    {"messages": [{"role": "user", "content": "what is the weather in sf"}]}
)
</code></pre>
<p>One function. Under the hood, it handles the LangGraph graph, state management, streaming, and context window management — none of which you touched.</p>
<p>But the real magic is in those four primitives. Let's break each one down.</p>
<hr />
<h2>The Four Pillars of Deep Agents</h2>
<h3>🧠 Pillar 1: The Planning Tool (The Most Counterintuitive One)</h3>
<p>Every deep agent automatically gets a <code>write_todos</code> tool.</p>
<p>Now here's the part that blew my mind when I first learned about it —</p>
<p><strong>This tool is a no-op. It literally does nothing.</strong></p>
<p>When the model calls <code>write_todos(["research X", "compare Y and Z", "draft summary"])</code>, no scheduler runs. No task queue gets populated. No database row is written. The tool just accepts the input and returns something like "todos updated."</p>
<p>So why does it work?</p>
<p>Remember the <strong>"Attention Budget"</strong> concept from my Context Engineering article? LLMs have no hidden scratchpad, no persistent working memory between tool calls. <strong>The context window IS the model's memory.</strong> Whatever isn't written down effectively doesn't exist for the model on the next step.</p>
<p>When the agent calls <code>write_todos</code>, three things happen:</p>
<ol>
<li><p><strong>The plan gets serialized into tokens.</strong> The todo list now physically exists as text in the message history.</p>
</li>
<li><p><strong>Future token predictions attend to it.</strong> Every subsequent word the model generates is conditioned on that plan being right there in recent context.</p>
</li>
<li><p><strong>The act of writing forced decomposition.</strong> To emit the tool call, the model had to commit to a specific breakdown. That commitment is now anchored.</p>
</li>
</ol>
<p>Without this, on a long task the model drifts. After 30 tool calls and 15,000 tokens of intermediate results, the original objective gets buried. The plan tool prevents this by keeping the goal in the "hot zone" of recent context.</p>
<blockquote>
<p>💡 Harrison Chase (LangChain CEO) specifically credits Claude Code as the inspiration. Claude Code's Todo list tool is also a no-op — it's pure context engineering strategy. Prompting matters still!</p>
</blockquote>
<p>This connects directly to what I discussed in the Context Engineering article — every token in the context affects how the model behaves. The plan tool is deliberately injecting <em>high-value tokens</em> that anchor the model's behavior across dozens of turns.</p>
<p><strong>The tool's functional uselessness is the feature, not a bug.</strong> A "real" scheduler would couple the agent to external infrastructure. A no-op just shapes the language model's own behavior — which is the only thing that actually matters.</p>
<hr />
<h3>📁 Pillar 2: The Virtual File System (Context Offloading in Action)</h3>
<p>Deep agents get built-in tools: <code>ls</code>, <code>read_file</code>, <code>write_file</code>, <code>edit_file</code>.</p>
<p>Now, if you've read my Context Engineering article, this should immediately ring a bell. This is <strong>Context Offloading</strong> — the strategy where the agent stores information outside the LLM's context window and pulls it back in when needed.</p>
<p>Instead of stuffing 50,000 tokens of research results into the conversation history (hello, Context Distraction 👋), the agent writes intermediate results to files. When it needs that information later, it reads just the relevant file.</p>
<p>The file system is <strong>virtual by default</strong> — "files" live in agent state, not on your actual disk. But you can swap backends:</p>
<ul>
<li><p><strong>In-memory</strong> — for quick, ephemeral tasks</p>
</li>
<li><p><strong>Local disk</strong> — for development</p>
</li>
<li><p><strong>LangGraph Store</strong> — for cross-thread persistence</p>
</li>
<li><p><strong>Sandboxes</strong> (Modal, Daytona, Deno) — for isolated code execution</p>
</li>
</ul>
<p>When using a sandbox backend, agents also get an <code>execute</code> tool to run shell commands — tests, builds, git operations. That's how the CLI version works as a terminal coding agent comparable to Claude Code.</p>
<blockquote>
<p>💡 The key insight: The file system isn't just storage. It's a <strong>context management strategy</strong>. Write large results to a file, keep a short summary in context, read the file back only when you need the details. This directly combats Context Confusion and Context Distraction.</p>
</blockquote>
<hr />
<h3>🤖 Pillar 3: Sub-agents (Context Quarantine in Disguise)</h3>
<p>A built-in <code>task</code> tool lets the main agent spawn specialized sub-agents. Each sub-agent gets its own clean context window, goes deep on a specific subtask, and returns only a condensed summary.</p>
<p>Again — this is exactly the <strong>Context Quarantine</strong> strategy from my previous article. Rather than one agent attempting to maintain state across an entire project, specialized sub-agents handle focused tasks with isolated contexts.</p>
<p>Here's how it works mechanically:</p>
<ol>
<li><p>The supervisor agent calls <code>task(description="research competitor pricing")</code>.</p>
</li>
<li><p>The runtime spins up a sub-agent with a fresh context window.</p>
</li>
<li><p>The sub-agent runs its full tool-calling loop — maybe 20-30 LLM calls, tens of thousands of tokens.</p>
</li>
<li><p>It returns only a condensed summary (1,000–2,000 tokens) to the supervisor.</p>
</li>
<li><p>The supervisor's context stays clean.</p>
</li>
</ol>
<p><strong>The sub-agent might explore extensively, but the supervisor only sees the distilled result.</strong> The main context never gets polluted with raw search results, API responses, or intermediate reasoning.</p>
<h4>Inline vs. Async Sub-agents</h4>
<p>Now, there's an important nuance here that the latest release (v0.5) addresses.</p>
<p><strong>Inline sub-agents block the supervisor.</strong> When the supervisor calls <code>task()</code>, its entire execution loop freezes until the sub-agent finishes. For a sub-agent doing deep research — 40 LLM calls, each taking 2-10 seconds, plus tool calls — that's easily 5-15 minutes of wall-clock time where the supervisor can't do anything. Can't respond to the user, can't work on other tasks, can't spawn other sub-agents.</p>
<p>Think of it like a restaurant where the head chef personally goes to the farm to pick vegetables every time an order comes in. The entire kitchen stops.</p>
<p><strong>Async sub-agents fix this.</strong> Instead of blocking, <code>start_async_task()</code> returns a task ID immediately. The actual work runs on a separate <strong>Agent Protocol</strong> server — different process, possibly different machine. The supervisor continues its loop, works on other things, and polls for results via <code>check_async_task(task_id)</code> when it's ready.</p>
<p>Same head chef analogy — now the chef calls the farm, places the order, and keeps cooking other dishes. When the delivery arrives, the chef incorporates the ingredients.</p>
<blockquote>
<p>💡 <strong>Rule of thumb:</strong> Inline for sub-second to tens-of-seconds work. Async for minutes-plus. Short, focused tasks (classify this input, extract these fields) should stay inline. Long-running research and multi-step pipelines are where async pays off.</p>
</blockquote>
<hr />
<h3>📝 Pillar 4: The Detailed System Prompt</h3>
<p>This one might seem obvious, but it's more nuanced than you think.</p>
<p>Claude Code's system prompts are long. Really long. They contain:</p>
<ul>
<li><p>Detailed instructions on how to use each tool</p>
</li>
<li><p>Few-shot examples for specific situations</p>
</li>
<li><p>Rules about when to plan vs. when to act</p>
</li>
<li><p>Guidelines for verifying work before reporting results</p>
</li>
</ul>
<p>Without these prompts, the agents would not be nearly as deep. <strong>Prompting matters still!</strong></p>
<p>Deep Agents ships with opinionated defaults inspired by Claude Code's prompt structure. These teach the model to:</p>
<ul>
<li><p>Plan before acting</p>
</li>
<li><p>Verify work after completing it</p>
</li>
<li><p>Manage context proactively (write to files, summarize when needed)</p>
</li>
<li><p>Use sub-agents for context isolation</p>
</li>
</ul>
<p>You can extend these with custom instructions or replace them entirely. But the defaults are strong — they encode hard-won lessons about what makes agents actually reliable.</p>
<hr />
<h2>How It All Connects to Context Engineering</h2>
<p>If you've been reading my articles in order, you might be seeing a pattern emerging. Let me make it explicit:</p>
<table>
<thead>
<tr>
<th>Context Engineering Strategy</th>
<th>Deep Agents Implementation</th>
</tr>
</thead>
<tbody><tr>
<td><strong>Compaction / Summarization</strong></td>
<td>Auto-summarization middleware compacts older messages when context grows long</td>
</tr>
<tr>
<td><strong>Context Offloading</strong></td>
<td>Virtual file system — write results to files, read back when needed</td>
</tr>
<tr>
<td><strong>Context Quarantine</strong></td>
<td>Sub-agents with isolated context windows</td>
</tr>
<tr>
<td><strong>Tool Loadout</strong></td>
<td>Skills system — reusable bundles of workflows and domain knowledge</td>
</tr>
</tbody></table>
<p>Deep Agents is essentially <strong>Context Engineering, productized.</strong> Every pillar directly addresses one of the context failure modes I wrote about:</p>
<ul>
<li><p><strong>Context Poisoning</strong> → The plan tool lets the agent self-correct by checking todos against actual progress</p>
</li>
<li><p><strong>Context Distraction</strong> → File system offloads intermediate results so they don't dilute attention</p>
</li>
<li><p><strong>Context Confusion</strong> → Sub-agents quarantine irrelevant context from the main thread</p>
</li>
<li><p><strong>Context Clash</strong> → Permission rules and structured tools prevent conflicting information from accumulating</p>
</li>
</ul>
<p>This is why I got so excited about this library. It's not just another framework. It's context engineering principles turned into reusable infrastructure.</p>
<hr />
<h2>When to Use What — The LangChain Stack</h2>
<p>LangChain now has three tiers. Choosing correctly matters:</p>
<p><strong>LangChain (</strong><code>create_agent</code><strong>)</strong> — For simple agents and standardized team patterns. The tool-calling loop is enough. Think: a customer service bot that looks up order status.</p>
<p><strong>LangGraph</strong> — The low-level runtime. For when you need full control over state, conditional edges, and custom graph topology. Think: a complex approval workflow with branching logic you need to define precisely.</p>
<p><strong>Deep Agents</strong> — For complex, non-deterministic, long-running tasks where you want planning, filesystem, sub-agents, and context compaction out of the box. Think: a research agent that explores a topic for 30 minutes and produces a comprehensive report.</p>
<p>For simple Q&amp;A or single-tool tasks, a basic agent is fine. Deep Agents shine when the task feels more like a <strong>project</strong> than a <strong>question</strong>.</p>
<hr />
<h2>Quick Start — Building Your First Deep Agent</h2>
<p>Here's a minimal but real example using Tavily for web search:</p>
<pre><code class="language-python">import os
from langchain.chat_models import init_chat_model
from langchain_core.tools import tool
from deepagents import create_deep_agent
from tavily import TavilyClient

os.environ["OPENAI_API_KEY"] = "your-key"
os.environ["TAVILY_API_KEY"] = "your-key"

tavily = TavilyClient()

@tool
def web_search(query: str) -&gt; str:
    """Search the web for current information."""
    results = tavily.search(query, max_results=3)
    return "\n".join([r["content"] for r in results["results"]])

model = init_chat_model("openai:gpt-4o")

agent = create_deep_agent(
    model=model,
    tools=[web_search],
    system_prompt="You are a research assistant. Always plan before acting.",
)

result = agent.invoke({
    "messages": [
        {"role": "user", "content": "Research the current state of AI agents in 2025 and write a summary"}
    ]
})
</code></pre>
<p>The agent will automatically:</p>
<ol>
<li><p>Create a plan using <code>write_todos</code></p>
</li>
<li><p>Search the web using your tool</p>
</li>
<li><p>Write intermediate findings to its virtual file system</p>
</li>
<li><p>Synthesize everything into a final summary</p>
</li>
<li><p>Check off todos as it goes</p>
</li>
</ol>
<p>All of that behavior comes from the harness — you didn't code any of it.</p>
<hr />
<h2>Things I Wish Someone Told Me Earlier</h2>
<p>After spending considerable time understanding this library, here are my honest takeaways:</p>
<p><strong>1. The plan tool is psychological, not functional.</strong> Don't expect <code>write_todos</code> to do scheduling. It shapes the model's behavior by making planning explicit in context. That's it. And that's enough.</p>
<p><strong>2. Sub-agents aren't free.</strong> Each spawn is another full LLM call stack. Use them for genuine context isolation, not just to make your architecture look fancy.</p>
<p><strong>3. Model choice changes behavior significantly.</strong> Some models plan well but execute tool calls unreliably. Some are the opposite. Benchmark before committing. Deep Agents is provider-agnostic — try GPT-4o, Claude, Qwen, Llama and compare.</p>
<p><strong>4. The file system is virtual by default.</strong> "Files" live in agent state unless you configure a durable backend. Don't assume writes persist across threads without explicit setup.</p>
<p><strong>5. Prompting still matters. A lot.</strong> The defaults are strong but opinionated toward coding/research work. Domain-specific agents need prompt customization.</p>
<hr />
<blockquote>
<p>Managing context is often the toughest part of creating an agent. Deep Agents doesn't eliminate that challenge — but it gives you principled tools to handle it, so you can focus on building what actually matters.</p>
</blockquote>
<hr />
<h2>Sources</h2>
<ul>
<li><p><a href="https://docs.langchain.com/oss/python/deepagents/overview">LangChain Deep Agents — Official Docs</a></p>
</li>
<li><p><a href="https://blog.langchain.com/deep-agents/">Deep Agents Blog Post — Harrison Chase</a></p>
</li>
<li><p><a href="https://blog.langchain.com/deep-agents-v0-5/">Deep Agents v0.5 Release</a></p>
</li>
<li><p><a href="https://github.com/langchain-ai/deepagents">Deep Agents GitHub Repository</a></p>
</li>
<li><p><a href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents">Anthropic — Effective Context Engineering for AI Agents</a></p>
</li>
<li><p><a href="https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html">How Contexts Fail — Drew Breunig</a></p>
</li>
</ul>
<hr />
<p>#deep-agents #langchain #context-engineering #gen-ai #agents #langgraph</p>
]]></content:encoded></item><item><title><![CDATA[Beyond Prompts: The Rise of Context Engineering]]></title><description><![CDATA[For past few years ‘Prompt Engineering’ has been the center of attention. The focus was centered on crafting the perfect sequence of words and instructions to get a desired response from the model in a single turn or a simple, short-term task.
Howeve...]]></description><link>https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/beyond-prompts-the-rise-of-context-engineering</link><guid isPermaLink="true">https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/beyond-prompts-the-rise-of-context-engineering</guid><category><![CDATA[gen ai]]></category><category><![CDATA[context engineering]]></category><category><![CDATA[#PromptEngineering]]></category><category><![CDATA[Prompt]]></category><category><![CDATA[generative ai]]></category><category><![CDATA[context]]></category><dc:creator><![CDATA[Pritam Chakroborty]]></dc:creator><pubDate>Mon, 24 Nov 2025 14:25:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763993838389/6a936871-c20b-4403-8e42-11f01bc7232b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For past few years ‘Prompt Engineering’ has been the center of attention. The focus was centered on crafting the perfect sequence of words and instructions to get a desired response from the model in a single turn or a simple, short-term task.</p>
<p>However, as the industry matured and moved from simple chat interfaces to building complex, autonomous AI Agents—systems that operate in a loop, use tools, and manage multi-step, long-horizon tasks. We got different engineering problem at hand -</p>
<blockquote>
<p>“what configuration of context is most likely to generate our model’s desired behavior?"</p>
</blockquote>
<p>To make it more simpler - “How can we feed only relevant information in context during LLM inference?”</p>
<p>Now, To get the gist of the problem first we have to understand the term called “<strong><mark>Attention Budget</mark></strong>”.</p>
<p>Despite LLM’s speed and ability to manage larger and larger volumes of data, like humans, LLM’s also lose focus or experience confusion at a certain point. Context, therefore, should be considered a limited resource with decreasing benefits as more is used. Like humans, who have limited working memory capacity, LLMs have an “<strong><mark>Attention Budget</mark></strong>” that they draw on when parsing large volumes of context. Every new token introduced depletes this budget by some amount, increasing the need to carefully curate the tokens available to the LLM.</p>
<p>This attention scarcity is a architectural constraint of LLM’s. Therefore, the need of utilizing the limited context window emerges - A new term called “Context Engineering” comes into the display. As well as a new doubt - <strong><mark>How is context engineering different from prompt engineering?</mark></strong></p>
<p>To answer first that we have to understand what context engineering is -</p>
<p>As Karpathy explains -</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763386831360/81e06fd4-d607-47a3-92bd-ae21ddf08f25.png" alt class="image--center mx-auto" /></p>
<p>Context Engineering VS Prompt Engineering</p>
<p>Prompt engineering refers to methods for writing and organizing LLM instructions for optimal outcomes (see <a target="_blank" href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview">our docs</a> <a target="_blank" href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview">for an o</a>verview and useful prompt engineering strategies).</p>
<p><strong>Context engineering</strong> refers to the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference, including all the other information that may land there outside of the prompts.</p>
<p>As the term implies, the main focus of prompt engineering is on writing effective prompts, especially system prompts. Prompts instruct the model on how to behave and what actions to take. However, to create an interactive system guided by these prompts, your system needs contextual awareness.</p>
<p>Therefore, context is not meant to replace prompts, nor is one better than the other. Both are essential parts of a fully functional agentic system.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763570163413/f932136b-60f5-4916-8b45-63fa0d9b36e9.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-the-need-of-context-engineering"><strong><mark>The need of Context Engineering :-</mark></strong></h2>
<p>Initially we all thought that long enough context window and giving access to tools would be enough for creating a sustainable agentic architecture. As model context windows continue to grow, with many supporting up to 1 million tokens, it might seem like you can include <em>everything</em> you need in a prompt—tools, documents, instructions, and more—and let the model handle it.</p>
<p>However, in reality, longer contexts don't always lead to better responses. Overloading your context can cause your agents and applications to fail in unexpected ways. Contexts can become contaminated, distracting, confusing, or conflicting. This is especially problematic for agents, which rely on context to gather information, synthesize findings, and coordinate actions.</p>
<p>LLMs use the transformer architecture, which allows each token to connect with every other token in the entire context. This creates n² pairwise relationships for n tokens. As the context length increases, the model's ability to manage these relationships becomes strained, leading to a natural conflict between context size and attention focus.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763390734358/f8c0632f-f480-4fe0-b1fc-42a173cec258.jpeg" alt class="image--center mx-auto" /></p>
<p>Here are some of the ways context can get out of hand ——</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Collected from this excellent article by <strong>Drew Breunig</strong></div>
</div>

<h3 id="heading-context-poisoning"><em>Context Poisoning</em></h3>
<p><em>Context Poisoning is when a hallucination or other error makes it into the context, where it is repeatedly referenced.</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763562685038/ce6dd894-4682-4d1e-a719-9f5c944bd259.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-context-distraction"><em>Context Distraction</em></h3>
<p><em>Context Distraction is when a context grows so long that the model over-focuses on the context, neglecting what it learned during training.</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763564502140/cb71602e-bc52-43ff-aa58-506e32303a0c.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-context-confusion"><em>Context Confusion</em></h3>
<p><em>Context Confusion is when superfluous content in the context is used by the model to generate a low-quality response.</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763564611056/c3c6d72c-6f18-4d88-8b52-1d39bc1c8019.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763564709377/0f53cbbf-177b-4f9a-be2c-0d315c9abeaa.png" alt class="image--center mx-auto" /></p>
<p>Here the explanation is: If you put anything on context the model has to pay attention to it, does not matter it is relevant or not. Large models, especially reasoning models, are getting better at ignoring or discarding superfluous context compare to smaller models. But longer context comes with it’s own downside.</p>
<h3 id="heading-context-clash"><em>Context Clash</em></h3>
<p><em>Context Clash is when you accrue new information and tools in your context that conflicts with other information in the context.</em></p>
<p>This is a more problematic version of <em>Context Confusion</em>: the bad context here isn’t irrelevant, it directly conflicts with other information in the prompt.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763565056087/e98bd0bc-05e3-42d7-b8cd-fe8240f41894.png" alt class="image--center mx-auto" /></p>
<p>Here is the explanation of this problem : When you stuffed the model lots of information as context, as an effect it creates confusion. The model gets confused between the information it has in context therefore for each separate question it tries to solve the problem based on assumed facts, but when it has the question with all details in hand it doesn't assume anything just answer based on the information.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763566312495/06af0ba4-fef8-4667-a726-a9386085aa47.png" alt class="image--center mx-auto" /></p>
<p>Therefore even we reach million-token context window and throw all information into that, does not matter how well defined your prompts are due to the architectural constraint LLM will not be able meet desired agentic behavior.</p>
<p>These failures hit agents hardest because agents operate in exactly the scenarios where contexts balloon: gathering information from multiple sources, making sequential tool calls, engaging in multi-turn reasoning, and accumulating extensive histories.</p>
<h2 id="heading-strategies-for-mitigating-context-failure-issues"><mark>Strategies for mitigating context failure issues:-</mark></h2>
<p>Fortunately, There are various solutions available for us to tackle these context failure issues.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">These strategies has been defined in depth in the sources given at the end of the article.</div>
</div>

<ol>
<li><h3 id="heading-compaction-context-summarization"><strong>Compaction / <em>Context Summarization</em></strong></h3>
<p> <em>Context Summarization is the process of condensing a large amount of context into a brief summary.</em></p>
<p> Context Summarization was first used to manage smaller context windows. When your chat session was about to exceed the maximum context length, a summary would be created, and a new thread would start. The skill in compaction is choosing what to keep and what to discard, as being too aggressive can lead to losing subtle but important context that might be needed later.</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763989229910/2a25fb4b-1ae1-4b76-8380-f234dbcd6deb.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763989563083/a3d4d4ba-9742-4a10-a887-54ecdea6d591.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-structured-note-taking-context-offloading"><strong>Structured note-taking / <em>Context Offloading</em></strong></h3>
<p> <em>Context Offloading is the act of storing information outside the LLM’s context, usually via a tool that stores and manages the data. It</em> is a technique where the agent regularly writes notes persisted to memory outside of the context window. These notes get pulled back into the context window at later times.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763990139053/af061026-614a-4543-aebd-0662e26571a7.png" alt class="image--center mx-auto" /></p>
<ol start="3">
<li><h3 id="heading-context-quarantine-sub-agent-architectures"><em>Context Quarantine /</em> <strong>Sub-agent architectures</strong></h3>
<p> <em>Context Quarantine is the act of isolating contexts in their own dedicated threads, each used separately by one or more LLMs.</em></p>
<p> We see better results when our contexts aren’t too long and don’t sport irrelevant content. One way to achieve this is to break our tasks up into smaller, isolated jobs – each with their own context. Rather than one agent attempting to maintain state across an entire project, specialized sub-agents can handle focused tasks with clean context windows. The main agent coordinates with a high-level plan while subagents perform deep technical work or use tools to find relevant information. Each subagent might explore extensively, using tens of thousands of tokens or more, but returns only a condensed, distilled summary of its work (often 1,000-2,000 tokens).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763990884278/71446ff8-4e4a-46bc-a03b-2af5e4372dcc.png" alt class="image--center mx-auto" /></p>
</li>
<li><h3 id="heading-tool-loadout"><em>Tool Loadout</em></h3>
<p> <em>Tool Loadout is the act of selecting only relevant tool definitions to add to your context.</em></p>
<p> In this strategy, We use RAG for selecting the most relevant tools for the model to solve the user query. By storing tool descriptions in a vector database, the model is able to select the most relevant tools given an input prompt.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763991600873/ed30fb5b-e515-47f7-afe4-1494ac2d3a52.png" alt /></p>
<p>Now before moving on we have to know when to use what ,The choice between these approaches depends on task characteristics. For example:</p>
<ul>
<li><p>Compaction maintains conversational flow for tasks requiring extensive back-and-forth;</p>
</li>
<li><p>Note-taking excels for iterative development with clear milestones;</p>
</li>
<li><p>Multi-agent architectures handle complex research and analysis where parallel exploration pays dividends.</p>
</li>
<li><p>Tool-Loadout becomes important in a agentic system with multiple tools.</p>
</li>
</ul>
<hr />
<p>Managing context is often the toughest part of creating an agent.</p>
<p>The important point in all these strategies is that <em>context isn't free</em>. Every token in the context affects how the model behaves, for better or worse. The large context windows of modern LLMs are a strong feature, but they don't justify careless information management.</p>
<p>When you build a new agent or improve an existing one, ask yourself: Is everything in this context necessary? If not, you have these strategies to fix it.</p>
<p>Context engineering isn't just about fitting more information into a prompt—it's about understanding that <strong>every token is a vote of confidence</strong>. When you include irrelevant or conflicting information, you're essentially asking the model to guess which signals matter. That's a losing bet, especially for agents that need to reason reliably across multiple steps and tool calls.</p>
<p>The strategies outlined—compaction, offloading, quarantine, and tool loadout—are all manifestations of the same principle: <strong>intentionality over abundance</strong>. Modern LLMs have unprecedented context windows, but that's a capability, not a mandate. The future of effective AI systems won't belong to those who can cram the most context into a request, but to those who architect context strategically.  </p>
<p><strong><em><mark>Our responsibility as a builder: Question every token. Measure context quality, not just context size. Build agents that fail gracefully when context is corrupted, and succeed reliably when context is clean.</mark></em></strong></p>
<p>As you build or refine your agents, remember: context management is context <em>optimization</em>. Clean context doesn't just reduce token waste—it dramatically improves model reasoning, reduces hallucination, and makes agents genuinely reliable at scale.</p>
<p>The next frontier isn't bigger context windows. It's smarter ones.  </p>
<p>Sources : -</p>
<ol>
<li><p><a target="_blank" href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents">https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents</a></p>
</li>
<li><p><a target="_blank" href="https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html">https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html</a></p>
</li>
<li><p><a target="_blank" href="https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html">https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html</a></p>
</li>
<li><p><a target="_blank" href="https://www.datacamp.com/blog/context-engineering">https://www.datacamp.com/blog/context-engineering</a></p>
</li>
<li><p><a target="_blank" href="https://www.dbreunig.com/2025/07/24/why-the-term-context-engineering-matters.html">https://www.dbreunig.com/2025/07/24/why-the-term-context-engineering-matters.html</a></p>
</li>
<li><p><a target="_blank" href="https://www.anthropic.com/engineering/claude-think-tool">https://www.anthropic.com/engineering/claude-think-tool</a></p>
</li>
<li><p><a target="_blank" href="https://maven.com/p/569540/i-don-t-use-rag-i-just-retrieve-documents?utm_medium=ll_share_link&amp;utm_source=maven">https://maven.com/p/569540/i-don-t-use-rag-i-just-retrieve-documents?utm_medium=ll_share_link&amp;utm_source=maven</a></p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Prompting Techniques: Your Toolkit for Mastering AI Communication]]></title><description><![CDATA[💡
I'm not an expert in this, but I'm an enthusiastic learner of generative artificial intelligence. All the knowledge I share is verified from reliable sources. Please feel free to point out areas of improvement and how I can do better. I'm definite...]]></description><link>https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompting-techniques-your-toolkit-for-mastering-ai-communication</link><guid isPermaLink="true">https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompting-techniques-your-toolkit-for-mastering-ai-communication</guid><category><![CDATA[#PromptEngineering]]></category><category><![CDATA[Prompt]]></category><category><![CDATA[AI Engineering]]></category><category><![CDATA[AI]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[prompting]]></category><dc:creator><![CDATA[Pritam Chakroborty]]></dc:creator><pubDate>Sat, 26 Jul 2025 16:50:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753538080356/725fe7e8-c6b2-4395-8c35-5f03d657789b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">I'm not an expert in this, but I'm an enthusiastic learner of generative artificial intelligence. All the knowledge I share is verified from reliable sources. Please feel free to point out areas of improvement and how I can do better. I'm definitely looking forward to your valuable feedback. Now go ahead….. 😊</div>
</div>

<p><mark>Quick Recap: In Part 1, we looked at how LLMs create responses using settings like temperature, Top-K, and Top-P. Now, we're going to explore the details of prompting techniques that make your prompts work effectively. Ready to improve your skills?</mark></p>
<hr />
<p><em>Part 2: Fundamentals of prompting techniques - that separates good prompts from great ones.</em></p>
<hr />
<p>Remember this picture from Part 1?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750836575623/23063262-05d7-4197-9c61-48b38ec8d6ab.webp?auto=compress,format&amp;format=webp" alt class="image--center mx-auto" /></p>
<p><strong><em><mark>"Well, I'm good with English. So does that mean I'm automatically good at prompt engineering?"</mark></em></strong></p>
<p>Let's find out, shall we?</p>
<p>Here's the thing - being fluent in English is like having a good voice. But knowing prompting techniques? That's like learning how to sing professionally. Both are English, but the results are very different.</p>
<p>To get more clarity, Let’s assume a situation:</p>
<p>Suppose you are asking someone "Can you help me?"</p>
<p>or</p>
<p>You can say "I need guidance on English Project which is on X topic, I have Y number of information on this topic, I need you to guide me on Z ."</p>
<h3 id="heading-see-the-difference-same-language-completely-different-outcomes">See the difference? Same language, completely different outcomes.</h3>
<p><strong><mark>Therefore, it's not just about your English skills, but also about how you frame your question to get the best possible result.</mark></strong></p>
<hr />
<p>Now let's take a deep dive into Prompting techniques.</p>
<h2 id="heading-the-foundation-building-blocks-of-good-prompt">The Foundation: Building blocks of good Prompt</h2>
<p>Before we jump into specific techniques, let's break down what makes a prompt effective. Every great prompt has these core components:</p>
<ul>
<li><p><strong>Context</strong> → What's the situation / story behind the question ?</p>
</li>
<li><p><strong>Task</strong> → What do you want the AI to do?</p>
</li>
<li><p><strong>Format</strong> → How should the output look?</p>
</li>
<li><p><strong>Constraints</strong> → What are the rules/limitations?</p>
</li>
<li><p><strong>Examples</strong> → What does good look like?</p>
</li>
</ul>
<p>Think of it like giving directions to a friend. You wouldn't just say "Go there."</p>
<p>You'd say "Take the main road, turn left at the coffee shop, look for the blue building, and park in the back."</p>
<hr />
<h2 id="heading-technique-1-zero-shot-prompting">Technique #1: Zero-Shot Prompting</h2>
<p>The name <mark>“</mark><strong><em><mark>Zero-Shot”</mark></em></strong> stands for <mark>’no examples’</mark>.</p>
<p>This prompt is the simplest type of prompt. It only provides a description of a task and some text for the LLM to get started with - giving the AI a task without any examples.</p>
<p>The model temperature should be set to a low number, since no creativity is needed,</p>
<p><strong>When to use:</strong> Simple, straightforward tasks where the instructions are clear.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">These code blocks are for visual ease; they are not actual TypeScript code.</div>
</div>

<pre><code class="lang-python">   <span class="hljs-comment"># System prompt to define the task clearly</span>

    system_prompt = <span class="hljs-string">"""
    You are a movie review classifier. Your task is to classify movie reviews into exactly one of these three categories:
    - POSITIVE: Reviews that express overall satisfaction, praise, or recommendation
    - NEUTRAL: Reviews that are balanced, mixed, or indifferent
    - NEGATIVE: Reviews that express overall dissatisfaction, criticism, or disappointment

    Respond with only the classification label: POSITIVE, NEUTRAL, or NEGATIVE.
    """</span>

   <span class="hljs-comment"># User prompt with the specific review</span>
    user_prompt = <span class="hljs-string">f"""
    Classify movie reviews as POSITIVE, NEUTRAL or NEGATIVE.

    Review: "<span class="hljs-subst">{review_text}</span>"

    Sentiment:
    """</span>

    <span class="hljs-keyword">try</span>:
        response = client.chat.completions.create(
            model=<span class="hljs-string">"gpt-4"</span>, 
            messages=[
                {<span class="hljs-string">"role"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"content"</span>: system_prompt},
                {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: user_prompt}
            ],
            temperature=<span class="hljs-number">0.1</span>, 
            max_tokens=<span class="hljs-number">5</span>,   
            top_p=<span class="hljs-number">1.0</span>,       
            frequency_penalty=<span class="hljs-number">0</span>,
            presence_penalty=<span class="hljs-number">0</span>
        )

        result= response.choices[<span class="hljs-number">0</span>].message.content.strip()
        <span class="hljs-keyword">return</span> result

    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        print(<span class="hljs-string">f"Error occurred: <span class="hljs-subst">{e}</span>"</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-string">"ERROR"</span>



Expected Output: POSITIVE
</code></pre>
<p>The AI knows exactly what you want, how long it should be, what tone to use, and what to include.</p>
<p>Even in zero-shot, be as specific as possible - clear, direct, and detailed.</p>
<p>When zero-shot doesn’t work, you can provide demonstrations or examples in the prompt, which leads to “one-shot” and “few-shot” prompting.</p>
<hr />
<h2 id="heading-technique-2-few-shot-prompting">Technique #2: Few-Shot Prompting</h2>
<p>Give the AI examples of what you want, then ask for more of the same. Examples are especially useful when you want to steer the model to a certain output structure or pattern.</p>
<p><mark>A </mark> <strong><em><mark>one-shot prompt</mark></em></strong><mark>, </mark> provides a single example, hence the name one-shot. The idea is the model has an example it can imitate to best complete the task.</p>
<p><strong><em><mark>A few-shot prompt , </mark></em></strong> provides multiple examples to the model. This approach shows the model a pattern that it needs to follow. The idea is similar to one-shot, but multiple examples of the desired pattern increases the chance the model follows the pattern.</p>
<p><strong>When to use:</strong> When you have a specific format, style, or pattern you want to replicate.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># System prompt to define the task clearly</span>
    system_prompt = <span class="hljs-string">"""
    You are a pizza order parser. Your task is to parse customer pizza orders into valid JSON format with this exact structure:
    - "size": can be "small", "medium", "large", or "extra large"
    - "type": can be "normal" (single topping set) or "half-half" (two different topping sets)
    - "ingredients": array of arrays containing ingredients for each half

    For normal pizzas: ingredients should be a single array inside the main array
    For half-half pizzas: ingredients should contain two separate arrays for each half

    Respond with only valid JSON in the specified format.
    """</span>

    <span class="hljs-comment"># User prompt with examples and the specific order</span>
    user_prompt = <span class="hljs-string">f"""
    Parse a customer's pizza order into valid JSON:

    EXAMPLE:
    I want a small pizza with cheese, tomato sauce, and pepperoni.
    JSON Response:</span>
</code></pre>
<p>    {{
    "size": "small",
    "type": "normal",
    "ingredients": [["cheese", "tomato sauce", "pepperoni"]]
    }}</p>
<pre><code>
    <span class="hljs-attr">EXAMPLE</span>:
    Can I get a large pizza <span class="hljs-keyword">with</span> tomato sauce, basil and mozzarella
    {{
    <span class="hljs-string">"size"</span>: <span class="hljs-string">"large"</span>,
    <span class="hljs-string">"type"</span>: <span class="hljs-string">"normal"</span>,
    <span class="hljs-string">"ingredients"</span>: [[<span class="hljs-string">"tomato sauce"</span>, <span class="hljs-string">"basil"</span>, <span class="hljs-string">"mozzarella"</span>]]
    }}

    Now parse <span class="hljs-built_in">this</span> order:
    {order_text}
    <span class="hljs-built_in">JSON</span> Response:
    <span class="hljs-string">""</span><span class="hljs-string">"

    try:
        # Make the API call with settings matching the original configuration
        response = client.chat.completions.create(
            model="</span>gpt<span class="hljs-number">-4</span><span class="hljs-string">",  
            messages=[
                {"</span>role<span class="hljs-string">": "</span>system<span class="hljs-string">", "</span>content<span class="hljs-string">": system_prompt},
                {"</span>role<span class="hljs-string">": "</span>user<span class="hljs-string">", "</span>content<span class="hljs-string">": user_prompt}
            ],
            temperature=0.1, 
            max_tokens=250,   
            top_p=1.0,       
        )

        # Extract and return the parsed JSON
        parsed_order = response.choices[0].message.content.strip()
        return parsed_order

    except Exception as e:
        print(f"</span><span class="hljs-built_in">Error</span> occurred: {e}<span class="hljs-string">")
        return "</span>ERROR<span class="hljs-string">"</span>
</code></pre><pre><code class="lang-json">Input: 

<span class="hljs-string">"Now, I would like a large pizza, with the first half cheese and mozzarella. 
And the other tomato sauce, ham and pineapple."</span>

Expected Output:

{
<span class="hljs-attr">"size"</span>: <span class="hljs-string">"large"</span>,
<span class="hljs-attr">"type"</span>: <span class="hljs-string">"half-half"</span>,
<span class="hljs-attr">"ingredients"</span>: [[<span class="hljs-string">"cheese"</span>, <span class="hljs-string">"mozzarella"</span>], [<span class="hljs-string">"tomato sauce"</span>, <span class="hljs-string">"ham"</span>, <span class="hljs-string">"pineapple"</span>]]
}
</code></pre>
<p>When you choose examples for your prompt, use examples that are relevant to the task you want to perform. The examples should be diverse, of high quality, and well written. One small mistake can confuse the model and will result in undesired output.</p>
<hr />
<h2 id="heading-technique-3-chain-of-thought-cot-prompting">Technique #3: Chain-of-Thought (CoT) Prompting</h2>
<p>Chain of Thought prompting is a technique for improving the reasoning capabilities of LLMs by generating intermediate reasoning steps. This helps the LLM generate more accurate answers.</p>
<p>You can combine it with few-shot prompting to get better results on more complex tasks that require reasoning before responding as it’s a challenge with a zero-shot chain of thought.</p>
<pre><code class="lang-python">user_prompt= <span class="hljs-string">"""
When I was 3 years old, my partner was 3 times my age. Now, I am 20 years old. 
How old is my partner?
 """</span>

Output :  <span class="hljs-number">63</span> years old
</code></pre>
<p>Yikes. That’s obviously the wrong answer. As a matter of fact, LLMs often struggle with mathematical tasks and can provide incorrect answers – even for a task as simple as multiplying two numbers. This is because they are trained on large volumes of text and math may require a different approach.</p>
<p>This is where you combine CoT with few-shot prompting to get better results on more complex tasks that require reasoning before responding as it’s a challenge with a zero-shot chain of thought.</p>
<p>Now let’s see if intermediate reasoning steps will improve the output.</p>
<p>Example of ‘zero-shot’ Chain of thought.</p>
<pre><code class="lang-python">Prompt : 
<span class="hljs-string">""" When I was 3 years old, my partner was 3 times my age. Now, I am 20 years old. 
How old is my partner? Let's think step by step. """</span>

Output : 
<span class="hljs-string">"""
1. Let’s assume my current age is “x” years.
2. When I was 3 years old, my age was 3 years.
3. My partner’s age at that time was 3 times my age, which means my partner’s
age was 3 * 3 = 9 years.
4. Now, I am 20 years old, which means my age has increased by 20 - 3 = 17
years since I was 3 years old.
5. Since my partner’s age was 9 years when I was 3 years old, and my age has
increased by 17 years, my partner’s age must have also increased by 17 years.
6. Therefore, my partner’s current age is 9 + 17 = 26 years.
So, my partner is 26 years old.
"""</span>
</code></pre>
<p>Now the final answer is correct. That’s because we clearly instructed the LLM to explain each step instead of just returning an answer.</p>
<p>Now let’s help the model to think a little bit more by combining it with few shot approach.</p>
<pre><code class="lang-python">Prompt : 
<span class="hljs-string">"""
Q: When my brother was 2 years old, I was double his age. Now
I am 40 years old. How old is my brother? Let's think step
by step.

A: When my brother was 2 years, I was 2 * 2 = 4 years old.
That's an age difference of 2 years and I am older. Now I am 40
years old, so my brother is 40 - 2 = 38 years old. The answer
is 38.

Q: When I was 3 years old, my partner was 3 times my age. Now,
I am 20 years old. How old is my partner? 
Let's think step
by step.

A:
"""</span>
Output :

<span class="hljs-string">""" When I was 3 years old, my partner was 3 * 3 = 9 years old. That’s an age
difference of 6 years and my partner is older. Now I am 20 years old, so my
partner is 20 + 6 = 26 years old. The answer is 26.
"""</span>
</code></pre>
<p>Chain of thought can be useful for various use-cases. Think of code generation, for breaking down the request into a few steps, and mapping those to specific lines of code. Or for creating synthetic data when you have some kind of seed like “The product is called XYZ, write a description guiding the model through the assumptions you would make based on the product given title.” Generally, any task that can be solved by ‘talking through is a good candidate for a chain of thought. If you can explain the steps to solve the problem, try chain of thought.</p>
<p>With this process, you get both the answer AND the reasoning, making it easier to verify accuracy and learn from the process.</p>
<hr />
<h2 id="heading-technique-4-role-based-prompting">Technique #4: Role-Based Prompting</h2>
<p>Role prompting is a technique in prompt engineering that involves assigning a specific role to the gen AI model. This can help the model to generate more relevant and informative output, as the model can craft its responses to the specific role that it has been assigned.</p>
<pre><code class="lang-python">Prompt : <span class="hljs-string">""" I want you to act as a travel guide. I will write to you about
my location and you will suggest 3 places to visit near me in
a humorous style.
My suggestion: "I am in Manhattan."
Travel Suggestions:
"""</span>
Output : <span class="hljs-string">"""
1. Behold the Empire State of Mind: Ascend to the dizzying heights of the Empire
State Building and bask in the glory of Manhattan's skyline. Prepare to feel like
King Kong atop the Big Apple, minus the giant ape-sized banana.

2. Get Artsy-Fartsy at MoMA: Unleash your inner art aficionado at the Museum
of Modern Art (MoMA). Gaze upon masterpieces that will boggle your
mind and make you question whether your stick-figure drawings have any
artistic merit.

3. Shop ‘Til You Drop on Fifth Avenue: Indulge in some retail therapy on the
iconic Fifth Avenue. Brace yourself for sticker shock as you window-shop (or
actually shop) at designer boutiques that will make your wallet cry. But hey,
"""</span>
</code></pre>
<p>Here are some styles you can choose from which I find effective: Confrontational, Descriptive, Direct, Formal, Humorous, Influential, Informal, Inspirational, Persuasive.</p>
<p>In this approach, AI draws from relevant knowledge patterns and adopts the thinking style of that profession.</p>
<hr />
<h2 id="heading-technique-5-step-back-prompting"><strong>Technique #5: Step-Back Prompting</strong></h2>
<p>Step-back prompting is a technique where instead of directly asking the question, first ask a broader or more general question to activate relevant background context. Then, we use that output as context to craft the final prompt. This extra “step back” gives the model more context and insight, ultimately leading to higher-quality, more accurate responses.</p>
<p>This approach helps the model to think more critically and more importantly it helps the model to avoid any of biasness / toxicity. It’s particularly useful for improving performance on complex or abstract prompts, where diving in directly might result in generic or shallow output.</p>
<p>Making the model contextually align with your query is the main goal here.</p>
<pre><code class="lang-python">Prompt : <span class="hljs-string">""" Based on popular first-person shooter action games, what are
5 fictional key settings that contribute to a challenging and
engaging level storyline in a first-person shooter video game?
"""</span>
Output : <span class="hljs-string">"""
1. **Abandoned Military Base**: A post-apocalyptic zone crawling with rogue robots and mutated enemies.
2. **Cyberpunk City**: A neon-lit urban maze filled with cybernetic foes and hacking puzzles.
3. **Alien Spaceship**: A stranded vessel featuring zero gravity combat and alien terror.
4. **Zombie-Infested Town**: Hordes of undead in a decaying town with tight quarters and puzzle challenges.
5. **Underwater Research Facility**: A sunken lab teeming with aquatic monsters and stealth missions.
"""</span>
</code></pre>
<p>Now, instead of jumping into the storyline directly, we include this rich context from the broader step-back question:</p>
<pre><code class="lang-python">Prompt : <span class="hljs-string">"""Context: 5 engaging themes for a first-person shooter video game:
1. Abandoned Military Base
2. Cyberpunk City
3. Alien Spaceship
4. Zombie-Infested Town
5. Underwater Research Facility

Take one of the themes and write a one paragraph storyline for a new level of a first-person shooter video game that is challenging and engaging.
"""</span>
Output : <span class="hljs-string">"""
In the abyss of the Atlantic, an underwater research facility crumbles beneath the weight of forgotten ambition. The player, a battle-hardened marine armed with deep-sea weaponry and razor-sharp instincts, must infiltrate the station to recover lost data—before mutated sea creatures claim it first. With claustrophobic tunnels, power outages, and lurking horrors, survival demands more than just firepower—it demands wit, timing, and a heart unshaken by the deep’s darkest secrets.
"""</span>
</code></pre>
<p>By asking a general question, the model got aligned with relevant concepts and scenarios, making the final result much concise and more aligned with expectations. Step-back prompting leverages the model’s internal knowledge graph more efficiently, and even mitigates bias or irrelevant outputs by anchoring it in core principles.</p>
<p>It’s like you are letting your friend know your break up story before he comment / suggest any stupid idea.</p>
<p>To put simply, You are building the contextual frame (mental frame) before the model respond to your query.</p>
<hr />
<h2 id="heading-technique-6-re-act-prompting-reason-act">Technique #6: Re-Act Prompting (Reason + Act)</h2>
<p>Re-Act (short for <em>Reason and Act</em>) is a powerful prompting framework that allows a language model to alternate between <strong>thinking</strong> and <strong>doing</strong>—just like humans do when they face unfamiliar tasks.</p>
<p>This technique break-downs the process of solving a task into few steps.</p>
<p>Those steps are :</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong><em><mark>Steps</mark></em></strong></td><td><strong><em><mark>Description of the Process</mark></em></strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Thought</strong></td><td>What the model is thinking or trying to figure out?</td></tr>
<tr>
<td><strong>Action</strong></td><td>What action the model is taking: Search[query], Database[query], or Calculate[Problem Statement]</td></tr>
<tr>
<td><strong>Observation</strong></td><td>What did the model get from performing that action?</td></tr>
</tbody>
</table>
</div><p>This loop of <code>Thought → Action → Observation → Thought</code> allows the model to gather fresh information from the outside world and update its internal decision-making process dynamically. It’s particularly useful in agent-based tasks, data retrieval, or solving problems with multiple steps and dependencies.</p>
<pre><code class="lang-python">Prompt : <span class="hljs-string">"""
You are a helpful AI assistant with the ability to find reason logically and use tools like 
web search, calculator, or database to find accurate and up-to-date answers.

Please answer the following query step-by-step while following the format given below.

Use the following structure repeatedly until you find the final answer:

Thought: [What are you thinking or trying to figure out?]  
Action: [What action are you taking: Search[query], Lookup[keyword], or Calculate[expression]]  
Observation: [What did you get from performing the action?]

Once you are confident in the answer, respond with:

Final Answer: [The answer to the user's original question]

---

Question: "Who won the FIFA World Cup in 2022 and what country will host the next tournament?"

Begin:

"""</span>
Output : <span class="hljs-string">"""
Question: "Who won the FIFA World Cup in 2022 and what country will host the next tournament?"

Thought: I need to find out which country won the FIFA World Cup in 2022, and also determine
which country will host the next (2026) World Cup. I will search for both pieces of 
information.

Action: Search["2022 FIFA World Cup winner"]

Observation: Argentina won the 2022 FIFA World Cup, defeating France in the final match.

Thought: Next, I need to find out which country is hosting the 2026 FIFA World Cup.

Action: Search["2026 FIFA World Cup host country"]

Observation: The 2026 FIFA World Cup will be jointly hosted by the United States, Canada, and 
Mexico.

Final Answer: Argentina won the 2022 FIFA World Cup. The 2026 FIFA World Cup will be jointly 
hosted by the United States, Canada, and Mexico.
"""</span>
</code></pre>
<p>In this process of prompting gives the model, the ability to <strong>self-reflect</strong>, <strong>fetch external knowledge</strong>, and <strong>update its path dynamically</strong>—making it an ideal approach for real-world applications like virtual agents, data scraping, or tools-based reasoning.</p>
<hr />
<p>And trust me that’s not all there are lots of other prompting methods as well.<br />I’ll mention some of them below:</p>
<ul>
<li><p>Trees of Thought (ToT)</p>
</li>
<li><p>Contextual Prompting</p>
</li>
<li><p>Automatic Prompt Engineering</p>
</li>
<li><p>Self-consistency ….. etc.  </p>
<p>  Incase you want to get more details on these techniques, I have mentioned sources</p>
</li>
</ul>
<hr />
<h2 id="heading-best-practices">Best Practices</h2>
<ul>
<li><p>The most important best practice is to provide (one shot / few shot) examples within a prompt. This is highly effective because it acts as a powerful teaching tool.</p>
</li>
<li><p>Prompts should be concise, clear, and easy to understand for both you and the model. As a rule of thumb, if it’s already confusing for you it will likely be also confusing for the model. Try not to use complex language and don’t provide unnecessary information.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753539828000/50553729-fca8-455e-8f5a-f4ccfd549639.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Be specific about the desired output. A concise instruction might not guide the LLM enough or could be too generic.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753539923371/fec14383-6121-49ce-8bf9-9bf0da7a85ff.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Use Instructions over Constraints.</p>
<ul>
<li><p>An instruction provides explicit instructions on the desired format, style, or content of the response. It guides the model on what the model should do or produce.</p>
</li>
<li><p>A constraint is a set of limitations or boundaries on the response. It limits what the model should not do or avoid.</p>
<p>  Just like human , LLM also prefers positive instruction over constraints means what not to do. Because it leaves the model guessing what else is allowed and it may result in hallucination.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753540272113/7278a299-d54c-4eab-aa03-69ea3044822c.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p>Try using verbs that describe the action. Here’s a set of examples: Act, Analyze, Categorize, Classify, Contrast, Compare, Create, Describe, Define, Evaluate, Extract, Find, Generate, Identify, List, Measure, Organize, Parse, Pick, Predict, Provide, Rank, Recommend, Return, Retrieve, Rewrite, Select, Show, Sort, Summarize, Translate, Write.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Prompt Engineering is an evolving field. And it will take sometime for us to get the hold of it.<br />Therefore, Keep experimenting with your prompt and another important suggestion, I received is that you should document your <mark>‘</mark><strong><em><mark>Prompt History</mark></em></strong><mark>‘</mark> means your question and the response you got from the model.<br />Keeping track of your prompt helps you to refine your prompts and tweak the model response into a desired one.</p>
<p>Here is one demo template :</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753541174961/bb7857cb-ce11-441d-9c17-3b5781b3c9d1.png" alt class="image--center mx-auto" /></p>
<p>That's all for this article, and this marks the end of my Prompt Engineering Series. In case you missed it, there is another article on this topic - <a target="_blank" href="https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompt-engineering-the-art-of-effective-ai-communication">Part One.</a></p>
<p>This is Part Two of the series, where I have tried to put together all my learnings on prompt engineering.</p>
<p>Here are some sources of my knowledge:</p>
<ol>
<li><p><a target="_blank" href="https://drive.google.com/file/d/1AbaBYbEa_EbPelsT40-vj64L-2IwUJHy/view">https://drive.google.com/file/d/1AbaBYbEa_EbPelsT40-vj64L-2IwUJHy/view</a></p>
</li>
<li><p><a target="_blank" href="https://arxiv.org/pdf/1706.03762">https://arxiv.org/pdf/1706.03762</a></p>
</li>
</ol>
<hr />
]]></content:encoded></item><item><title><![CDATA[Prompt Engineering: The Art of Effective AI Communication]]></title><description><![CDATA[💡
I'm not an expert in this, but I'm an enthusiastic learner of generative artificial intelligence. All the knowledge I share is verified from reliable sources. Please feel free to point out areas for improvement and how I can do better. I'm definit...]]></description><link>https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompt-engineering-the-art-of-effective-ai-communication</link><guid isPermaLink="true">https://prompt-engineering-effective-way-to-communicate-with-ai.hashnode.dev/prompt-engineering-the-art-of-effective-ai-communication</guid><category><![CDATA[Prompt Engineering]]></category><category><![CDATA[Prompt]]></category><category><![CDATA[AI]]></category><category><![CDATA[generative ai]]></category><category><![CDATA[gen ai]]></category><dc:creator><![CDATA[Pritam Chakroborty]]></dc:creator><pubDate>Wed, 25 Jun 2025 10:05:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1750841840653/6d72a46b-0ad9-48a2-b793-c3911024c719.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">I'm not an expert in this, but I'm an enthusiastic learner of generative artificial intelligence. All the knowledge I share is verified from reliable sources. Please feel free to point out areas for improvement and how I can do better. I'm definitely looking forward to your valuable feedback. Now go ahead….. 😊</div>
</div>

<h1 id="heading-why-the-most-criticized-ai-skill-might-be-the-most-valuable-one-youll-learn">Why the most criticized AI skill might be the most valuable one you'll learn.</h1>
<p>You must have seen pictures like this. It’s all over the internet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750746486551/788fcebb-c055-4ab0-a322-c3be73779993.jpeg" alt class="image--center mx-auto" /></p>
<p>Haha😉, the hate is real.<br />I also hated this term until I understood it better.</p>
<p>I'm not here to convince you to change your mind about "Prompt Engineering."</p>
<p>Instead, I'll leave that decision to you. But I do suggest that before making a final judgment, we should at least try to understand <strong><em>what “Prompt Engineering” is.</em></strong></p>
<p>So, let's give it a try, shall we?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750747433004/a769e720-8220-4f54-be44-66aa3f1f5335.jpeg" alt class="image--center mx-auto" /></p>
<p>Does this tweet make any sense to you? If not, that’s completely fine because trust me, after reading this article, you will have a clear picture of why someone said so.</p>
<p>Before we jump into the topic, let me answer some of the hottest questions on the internet.</p>
<p><strong><em>Is Prompt Engineering only a software developer thing?</em></strong></p>
<p><strong><em>I am a physician/doctor/graphic designer/painter/businessman/creative writer/architect … (list goes on). Should I learn prompt engineering?</em></strong></p>
<p>— My thoughts on these questions —→ No, Prompt Engineering is not only for Software Developers. It’s a universal skill for anyone willing to skill up in their respective domain using the advantage of LLMs. And let me tell you, using AI in your domain is not a typical big NO NO anymore. Whether you are a doctor looking for a precise medical query or a graphic designer trying to get creative inspiration, or a singer looking for the tune that matches your rhythm, knowing how to communicate to get the best out of these language models amplifies your expertise.</p>
<p>Think of it as learning a new language that turns AI into a powerful assistant in your field. Investing time in learning prompt engineering benefits you in the long run, no matter your profession.</p>
<p>Now, with a positive attitude, let's move forward.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750749161015/6166b8b5-20af-4815-b51e-73888b70d69e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-what-is-a-prompt">What is a prompt?</h2>
<ul>
<li>A prompt is simply an instruction or a question you give to an LLM to get it to do something for you. A prompt can be a single word, a sentence, or even a detailed paragraph, depending on what you're trying to accomplish.</li>
</ul>
<h2 id="heading-now-what-is-prompt-engineering"><strong>Now, what is Prompt Engineering?</strong></h2>
<ul>
<li>Prompt engineering is the process of designing high-quality prompts that guide LLMs to produce accurate outputs.</li>
</ul>
<p>When you write a prompt, you are attempting to set up the LLM to predict the right sequence of tokens.</p>
<p>You don’t need to be a data scientist or a machine learning engineer – everyone can write a prompt. However, writing a prompt that suits your requirements can be tricky. Because it depends on multiple factors like - Model Configuration, your requirements, choice of words, tune of words, examples (if there are any), structure of the question, context of the question, etc.</p>
<p>An ambiguous question will result in an ambiguous answer. As simple as that. If you ask a question that already sounds confusing to you, most probably it will confuse LLM models too and will result in hallucination.</p>
<p>As I said, it’s more than the hate we see on the internet.</p>
<p>In a recent speech at YC AI Startup School, <a target="_blank" href="https://x.com/karpathy">Andrej Karpathy</a> discussed the psychology of LLMs. — He characterizes LLMs as "fallible savants" with unique cognitive quirks. They can be superhuman at some tasks but make mistakes that no human will make. He said LLMs are like a patient who is diagnosed with Anterograde Amnesia, which means they can't form new long-term memories within a conversation beyond their context window.</p>
<p>So now it is fair to say that it is certainly not any other buzzword, but a universal skill to move forward.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">In this article, we will discuss how to adjust and modify LLM outputs based on our needs.</div>
</div>

<h1 id="heading-some-jargon-to-define-llms-output">Some Jargon to Define LLMs’ Output</h1>
<hr />
<ol>
<li><h1 id="heading-output-length"><strong>Output Length</strong></h1>
</li>
</ol>
<p>Although it seems straightforward, many people find it confusing. It simply refers to how many tokens the model should use in its response. It doesn't guarantee the quality of the response, just the length.</p>
<p>Keep in mind: a long response means using many tokens, which means LLMs use more computing power, making the response more expensive.<br />A shorter response uses fewer tokens, so LLMs use less computing power, making the response less expensive.</p>
<blockquote>
<p>Reducing the output length of the LLM doesn’t cause the LLM to become more stylistically or textually succinct in the output it creates, it just causes the LLM to stop predicting more tokens once the limit is reached.</p>
</blockquote>
<hr />
<ol start="2">
<li><h1 id="heading-sampling-control-its-the-settings-that-define-how-the-next-token-will-be-chosen"><strong>Sampling Control ( It’s the settings that define how the next token will be chosen )</strong></h1>
</li>
</ol>
<p>Language Models do not predict any single token; it’s just predict the probability of what the next token could be in LLM’s vocabulary. Given a list of probabilities, now it’s up to the <strong><em>Sampling Control</em></strong> settings that determine how these probabilities are used to choose one output token.</p>
<h2 id="heading-some-of-the-most-common-sampling-control-configurations">Some of the most common sampling control configurations ——</h2>
<h2 id="heading-2a-temperature-creativity-control-room"><mark>2a. Temperature: Creativity Control Room</mark></h2>
<ul>
<li><strong>Temperature</strong> — (You may think I know this one, I know this one, this is classic. No, it’s not what you may have convinced yourself to think.) <strong><em>Temperature</em></strong> simply defines how much creativity/risk LLM should consider with word choices.</li>
</ul>
<h3 id="heading-how-it-works-the-pizza-restaurant-analogy">How It Works: The Pizza Restaurant Analogy</h3>
<p>Imagine you're at a pizza restaurant and the waiter asks what you want. The menu shows popularity ratings:</p>
<ul>
<li><p><strong>Margherita Pizza</strong>: 45% of customers order this</p>
</li>
<li><p><strong>Pepperoni Pizza</strong>: 30% of customers order this</p>
</li>
<li><p><strong>Hawaiian Pizza</strong>: 15% of customers order this</p>
</li>
<li><p><strong>Veggie Supreme</strong>: 8% of customers order this</p>
</li>
<li><p><strong>Anchovy Special</strong>: 2% of customers order this</p>
</li>
</ul>
<p>Temperature controls how much you stick to popular choices vs. trying something different.</p>
<h3 id="heading-lets-take-another-example">Let’s take another example :</h3>
<h3 id="heading-the-cat-walked-into-the-room-and-saw-a"><strong>—— " <mark>The cat walked into the room and saw a...</mark>"</strong></h3>
<h3 id="heading-now-lets-use-this-sentence-to-see-how-different-sampling-control-settings-affect-the-llms-word-choices">Now, let's use this sentence to see how different 'Sampling Control' settings affect the LLM's word choices.</h3>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">These code blocks are for visual ease; they are not actual TypeScript code.</div>
</div>

<pre><code class="lang-typescript">The LLMs internal probability distribution might look like:

<span class="hljs-string">"mouse"</span> (<span class="hljs-number">35</span>%)
<span class="hljs-string">"ball"</span> (<span class="hljs-number">20</span>%)
<span class="hljs-string">"person"</span> (<span class="hljs-number">18</span>%)
<span class="hljs-string">"toy"</span> (<span class="hljs-number">12</span>%)
<span class="hljs-string">"shadow"</span> (<span class="hljs-number">8</span>%)
<span class="hljs-string">"ghost"</span> (<span class="hljs-number">4</span>%)
<span class="hljs-string">"unicorn"</span> (<span class="hljs-number">2</span>%)
<span class="hljs-string">"spaceship"</span> (<span class="hljs-number">1</span>%)
</code></pre>
<p>Now let's see how different temperature settings affect the output:</p>
<h3 id="heading-temperature-0-greedy-decoding">Temperature = 0 (Greedy Decoding)</h3>
<p><strong>Behavior:</strong> Always picks the highest probability word, no exceptions.</p>
<pre><code class="lang-typescript">Output: <span class="hljs-string">"The cat walked into the room and saw a mouse."</span> 
Every single time: <span class="hljs-string">"mouse"</span> (because it has <span class="hljs-number">35</span>% probability - the highest)

Why use <span class="hljs-built_in">this</span>:

<span class="hljs-built_in">Math</span> problems: <span class="hljs-string">"2 + 2 = 4"</span> (not <span class="hljs-string">"2 + 2 = purple"</span>)
Code generation: Variable names should be consistent
Factual questions: <span class="hljs-string">"Paris is the capital of France"</span> (not <span class="hljs-string">"Paris is the capital of pizza"</span>)
</code></pre>
<h3 id="heading-temperature-02-very-low">Temperature = 0.2 (Very Low)</h3>
<p><strong>Behavior:</strong> Heavily favors high-probability words, but allows tiny variations.</p>
<pre><code class="lang-typescript">Possible outputs:

<span class="hljs-string">"The cat walked into the room and saw a mouse."</span> (<span class="hljs-number">90</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a ball."</span> (<span class="hljs-number">8</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a person."</span> (<span class="hljs-number">2</span>% <span class="hljs-keyword">of</span> the time)

Why use <span class="hljs-built_in">this</span>:

Professional emails: Consistent tone, occasional word variety
Technical documentation: Clear but not robotic
Customer service responses: Reliable but slightly personalized
</code></pre>
<h3 id="heading-temperature-05-low-medium">Temperature = 0.5 (Low-Medium)</h3>
<p><strong>Behaviour</strong>: Still prefers likely words but gives reasonable alternatives a fair chance.</p>
<pre><code class="lang-typescript">Possible outputs:

<span class="hljs-string">"The cat walked into the room and saw a mouse."</span> (<span class="hljs-number">50</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a ball."</span> (<span class="hljs-number">25</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a person."</span> (<span class="hljs-number">20</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a toy."</span> (<span class="hljs-number">5</span>% <span class="hljs-keyword">of</span> the time)

Why use <span class="hljs-built_in">this</span>:

Blog writing: Natural variety without being weird
Conversational AI: Engaging but predictable
Content creation: Fresh but coherent
</code></pre>
<h3 id="heading-temperature-08-medium-high">Temperature = 0.8 (Medium-High)</h3>
<p><strong>Behavior:</strong> Good balance - explores less likely options while staying sensible.</p>
<pre><code class="lang-typescript">Possible outputs:

<span class="hljs-string">"The cat walked into the room and saw a mouse."</span> (<span class="hljs-number">25</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a ball."</span> (<span class="hljs-number">20</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a person."</span> (<span class="hljs-number">20</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a toy."</span> (<span class="hljs-number">15</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a shadow."</span> (<span class="hljs-number">12</span>% <span class="hljs-keyword">of</span> the time)
<span class="hljs-string">"The cat walked into the room and saw a ghost."</span> (<span class="hljs-number">8</span>% <span class="hljs-keyword">of</span> the time)

Why use <span class="hljs-built_in">this</span>:

Creative writing: Interesting but logical
Story generation: Surprising but believable plot points
Dialogue writing: Natural human-like conversation
</code></pre>
<h3 id="heading-temperature-12-high">Temperature = 1.2 (High)</h3>
<p><strong>Behavior:</strong> Much more willing to pick unusual options, probability differences matter less.</p>
<pre><code class="lang-typescript">Possible outputs:

<span class="hljs-string">"The cat walked into the room and saw a unicorn."</span>
<span class="hljs-string">"The cat walked into the room and saw a spaceship."</span>
<span class="hljs-string">"The cat walked into the room and saw a mouse wearing a tiny hat."</span>
<span class="hljs-string">"The cat walked into the room and saw a portal to another dimension."</span>
<span class="hljs-string">"The cat walked into the room and saw a philosophical debate."</span>

Why use <span class="hljs-built_in">this</span>:

Brainstorming: Need completely unexpected ideas
Surreal creative writing: Fantasy, sci-fi, experimental fiction
Idea generation: Breaking out <span class="hljs-keyword">of</span> conventional thinking
</code></pre>
<h3 id="heading-temperature-20-very-high">Temperature = 2.0+ (Very High)</h3>
<p><strong>Behavior:</strong> Almost random - all words become nearly equally likely.</p>
<pre><code class="lang-typescript">Possible outputs:

<span class="hljs-string">"The cat walked into the room and saw a refrigerator singing opera."</span>
<span class="hljs-string">"The cat walked into the room and saw a mathematics of purple seventeen."</span>
<span class="hljs-string">"The cat walked into the room and saw a democracy flavored with nostalgia."</span>

Why use <span class="hljs-built_in">this</span>:

Abstract art generation
Surreal poetry
Random idea sparks (though often nonsensical)
</code></pre>
<hr />
<h2 id="heading-2b-top-k-limiting-the-menu"><mark>2b. Top-K: Limiting the Menu</mark></h2>
<p><strong>What it does:</strong> Only considers the K most likely words, ignoring the rest.</p>
<pre><code class="lang-typescript">Top-K = <span class="hljs-number">1</span>

Available choices: Only <span class="hljs-string">"mouse"</span> (the single highest probability word)
Output: <span class="hljs-string">"The cat walked into the room and saw a mouse."</span> (always exactly the same)

Why use <span class="hljs-built_in">this</span>: When you need <span class="hljs-number">100</span>% predictable results. Same <span class="hljs-keyword">as</span> setting temperature to <span class="hljs-number">0.</span>

Top-K = <span class="hljs-number">3</span>

Available choices: <span class="hljs-string">"mouse,"</span> <span class="hljs-string">"ball,"</span> <span class="hljs-string">"person"</span> (top <span class="hljs-number">3</span> most likely)

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a mouse."</span>
<span class="hljs-string">"The cat walked into the room and saw a ball."</span>
<span class="hljs-string">"The cat walked into the room and saw a person."</span>

Why use <span class="hljs-built_in">this</span>: Very controlled creativity - safe options only.

Top-K = <span class="hljs-number">6</span>

Available choices: <span class="hljs-string">"mouse,"</span> <span class="hljs-string">"ball,"</span> <span class="hljs-string">"person,"</span> <span class="hljs-string">"toy,"</span> <span class="hljs-string">"shadow,"</span> <span class="hljs-string">"ghost"</span> (top <span class="hljs-number">6</span>)

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a shadow."</span>
<span class="hljs-string">"The cat walked into the room and saw a ghost."</span>
(Plus all previous options)

Why use <span class="hljs-built_in">this</span>: Moderate creativity - includes some interesting but reasonable choices.

Top-K = <span class="hljs-number">50</span>

Available choices: All <span class="hljs-number">8</span> words <span class="hljs-keyword">from</span> our list, plus <span class="hljs-number">42</span> other possible words like <span class="hljs-string">"butterfly,"</span> <span class="hljs-string">"mirror,"</span> 
<span class="hljs-string">"photograph,"</span> <span class="hljs-string">"rainbow,"</span> <span class="hljs-string">"telephone,"</span> etc.

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a butterfly."</span>
<span class="hljs-string">"The cat walked into the room and saw a mysterious photograph."</span>
<span class="hljs-string">"The cat walked into the room and saw a ringing telephone."</span>

Why use <span class="hljs-built_in">this</span>: High creativity - many unexpected but sensible possibilities.
</code></pre>
<hr />
<h2 id="heading-2c-top-p-nucleus-sampling-the-probability-threshold"><mark>2c. Top-P (Nucleus Sampling): The Probability Threshold</mark></h2>
<p><strong>What it does:</strong> Includes words until their combined probability reaches P, then stops.</p>
<pre><code class="lang-typescript">Top-P = <span class="hljs-number">0.5</span> (<span class="hljs-number">50</span>% threshold)
Process: Keep adding words until we hit <span class="hljs-number">50</span>% total probability

<span class="hljs-string">"mouse"</span> (<span class="hljs-number">35</span>%) → Running total: <span class="hljs-number">35</span>%
<span class="hljs-string">"ball"</span> (<span class="hljs-number">20</span>%) → Running total: <span class="hljs-number">55</span>% ← STOP! We passed <span class="hljs-number">50</span>%

Available choices: Only <span class="hljs-string">"mouse"</span> and <span class="hljs-string">"ball"</span>

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a mouse."</span>
<span class="hljs-string">"The cat walked into the room and saw a ball."</span>

Why use <span class="hljs-built_in">this</span>: Very safe, predictable outputs. Good <span class="hljs-keyword">for</span> professional writing where you can not afford weird
 word choices.
---------------------------------------------------------------------------------------------------------
Top-P = <span class="hljs-number">0.75</span> (<span class="hljs-number">75</span>% threshold)
Process: Keep adding until <span class="hljs-number">75</span>%

<span class="hljs-string">"mouse"</span> (<span class="hljs-number">35</span>%) → <span class="hljs-number">35</span>%
<span class="hljs-string">"ball"</span> (<span class="hljs-number">20</span>%) → <span class="hljs-number">55</span>%
<span class="hljs-string">"person"</span> (<span class="hljs-number">18</span>%) → <span class="hljs-number">73</span>%
<span class="hljs-string">"toy"</span> (<span class="hljs-number">12</span>%) → <span class="hljs-number">85</span>% ← STOP! We passed <span class="hljs-number">75</span>%

Available choices: <span class="hljs-string">"mouse,"</span> <span class="hljs-string">"ball,"</span> <span class="hljs-string">"person,"</span> <span class="hljs-string">"toy"</span>

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a mouse."</span>
<span class="hljs-string">"The cat walked into the room and saw a person."</span>
<span class="hljs-string">"The cat walked into the room and saw a toy."</span>

Why use <span class="hljs-built_in">this</span>: Good balance - includes reasonable alternatives <span class="hljs-keyword">while</span> filtering out the weird stuff.
---------------------------------------------------------------------------------------------------------
Top-P = <span class="hljs-number">0.95</span> (<span class="hljs-number">95</span>% threshold)
Process: Keep adding until <span class="hljs-number">95</span>%

<span class="hljs-string">"mouse"</span> (<span class="hljs-number">35</span>%) → <span class="hljs-number">35</span>%
<span class="hljs-string">"ball"</span> (<span class="hljs-number">20</span>%) → <span class="hljs-number">55</span>%
<span class="hljs-string">"person"</span> (<span class="hljs-number">18</span>%) → <span class="hljs-number">73</span>%
<span class="hljs-string">"toy"</span> (<span class="hljs-number">12</span>%) → <span class="hljs-number">85</span>%
<span class="hljs-string">"shadow"</span> (<span class="hljs-number">8</span>%) → <span class="hljs-number">93</span>%
<span class="hljs-string">"ghost"</span> (<span class="hljs-number">4</span>%) → <span class="hljs-number">97</span>% ← STOP! We passed <span class="hljs-number">95</span>%

Available choices: <span class="hljs-string">"mouse,"</span> <span class="hljs-string">"ball,"</span> <span class="hljs-string">"person,"</span> <span class="hljs-string">"toy,"</span> <span class="hljs-string">"shadow,"</span> <span class="hljs-string">"ghost"</span>

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a shadow."</span>
<span class="hljs-string">"The cat walked into the room and saw a ghost."</span>
(Plus all the previous options)

Why use <span class="hljs-built_in">this</span>: Most common setting - gives creativity <span class="hljs-keyword">while</span> avoiding the really bizarre choices like <span class="hljs-string">"unicorn"</span> and
<span class="hljs-string">"spaceship."</span>
---------------------------------------------------------------------------------------------------------
Top-P = <span class="hljs-number">1.0</span> (<span class="hljs-number">100</span>% threshold)
Process: Include everything, no matter how unlikely
Available choices: Every single word, including <span class="hljs-string">"unicorn"</span> and <span class="hljs-string">"spaceship"</span>

Possible outputs:
<span class="hljs-string">"The cat walked into the room and saw a unicorn."</span>
<span class="hljs-string">"The cat walked into the room and saw a spaceship."</span>
<span class="hljs-string">"The cat walked into the room and saw a philosophical debate."</span>

Why use <span class="hljs-built_in">this</span>: Maximum creativity, but risk <span class="hljs-keyword">of</span> nonsensical results.
</code></pre>
<hr />
<p>The best way to choose between top-K and top-P is to experiment with both methods (or both together) and see which one produces the results you are looking for.</p>
<p><strong>Now that we have the whole picture of how LLMs determine the possible token, it becomes really important to know that we use all these configurations together while forming a prompt, because the end goal here is being able to write an appropriate prompt based on our requirements.</strong></p>
<h2 id="heading-so-how-do-they-work-together">So, how do They Work Together:-</h2>
<p>The AI applies these filters in sequence:</p>
<ol>
<li><p><strong>First,</strong> apply Top-K and Top-P filters to create a shortlist</p>
</li>
<li><p><strong>Then,</strong> use temperature to sample from that shortlist</p>
</li>
</ol>
<h3 id="heading-example">Example:</h3>
<pre><code class="lang-typescript">Settings: Temperature=<span class="hljs-number">0.7</span>, Top-K=<span class="hljs-number">10</span>, Top-P=<span class="hljs-number">0.8</span>

For <span class="hljs-string">"Write a story about a dragon who..."</span>:

Top-K limits to <span class="hljs-number">10</span> most likely next words: <span class="hljs-string">"lived,"</span> <span class="hljs-string">"flew,"</span> <span class="hljs-string">"breathed,"</span> <span class="hljs-string">"loved,"</span> <span class="hljs-string">"feared,"</span> <span class="hljs-string">"discovered,"</span> <span class="hljs-string">"lost,"</span>
 <span class="hljs-string">"wanted,"</span> <span class="hljs-string">"dreamed,"</span> <span class="hljs-string">"fought"</span>

Top-P removes words until cumulative probability ≤ <span class="hljs-number">80</span>%: keeps <span class="hljs-string">"lived,"</span> <span class="hljs-string">"flew,"</span> <span class="hljs-string">"breathed,"</span> <span class="hljs-string">"loved,"</span> <span class="hljs-string">"feared"</span>

Temperature=<span class="hljs-number">0.7</span> samples <span class="hljs-keyword">from</span> these <span class="hljs-number">5</span> options <span class="hljs-keyword">with</span> moderate randomness

Result: <span class="hljs-string">"Write a story about a dragon who feared the dark."</span>
</code></pre>
<hr />
<h2 id="heading-common-problems-and-solutions">Common Problems and Solutions</h2>
<h3 id="heading-the-repetition-loop-bug">The "Repetition Loop Bug"</h3>
<p><strong>Problem:</strong> AI gets stuck repeating the same phrases over and over.</p>
<p><strong>Example of bad output:</strong> "The solution is simple, the solution is simple, the solution is simple, the solution is..."</p>
<p><strong>Why does it happen?</strong></p>
<ul>
<li><p><strong>Low temperature:</strong> AI becomes too rigid, follows the same probability path</p>
</li>
<li><p><strong>High temperature:</strong> Random choices accidentally cycle back to the previous text</p>
</li>
</ul>
<p><strong>Solution:</strong> Adjust temperature to 0.3-0.7 range and use Top-P around 0.9-0.95</p>
<h3 id="heading-extreme-settings-cancel-each-other-out">Extreme Settings Cancel Each Other Out</h3>
<p><strong>Temperature = 0:</strong> Makes Top-K and Top-P irrelevant (always picks the most probable)</p>
<p><strong>Top-K = 1:</strong> Makes temperature irrelevant (only one choice available)</p>
<p><strong>Top-P = 0:</strong> Makes other settings irrelevant (only the most probable word allowed)</p>
<h2 id="heading-quick-reference">Quick Reference</h2>
<p>Here is a table of different use case scenarios with various sampling control configurations.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Task Type</td><td>Temperature</td><td>Top-P</td><td>Top-K</td><td>Example Use</td></tr>
</thead>
<tbody>
<tr>
<td>Math/Code</td><td>0</td><td>0.9</td><td>20</td><td>"What is 2+2?"</td></tr>
<tr>
<td>Technical Writing</td><td>0.1-0.2</td><td>0.9</td><td>20</td><td>API documentation</td></tr>
<tr>
<td>Business Writing</td><td>0.2-0.5</td><td>0.95</td><td>30</td><td>Professional emails</td></tr>
<tr>
<td>Creative Writing</td><td>0.7-0.9</td><td>0.99</td><td>40</td><td>Short stories</td></tr>
<tr>
<td>Brainstorming</td><td>0.8-1.0</td><td>0.99</td><td>50</td><td>Idea generation</td></tr>
</tbody>
</table>
</div><h2 id="heading-conclusion"><strong>Conclusion: -</strong></h2>
<p>So far, we have seen how to tweak LLM’s output based on your needs through Sampling control configurations. Also discussed some problems and their solutions. Understanding temperature, Top-K, and Top-P settings allows you to fine-tune creativity versus consistency based on your specific needs.</p>
<p>Therefore, the question isn't whether prompt engineering is "real" or just hype. The question is: Are you ready to harness the full potential of AI tools in your field?</p>
<hr />
<p>Haha 😒 Did you forget that at the start of this article I showed you a tweet saying——</p>
<blockquote>
<p>The hottest new programming language is ‘English‘.</p>
<p>- Andrej Karpathy</p>
</blockquote>
<p>Now, in the whole article, have you seen anything related to any particular field? No, right. As I said, it is universal.</p>
<p>Isn't it amazing that we can communicate with these incredibly smart language models using just plain, structured English?</p>
<p>We can use English to communicate with LLMs and build applications, businesses, solve our problems, demystify ongoing challenges, and create exciting new opportunities. In the very near future ( Within the next 6 months ), the whole industry will be driven by an agentic AI ecosystem, where your prompts become your intellectual asset of the business. Therefore, it is extremely important to know how we craft our intellectual assets.</p>
<p>And all these are in Simple English, but strategically crafted for specific use cases.</p>
<p>I mean, it’s mind-boggling, right?</p>
<p>See this article to get more insights: <a target="_blank" href="https://www.geekwire.com/2025/takeaways-from-the-ai-engineer-worlds-fair-the-startup-playbook-is-being-rewritten-in-real-time/">Takeaways from the AI Engineer World's Fair: The startup playbook is being rewritten in real-time – GeekWire</a> (It’s not about prompt engineering)</p>
<hr />
<h2 id="heading-now-you-may-assume-that-well-im-good-with-english-so-does-that-mean">Now, you may assume that, well, I’m good with English. So does that mean —</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750836575623/23063262-05d7-4197-9c61-48b38ec8d6ab.webp" alt class="image--center mx-auto" /></p>
<p>Well, we will see……</p>
<p>In my next article, we will continue from here onwards, where I’ll write about various prompting techniques.</p>
<p>Feedbacks are appreciated.</p>
<details><summary>AI-Generated Summary</summary><div data-type="detailsContent">Prompt engineering is a legitimate universal skill, not just hype—it's the art of designing effective instructions for AI language models to get optimal results. The article explains that it's valuable for all professionals, not just developers, as it amplifies expertise across any field. Key technical concepts include Temperature (creativity control from 0-2.0), Top-K (limiting word choices), and Top-P (probability thresholds) that work together to fine-tune AI responses. The author provides practical configuration settings for different tasks: low temperature (0-0.2) for factual work, medium (0.5-0.7) for professional writing, and high (0.8+) for creative tasks. Common problems like repetition loops can be solved by adjusting these parameters appropriately. Clear, specific prompts prevent ambiguous outputs since LLMs are like "patients with amnesia" who need comprehensive context. The conclusion emphasizes that prompt engineering will become as fundamental as typing, essential for anyone wanting to effectively collaborate with AI tools in their profession.</div></details>]]></content:encoded></item></channel></rss>