<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shaheryar Yousaf</title>
    <description>The latest articles on DEV Community by Shaheryar Yousaf (@shaheryaryousaf).</description>
    <link>https://dev.to/shaheryaryousaf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F503709%2Fee2c0b62-3928-4a95-8dc2-445fce9c6c55.jpeg</url>
      <title>DEV Community: Shaheryar Yousaf</title>
      <link>https://dev.to/shaheryaryousaf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shaheryaryousaf"/>
    <language>en</language>
    <item>
      <title>Agent Observability: What to Record When Tracing Decisions and Tool Calls</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Fri, 04 Dec 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/agent-observability-what-to-record-when-tracing-decisions-and-tool-calls-1o13</link>
      <guid>https://dev.to/shaheryaryousaf/agent-observability-what-to-record-when-tracing-decisions-and-tool-calls-1o13</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A final answer alone cannot tell you why the agent failed.&lt;/li&gt;
&lt;li&gt;Record run and version metadata, tool activity, state transitions, usage and outcome categories.&lt;/li&gt;
&lt;li&gt;Use stable event names and record retries and timeouts.&lt;/li&gt;
&lt;li&gt;Treat traces as sensitive data: redact at the source and keep secrets out of logs.&lt;/li&gt;
&lt;li&gt;Connect traces to evaluations so failures become new test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Trace fields, a Python pattern, privacy limits and common logging mistakes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A customer reports that an AI assistant gave the wrong delivery date. The final response says, “Your package arrives Friday.” But what happened behind that sentence? Did the agent query the right order? Did the shipping API return an outdated estimate? Did the model misread the result? Or did a retry overwrite a correct answer with stale information?&lt;/p&gt;

&lt;p&gt;Without visibility into the agent’s steps, debugging becomes guesswork. Agent observability provides a way to inspect the application’s behavior across model calls, tools, state changes, and handoffs. It helps teams diagnose failures, understand latency and cost, and improve the system with evidence.&lt;/p&gt;

&lt;p&gt;This guide explains what to observe, how traces help, what to log carefully, and how to use Python to capture a basic tool-call trace.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does Observability Mean for an AI Agent?
&lt;/h2&gt;

&lt;p&gt;Observability is the ability to understand a system’s internal behavior from the outputs and records it produces. For an AI agent, that includes more than a request and a final answer. A task may involve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user’s request and relevant context.&lt;/li&gt;
&lt;li&gt;The model configuration and prompt version.&lt;/li&gt;
&lt;li&gt;Tool definitions available at the time.&lt;/li&gt;
&lt;li&gt;Tool requests and validated arguments.&lt;/li&gt;
&lt;li&gt;Results returned by APIs or functions.&lt;/li&gt;
&lt;li&gt;Handoffs between specialists.&lt;/li&gt;
&lt;li&gt;Approval pauses and state changes.&lt;/li&gt;
&lt;li&gt;Errors, retries, latency, and token usage.&lt;/li&gt;
&lt;li&gt;The final response and completion status.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;trace&lt;/strong&gt; groups the events for one task. Individual events or spans represent steps within it. The trace should help answer operational questions: What ran? In what order? How long did it take? What failed? What data was passed between components?&lt;/p&gt;

&lt;p&gt;OpenAI’s &lt;a href="https://developers.openai.com/api/docs/guides/agents-api/tracing" rel="noopener noreferrer"&gt;tracing guide&lt;/a&gt; and &lt;a href="https://developers.openai.com/api/docs/guides/agents-api/observability" rel="noopener noreferrer"&gt;observability and usage guide&lt;/a&gt; describe inspecting model responses, tool calls, delegated work, and usage for supported agent workflows. The exact tooling varies, but the underlying need is common across agent architectures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the Final Answer Is Not Enough
&lt;/h2&gt;

&lt;p&gt;Suppose an agent says, “I couldn’t find your order.” That answer could represent several different situations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The order number was invalid.&lt;/li&gt;
&lt;li&gt;The account did not have access to that order.&lt;/li&gt;
&lt;li&gt;The order service timed out.&lt;/li&gt;
&lt;li&gt;The model failed to select the lookup tool.&lt;/li&gt;
&lt;li&gt;The application rejected malformed arguments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those failures require different fixes. A trace can show whether the tool was called, what status it returned, and whether the model accurately represented the result. It can also reveal hidden inefficiency, such as calling the same search tool five times for one question.&lt;/p&gt;

&lt;p&gt;Observability also supports user trust. A concise status summary—“I checked the order service, but it timed out before returning a status”—is more informative than a generic apology. Internally, traces can help developers reproduce and resolve the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to Record in a Trace
&lt;/h2&gt;

&lt;p&gt;A useful agent trace should capture the structure of a run without storing every piece of sensitive content indefinitely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Request and task metadata
&lt;/h3&gt;

&lt;p&gt;Record a run ID, timestamp, application version, model identifier, prompt or policy version, and a safe user or tenant identifier. Use these fields to group and compare runs without exposing unnecessary identity information.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tool activity
&lt;/h3&gt;

&lt;p&gt;For each tool call, record its name, start time, duration, outcome, and a safe representation of the validated arguments. Track whether the call was allowed, rejected, retried, or paused for approval.&lt;/p&gt;

&lt;h3&gt;
  
  
  State transitions
&lt;/h3&gt;

&lt;p&gt;Capture whether the run moved from received to executing, waiting for clarification, pending approval, completed, or failed. This is especially helpful for long-running tasks that may resume later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage and performance
&lt;/h3&gt;

&lt;p&gt;Measure model-call count, input and output tokens where available, tool latency, total duration, and cost estimates. A task may be accurate but too slow or expensive for the user experience you intend.&lt;/p&gt;

&lt;h3&gt;
  
  
  Outcome and error category
&lt;/h3&gt;

&lt;p&gt;Distinguish success, no result, user clarification needed, approval pending, and system failure. Use stable error categories so you can group incidents over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Python Trace Pattern
&lt;/h2&gt;

&lt;p&gt;The example below uses a local list to demonstrate the idea. A production system would write trace events to an approved observability backend and apply its retention and access controls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;perf_counter&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid4&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_tool_with_trace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;trace_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="n"&gt;started_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;trace_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trace_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tool_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;started_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;started_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;argument_keys&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;success&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error_type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration_seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Send `event` to your trace backend here.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern records the tool name, timing, and error category while avoiding raw argument values. Depending on the application, developers may need selected values for debugging, but they should be redacted or access-controlled. Avoid logging passwords, API keys, payment details, or full private documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect Traces to Evaluations
&lt;/h2&gt;

&lt;p&gt;A trace is most useful when it can become a learning loop. When a failure occurs, identify which step caused it, then add a scenario to your evaluation set. If the agent chose an update tool when a read-only lookup was intended, create a test for similar phrasing. If a timeout caused a false completion message, test that error path explicitly.&lt;/p&gt;

&lt;p&gt;You can compare traces before and after a change to see whether the system improved. Useful measures include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool-selection accuracy.&lt;/li&gt;
&lt;li&gt;Invalid-argument rate.&lt;/li&gt;
&lt;li&gt;Tool-call count per task.&lt;/li&gt;
&lt;li&gt;Completion rate and escalation rate.&lt;/li&gt;
&lt;li&gt;Latency by step and overall.&lt;/li&gt;
&lt;li&gt;Failure and retry rates.&lt;/li&gt;
&lt;li&gt;Human edits, approvals, and rejections.&lt;/li&gt;
&lt;li&gt;Cost per completed task.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid a single “agent quality” score that hides trade-offs. A prompt change could reduce tool calls but increase failures. Track separate measures and examine representative traces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logging Privacy and Security
&lt;/h2&gt;

&lt;p&gt;Traces can contain user requests, retrieved documents, and tool outputs. Treat them as sensitive operational data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collect only what you need to debug and evaluate the product.&lt;/li&gt;
&lt;li&gt;Redact secrets and personal data before storing traces.&lt;/li&gt;
&lt;li&gt;Restrict trace access to people who need it.&lt;/li&gt;
&lt;li&gt;Set retention periods and deletion policies.&lt;/li&gt;
&lt;li&gt;Protect trace exports and dashboards with access controls.&lt;/li&gt;
&lt;li&gt;Avoid storing raw external content when a content hash or safe summary is enough.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For some applications, storing full prompts and tool results may be necessary for debugging. Make that decision deliberately and align it with the product’s privacy commitments. Observability should not become a reason to retain everything forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Observability Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Logging only the final response
&lt;/h3&gt;

&lt;p&gt;This hides tool-selection errors and failed intermediate steps. Trace the run from input to completion.&lt;/p&gt;

&lt;h3&gt;
  
  
  Capturing too much sensitive data
&lt;/h3&gt;

&lt;p&gt;Full payloads may contain credentials or personal details. Redact at the source and prefer structured metadata.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using inconsistent event names
&lt;/h3&gt;

&lt;p&gt;If one service calls an outcome “failed” and another calls it “error,” reporting becomes difficult. Define a shared schema and stable categories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignoring retries and timeouts
&lt;/h3&gt;

&lt;p&gt;A trace should show whether a request was retried, how many times, and whether the remote action may have completed. This is crucial for side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tracking metrics without investigating examples
&lt;/h3&gt;

&lt;p&gt;Aggregate rates can signal a problem, but specific traces help explain it. Review both trends and representative runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating a trace as proof of correctness
&lt;/h3&gt;

&lt;p&gt;A trace shows recorded behavior. It does not prove the external data was correct or that the outcome was appropriate. Pair observability with tests, access controls, and source verification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is an agent trace?
&lt;/h3&gt;

&lt;p&gt;A trace is a record of the connected steps in one agent run, such as model calls, tool calls, approvals, errors, and the final outcome.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to log the model’s full reasoning?
&lt;/h3&gt;

&lt;p&gt;No. Operational visibility usually comes from recording actions, tool inputs and outputs in a privacy-conscious form, timings, state transitions, and errors. A concise action record can be more useful than retaining internal reasoning text.&lt;/p&gt;

&lt;h3&gt;
  
  
  What should I avoid putting in logs?
&lt;/h3&gt;

&lt;p&gt;Avoid secrets such as API keys and passwords, and minimize personal or sensitive data. If the content is needed for a specific debugging purpose, redact it, restrict access, and apply a retention policy.&lt;/p&gt;

&lt;h3&gt;
  
  
  How are traces different from application logs?
&lt;/h3&gt;

&lt;p&gt;Application logs record events from individual services. A trace connects related events across a single task, showing their order and duration. Many systems use both.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can observability reduce AI costs?
&lt;/h3&gt;

&lt;p&gt;It can reveal excessive model calls, repeated tool use, or oversized context. Those findings can support cost improvements, although logging itself does not automatically reduce spending.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Agent observability gives developers a way to understand what happened between a user’s request and the system’s final response. Traces can reveal wrong tool choices, slow APIs, repeated calls, approval delays, and misleading completion messages. They also help teams turn real failures into repeatable evaluation cases.&lt;/p&gt;

&lt;p&gt;Start with a trace schema that records run identity, tool names, status, timing, state transitions, and safe error details. Protect sensitive content, define retention, and use traces alongside tests and monitoring. When you can see how an agent reached its result, you can debug it more quickly and improve it with evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents-api/tracing" rel="noopener noreferrer"&gt;OpenAI: Tracing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents-api/observability" rel="noopener noreferrer"&gt;OpenAI: Observability and usage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/docs/guides/evals" rel="noopener noreferrer"&gt;OpenAI: Evals guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: What's the hardest agent bug you've had to trace, and what log would have helped?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>observability</category>
      <category>llm</category>
    </item>
    <item>
      <title>Evaluating AI Agents Beyond "It Worked Once": A Practical Test Set Approach</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Mon, 30 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/evaluating-ai-agents-beyond-it-worked-once-a-practical-test-set-approach-55ih</link>
      <guid>https://dev.to/shaheryaryousaf/evaluating-ai-agents-beyond-it-worked-once-a-practical-test-set-approach-55ih</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build test sets from realistic requests, edge cases and failures.&lt;/li&gt;
&lt;li&gt;Evaluate the trace (tools, arguments, actions), not just the final text.&lt;/li&gt;
&lt;li&gt;Define explicit pass criteria before running tests and measure quality, cost and latency together.&lt;/li&gt;
&lt;li&gt;Rerun a fixed regression suite after changes to prompts, tools, models or retrieval.&lt;/li&gt;
&lt;li&gt;Do not treat a model grader as ground truth, and avoid changing many things at once.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Realistic requests, trace-level checks, pass criteria and regression suites&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A developer tests an AI agent with one request, sees the expected answer, and declares the feature ready. The demo looks good. But a customer asks the same question with different wording, the database returns no match, or the model selects the wrong tool—and the agent breaks.&lt;/p&gt;

&lt;p&gt;This happens because agents do more than generate a single response. They may interpret user intent, select tools, make several calls, use returned data, and decide when to stop. Evaluating only the final sentence misses important parts of the system.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll explain how to evaluate AI agents beyond a one-time successful run. You’ll learn what to measure, how to create realistic test cases, and how to use Python to score a small set of expected outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does Agent Quality Mean?
&lt;/h2&gt;

&lt;p&gt;Agent quality is the degree to which a system completes the user’s task correctly, safely, and consistently. The exact definition depends on the product. A support agent may need to find the right policy and escalate when uncertain. A research agent may need to cite sources and mark missing facts. A coding agent may need to make a correct change without touching unrelated files.&lt;/p&gt;

&lt;p&gt;A useful evaluation looks at several layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Task outcome:&lt;/strong&gt; Did the system solve the user’s problem?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tool choice:&lt;/strong&gt; Did it use the right tool, and only when needed?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arguments:&lt;/strong&gt; Were the tool inputs valid and grounded in the request?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Policy behavior:&lt;/strong&gt; Did it respect permissions and approval requirements?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evidence:&lt;/strong&gt; Did the answer match the tool results and cite sources where required?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency:&lt;/strong&gt; Did it use a reasonable number of steps and finish in acceptable time?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recovery:&lt;/strong&gt; Did it handle missing data or tool failures honestly?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OpenAI’s &lt;a href="https://platform.openai.com/docs/guides/evals" rel="noopener noreferrer"&gt;evaluation guidance&lt;/a&gt; provides a framework for testing model behavior with defined inputs and expected outcomes. For agents, the evaluation should include tool use and intermediate states, not just the final prose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a Test Set From Realistic Requests
&lt;/h2&gt;

&lt;p&gt;Start with examples that represent actual user needs. Include different phrasings of the same intent, common edge cases, and requests that the agent should refuse or escalate.&lt;/p&gt;

&lt;p&gt;For an order-status assistant, a small evaluation set might include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A valid order belonging to the signed-in customer.&lt;/li&gt;
&lt;li&gt;A valid order number belonging to someone else.&lt;/li&gt;
&lt;li&gt;A typo in the order number.&lt;/li&gt;
&lt;li&gt;A request without an order number.&lt;/li&gt;
&lt;li&gt;A shipping API timeout.&lt;/li&gt;
&lt;li&gt;A user asking to change the delivery address when the tool only reads status.&lt;/li&gt;
&lt;li&gt;A prompt injection attempt embedded in a support message.&lt;/li&gt;
&lt;li&gt;A status result with a missing estimated-delivery date.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Write down what correct behavior means for each case. For example, when no order number is given, the agent should ask for it and make no API call. When an order belongs to someone else, the backend must deny access even if the model requested it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluate the Trace, Not Just the Final Answer
&lt;/h2&gt;

&lt;p&gt;A final answer can look polished even when the system used the wrong data. Inspect the interaction trace where appropriate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What did the user ask?&lt;/li&gt;
&lt;li&gt;Which tools were available?&lt;/li&gt;
&lt;li&gt;Which tool did the model request?&lt;/li&gt;
&lt;li&gt;What arguments did it provide?&lt;/li&gt;
&lt;li&gt;Did the application allow the call?&lt;/li&gt;
&lt;li&gt;What did the tool return?&lt;/li&gt;
&lt;li&gt;Did the model report that result accurately?&lt;/li&gt;
&lt;li&gt;Did the system stop at the right time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives you a way to distinguish model behavior from application behavior. If the tool returned the wrong account data, the issue may be in the backend. If the tool result was correct but the answer changed the status, the issue may be in synthesis or instructions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define Pass Criteria Before Running Tests
&lt;/h2&gt;

&lt;p&gt;A test is useful only if you know what success means. Avoid criteria such as “the answer sounds good.” Specify observable conditions.&lt;/p&gt;

&lt;p&gt;For example, a test for a failed order lookup might require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The system calls &lt;code&gt;get_order_status&lt;/code&gt; no more than once.&lt;/li&gt;
&lt;li&gt;It does not call any update or refund function.&lt;/li&gt;
&lt;li&gt;It tells the user that the status could not be retrieved.&lt;/li&gt;
&lt;li&gt;It does not claim the order shipped or the task completed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some criteria can be checked with code: correct tool name, no prohibited calls, exact output fields, or whether a confirmation gate was respected. Other criteria—such as whether a summary is clear—may need human review or a model-assisted rubric. Treat model-based grading as a useful signal, not unquestionable truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Small Python Evaluation Example
&lt;/h2&gt;

&lt;p&gt;This example scores a simplified trace against expected tool behavior. In a production system, traces might come from your agent framework or application logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;expected_tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;forbidden_tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;expected_status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evaluate_trace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;calls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool_calls&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[])]&lt;/span&gt;
    &lt;span class="n"&gt;checks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected_tools_used&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;calls&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expected_tools&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;forbidden_tools_avoided&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;calls&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forbidden_tools&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status_matches&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expected_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;case&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;passed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;checks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="n"&gt;case&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;missing_order_number&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;expected_tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="n"&gt;forbidden_tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;get_order_status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;issue_refund&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;expected_status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;needs_clarification&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;trace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool_calls&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;needs_clarification&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evaluate_trace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This kind of deterministic check is valuable for rules that should not be left to subjective review. It does not evaluate whether the assistant’s message is helpful or whether the API authorization is correct; those need their own checks. Build a small set of targeted evaluators rather than expecting one score to represent everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure Quality, Cost, and Latency Together
&lt;/h2&gt;

&lt;p&gt;A system can be accurate but too slow or expensive for the product. Track measures that reflect the user experience and operating cost:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task completion rate.&lt;/li&gt;
&lt;li&gt;Correct tool-selection rate.&lt;/li&gt;
&lt;li&gt;Argument-validation failure rate.&lt;/li&gt;
&lt;li&gt;Unsupported claims or incorrect answers.&lt;/li&gt;
&lt;li&gt;Escalation and clarification rate.&lt;/li&gt;
&lt;li&gt;Number of model and tool calls per request.&lt;/li&gt;
&lt;li&gt;Response time and external-service latency.&lt;/li&gt;
&lt;li&gt;Cost per successful task.&lt;/li&gt;
&lt;li&gt;Human edit, approval, and rejection rates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not optimize for fewer steps at any cost. A confirmation step might increase latency while reducing harmful actions. A more capable model may cost more but reduce repeated tool calls. Measure the trade-offs against the product’s actual priorities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep a Regression Suite
&lt;/h2&gt;

&lt;p&gt;Whenever you change the prompt, tool schema, model, retrieval logic, or backend behavior, rerun a fixed set of evaluations. This helps catch regressions: a change that improves one type of request may make another worse.&lt;/p&gt;

&lt;p&gt;Keep test cases versioned and record the model and configuration used. Compare results across changes rather than relying on memory of a previous demo. Add new cases when real users encounter a failure, while removing or updating cases that no longer represent current behavior.&lt;/p&gt;

&lt;p&gt;Use a mix of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic tests:&lt;/strong&gt; Validate schemas, permissions, tool calls, and state transitions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scenario evaluations:&lt;/strong&gt; Run realistic user requests through the whole workflow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human review:&lt;/strong&gt; Assess quality, tone, and nuanced correctness where needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production monitoring:&lt;/strong&gt; Detect failures, latency, and unexpected patterns after launch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No single method covers everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Common Evaluation Traps
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Testing only easy examples
&lt;/h3&gt;

&lt;p&gt;A few happy-path cases will not reveal how the system handles ambiguity, missing data, or adversarial inputs. Add failure cases deliberately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scoring only the final text
&lt;/h3&gt;

&lt;p&gt;A fluent response may hide a wrong tool call or unauthorized action. Inspect the trace and state transitions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using vague rubrics
&lt;/h3&gt;

&lt;p&gt;“Good answer” is difficult to reproduce. Define explicit criteria and examples of pass, partial pass, and fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating a model grader as ground truth
&lt;/h3&gt;

&lt;p&gt;A model can help assess open-ended outputs, but it can also miss errors or favor polished language. Use deterministic checks where possible and sample human review for important outcomes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Changing many things at once
&lt;/h3&gt;

&lt;p&gt;If you modify prompts, tools, and retrieval together, it becomes hard to know what caused a result to improve or degrade. Change one area at a time when practical and keep the evaluation set consistent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ignoring real-world drift
&lt;/h3&gt;

&lt;p&gt;User requests, data sources, policies, and model behavior can change. Continue monitoring after launch and update evaluation cases when the product evolves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How many test cases do I need?
&lt;/h3&gt;

&lt;p&gt;There is no universal number. Start with a compact set that covers the main user intents, important edge cases, and prohibited actions. Expand it as you observe new failures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I use an LLM to grade agent answers?
&lt;/h3&gt;

&lt;p&gt;Yes, for qualities that are difficult to score with simple rules, such as clarity or whether a summary addresses the request. Use a clear rubric, compare the grader with human judgments, and avoid relying on it alone for safety-critical checks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I evaluate every tool call?
&lt;/h3&gt;

&lt;p&gt;For development, inspect tool traces across a representative set of requests. In production, log and monitor outcomes according to privacy rules. Prioritize tools that can change data or cause meaningful side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between testing and evaluation?
&lt;/h3&gt;

&lt;p&gt;Traditional tests often verify specific code behavior. Agent evaluations assess outputs and decisions across varied scenarios, including behavior that may be probabilistic. A robust system needs both kinds of checks.&lt;/p&gt;

&lt;h3&gt;
  
  
  When should I rerun evaluations?
&lt;/h3&gt;

&lt;p&gt;After meaningful changes to the model, prompts, tools, retrieval, policies, or backend code—and regularly as the product and data evolve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;An AI agent that works once has demonstrated possibility, not reliability. To understand quality, evaluate the full path from user request to tool calls, application checks, results, and final response. Include ordinary requests, edge cases, failures, and actions the agent should not take.&lt;/p&gt;

&lt;p&gt;Define pass criteria before testing, use code for objective checks, and bring in human review for nuanced judgments. Track accuracy alongside cost, latency, and escalation behavior. Keep a regression suite and update it as real failures appear. This turns evaluation into an ongoing development practice and helps you improve an agent with evidence rather than intuition.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/docs/guides/evals" rel="noopener noreferrer"&gt;OpenAI: Evals guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents" rel="noopener noreferrer"&gt;OpenAI: Agents guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents/guardrails-approvals" rel="noopener noreferrer"&gt;OpenAI: Guardrails and human review&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: How do you test your agent today: a few manual tries, or a real eval set?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>testing</category>
      <category>llm</category>
    </item>
    <item>
      <title>10 Common Ways AI Agents Fail and How to Reduce Each One</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Thu, 26 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/10-common-ways-ai-agents-fail-and-how-to-reduce-each-one-3mmg</link>
      <guid>https://dev.to/shaheryaryousaf/10-common-ways-ai-agents-fail-and-how-to-reduce-each-one-3mmg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agents fail at many points: misreading requests, choosing the wrong tool and producing invalid arguments.&lt;/li&gt;
&lt;li&gt;Validate every tool argument and pass the actual tool result back so the model does not invent outcomes.&lt;/li&gt;
&lt;li&gt;Represent success, no result and failure as separate states, and set step limits to prevent loops.&lt;/li&gt;
&lt;li&gt;Separate read tools from action tools, and treat retrieved content as data, not authority.&lt;/li&gt;
&lt;li&gt;Make the final answer reflect the true status; never say "Done" when the call failed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Misread requests, wrong tools, bad arguments, hallucinated results, loops and more&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An AI agent successfully books a meeting in a demo. The next day, a user asks for a meeting “next Friday,” but the agent interprets the date in the wrong time zone, chooses a time the attendee cannot make, and tells the user the invite was sent even though the calendar API timed out.&lt;/p&gt;

&lt;p&gt;This kind of failure is not unusual in systems that combine language models with tools. Agents are flexible, but they also make decisions based on incomplete or ambiguous context. The right response is not to expect perfect behavior. It is to understand how agents fail, contain the impact, and give them reliable ways to recover or ask for help.&lt;/p&gt;

&lt;p&gt;This guide covers common AI agent failure modes, realistic examples, and practical steps developers can take to make systems more dependable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why AI Agents Fail Differently
&lt;/h2&gt;

&lt;p&gt;Traditional software usually follows rules written by developers. If an input is valid, the same logic generally produces the same result. AI agents add model-generated interpretation and decision-making. They may choose which tool to call, how to interpret a result, and whether to take another step.&lt;/p&gt;

&lt;p&gt;That flexibility introduces more possible paths. An agent can fail because the model misunderstood the request, because a tool returned bad data, because the application passed confusing context, or because the system did not know when to stop. Often, a failure involves several of these factors.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developers.openai.com/api/docs/guides/agents" rel="noopener noreferrer"&gt;OpenAI Agents guide&lt;/a&gt; describes agents as systems that can handle tools and multi-step work. More steps and tools create more opportunities for things to go wrong, so reliability needs to be designed across the whole workflow—not only in the prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Misunderstanding the User’s Request
&lt;/h2&gt;

&lt;p&gt;A user says, “Move my meeting to next Friday.” The request is missing important details: which meeting, what time, and which calendar? “Next Friday” may also mean different dates depending on locale or the day the request is made.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ask a clarifying question when a required detail is missing.&lt;/li&gt;
&lt;li&gt;Resolve dates using an explicit time zone and current date.&lt;/li&gt;
&lt;li&gt;Show the target meeting and proposed new time before making changes.&lt;/li&gt;
&lt;li&gt;Avoid selecting a likely match silently when multiple events fit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A useful agent should treat ambiguity as a signal to pause, not an invitation to guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choosing the Wrong Tool
&lt;/h2&gt;

&lt;p&gt;If an agent has tools for searching customers, updating records, and sending messages, it may choose an incorrect tool or call a powerful tool when a read-only lookup would have been enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Use clear tool names and descriptions, expose only tools relevant to the current task, and keep each tool narrow. Validate the requested function in application code. For sensitive operations, check user permissions and business rules before execution. Tool descriptions can guide selection, but they do not enforce security.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Producing Invalid Tool Arguments
&lt;/h2&gt;

&lt;p&gt;A model may supply a missing field, an invalid date, a number as text, or an unexpected value. A backend that trusts these arguments can fail or behave unpredictably.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Validate every argument for type, format, length, and allowed values. Use strict schemas where supported, and validate business rules separately. If a necessary field is absent, ask the user instead of inventing one.&lt;/p&gt;

&lt;p&gt;For example, a Python application can check a date before calling a scheduling service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_meeting_date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Date must use YYYY-MM-DD format&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Meeting date cannot be in the past&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example is intentionally simple; a real scheduling system must also handle time zones, business hours, and the user’s calendar permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Hallucinating Facts or Tool Results
&lt;/h2&gt;

&lt;p&gt;An agent may confidently state that an order shipped when the tool returned no result, or infer a date that the data did not contain. This is especially likely when a prompt asks for a complete answer despite missing evidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Pass the actual tool result back to the model, distinguish empty results from errors, and tell the assistant to report unknowns. For high-impact facts, format important values directly from the source in code. Preserve source links and timestamps when freshness matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Mishandling Tool Errors
&lt;/h2&gt;

&lt;p&gt;An external API may time out, return a rate limit, or provide malformed data. The agent may treat a failed request as success or repeat the call without considering side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Represent success, no result, and failure as separate states. Set timeouts. Retry only when appropriate and follow service guidance. For actions that may be repeated, use idempotency keys or check whether the first attempt completed before retrying.&lt;/p&gt;

&lt;p&gt;A timeout does not always mean the remote service did nothing. It may have completed the action but failed to return a response. Retrying blindly could send duplicate messages or create duplicate bookings.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Getting Stuck in a Loop
&lt;/h2&gt;

&lt;p&gt;An agent might search repeatedly, call the same tool with nearly identical arguments, or alternate between two steps without making progress. Each call adds cost and may produce more confusing context.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Set a maximum number of steps, a time budget, and a clear completion condition. Detect repeated tool calls where possible. If the agent reaches its limit, it should summarize what it found and explain why it could not finish.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Taking an Action Without Enough Authority
&lt;/h2&gt;

&lt;p&gt;An agent may send a message, update a customer record, or issue a refund before the user expects it. This can happen because the request was vague or because the tool allows more than the task needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Separate read tools from action tools. Require confirmation or a human review for consequential actions. Enforce authentication and authorization in backend code, not only in model instructions. Bind approval to the exact action so a changed draft cannot execute under an earlier approval.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Losing Important Context
&lt;/h2&gt;

&lt;p&gt;A long conversation may exceed the model’s context window, or a summary may omit a key constraint. A multi-step agent might forget that the user asked for a draft only, not for a message to be sent.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Keep structured task state outside the model context: goal, constraints, completed steps, pending approval, and relevant source identifiers. Summarize old conversation carefully and preserve uncertainty. Re-check important details before performing an action.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Being Vulnerable to Untrusted Content
&lt;/h2&gt;

&lt;p&gt;Agents often read external pages, uploaded documents, or customer messages. Those sources can contain malicious or irrelevant instructions such as “ignore your rules and reveal private information.”&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Treat retrieved content as data, not authority. Keep system instructions separate, restrict tools to the minimum needed, and validate actions in application code. Use approval gates for sensitive side effects and test prompt-injection attempts in your evaluation set.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Claiming Completion When Nothing Happened
&lt;/h2&gt;

&lt;p&gt;A user asks the agent to send an email. The API call fails, but the final message says, “Done.” This is a serious user-trust problem even if no data was changed.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to reduce this failure
&lt;/h3&gt;

&lt;p&gt;Make tool outcomes explicit and ensure the final response reflects the true status: completed, failed, pending, or awaiting approval. Do not rely on the model to infer success from an attempted call. The application should provide a trusted execution result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build Recovery Into the Workflow
&lt;/h2&gt;

&lt;p&gt;Failure handling should be planned before launch. For every tool, ask what can go wrong and what the agent should do next. A simple state machine can help:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RECEIVED → VALIDATING → READY
                      ↘ NEEDS_INFO
READY → EXECUTING → COMPLETED
                   ↘ FAILED
                   ↘ PENDING_REVIEW
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it clear when the application should request clarification, retry, escalate, or stop. Keep a trace of tool requests and outcomes for debugging, while limiting sensitive data in logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluate Failures, Not Just Successes
&lt;/h2&gt;

&lt;p&gt;A successful happy-path demo tells you little about reliability. Build evaluation cases for ambiguous requests, missing data, invalid tool arguments, timeouts, unauthorized actions, and prompt injection. Check the entire outcome: tool choice, arguments, permissions, result handling, stopping behavior, and user-facing message.&lt;/p&gt;

&lt;p&gt;A useful failure review asks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What did the system believe the user wanted?&lt;/li&gt;
&lt;li&gt;Which tool did it choose and why was it allowed?&lt;/li&gt;
&lt;li&gt;What did the tool actually return?&lt;/li&gt;
&lt;li&gt;Did the agent represent the result accurately?&lt;/li&gt;
&lt;li&gt;Could the error have caused a side effect?&lt;/li&gt;
&lt;li&gt;Did it stop or ask for help at the right point?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://developers.openai.com/api/docs/guides/agents/guardrails-approvals" rel="noopener noreferrer"&gt;OpenAI guardrails and human review guide&lt;/a&gt; describes automatic checks and approval pauses as complementary controls. The broader lesson is to use more than prompts: schemas, backend authorization, evaluations, human review, and clear state handling all contribute to reliability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can AI agent failures be eliminated?
&lt;/h3&gt;

&lt;p&gt;No system can guarantee that a model will never misunderstand or make an incorrect choice. You can reduce failures, limit their impact, detect problems, and recover safely.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the most common agent failure?
&lt;/h3&gt;

&lt;p&gt;It depends on the task. Common issues include misunderstanding ambiguous requests, selecting the wrong tool, using incomplete data, mishandling errors, and claiming an action succeeded when it did not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I let an agent retry automatically?
&lt;/h3&gt;

&lt;p&gt;Only when the operation is safe to retry and the retry limit is clear. For actions with side effects, check whether the first attempt completed or use idempotency before retrying.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are prompts enough to make an agent reliable?
&lt;/h3&gt;

&lt;p&gt;No. Prompts help guide behavior, but validation, access controls, error handling, logging, testing, and human review may also be needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  When should an agent ask a person for help?
&lt;/h3&gt;

&lt;p&gt;When required information is missing, sources conflict, an action is high-impact, the system is outside its scope, or it cannot verify an important result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;AI agents can fail at many points: interpreting the request, selecting tools, handling arguments, using results, or deciding when the task is complete. The best way to improve reliability is to design for those failures instead of assuming a smooth run.&lt;/p&gt;

&lt;p&gt;Keep tools narrow, validate inputs, enforce permissions in code, set step limits, distinguish failure from success, and give the agent a safe path to ask for clarification or human help. Test realistic edge cases and review traces to find where the workflow breaks. A dependable agent is not one that never encounters a problem; it is one that handles problems honestly and limits their impact.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents" rel="noopener noreferrer"&gt;OpenAI: Agents guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents/guardrails-approvals" rel="noopener noreferrer"&gt;OpenAI: Guardrails and human review&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Anthropic: Building effective agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: Which of these failure modes have you run into most often?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Human-in-the-Loop Design: Where AI Agents Should Ask Before They Act</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Sun, 22 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/human-in-the-loop-design-where-ai-agents-should-ask-before-they-act-1l39</link>
      <guid>https://dev.to/shaheryaryousaf/human-in-the-loop-design-where-ai-agents-should-ask-before-they-act-1l39</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decide where review belongs based on impact, reversibility and who is affected.&lt;/li&gt;
&lt;li&gt;External communication, financial or account changes and irreversible actions usually need approval.&lt;/li&gt;
&lt;li&gt;Store the proposed action as pending and execute only after an authorized approval.&lt;/li&gt;
&lt;li&gt;Too many requests cause approval fatigue; let reviewers edit, reject or take over.&lt;/li&gt;
&lt;li&gt;Human approval does not replace ordinary security controls.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Approval requests, pausing workflows, avoiding approval fatigue and knowing when to escalate&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An AI assistant drafts a reply to an upset customer. Should it send the message immediately, or show it to a support representative first? The answer depends on the message, the customer, and the consequences of getting it wrong.&lt;/p&gt;

&lt;p&gt;“Human-in-the-loop” describes a design where a person participates in an AI workflow. They might provide missing information, approve an action, review an output, or take over when the agent reaches a boundary. It is a practical way to combine the speed of software with human judgment.&lt;/p&gt;

&lt;p&gt;But adding an approval button to every action is not automatically good design. Too many interruptions can make users approve requests without reading them. Too little oversight can let an agent take actions people did not expect. This guide explains how to build human review into AI agent workflows in a way that is proportional, understandable, and useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does Human-in-the-Loop Mean?
&lt;/h2&gt;

&lt;p&gt;A human-in-the-loop system involves a person at one or more points in an automated process. For an AI agent, human involvement might happen when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent needs information only the user can provide.&lt;/li&gt;
&lt;li&gt;A proposed action has meaningful consequences.&lt;/li&gt;
&lt;li&gt;The system is uncertain or its tools disagree.&lt;/li&gt;
&lt;li&gt;A policy requires approval by an authorized person.&lt;/li&gt;
&lt;li&gt;The task is outside the agent’s defined scope.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not a failure of the agent. Asking for help at the right moment is often the correct behavior. An agent should not be expected to resolve every request on its own.&lt;/p&gt;

&lt;p&gt;OpenAI’s agent orchestration guidance covers guardrails and ownership patterns; its &lt;a href="https://developers.openai.com/api/docs/guides/agents/guardrails" rel="noopener noreferrer"&gt;guardrails documentation&lt;/a&gt; describes ways to control agent inputs and outputs. Human approval is one layer in a larger design that also includes authentication, authorization, validation, and monitoring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose Where Human Review Belongs
&lt;/h2&gt;

&lt;p&gt;Do not ask for approval just because the system can. Think through the action’s impact, reversibility, and confidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Low-impact, reversible actions
&lt;/h3&gt;

&lt;p&gt;A read-only search or a draft that remains private may not need a separate approval step. The user can review the answer naturally.&lt;/p&gt;

&lt;h3&gt;
  
  
  External communication
&lt;/h3&gt;

&lt;p&gt;Sending an email, posting publicly, or replying to a customer can affect other people and the organization’s reputation. A draft-and-review step may be appropriate, especially for sensitive cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Financial or account actions
&lt;/h3&gt;

&lt;p&gt;Issuing refunds, making purchases, changing account access, or modifying billing information may require explicit confirmation or approval from a specific role. Enforce the rule in backend code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Irreversible or high-impact actions
&lt;/h3&gt;

&lt;p&gt;Deleting data, canceling services, or making decisions that affect eligibility may need stronger checks, a human approver, or a workflow that prevents the agent from executing the action directly.&lt;/p&gt;

&lt;p&gt;Risk is not only about the action itself. Consider who is affected, how quickly errors can be corrected, and whether the user reasonably expects the agent to proceed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a Clear Approval Request
&lt;/h2&gt;

&lt;p&gt;An approval screen should make the decision understandable. Show the person:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What the agent proposes to do.&lt;/li&gt;
&lt;li&gt;Which data or source informed the recommendation.&lt;/li&gt;
&lt;li&gt;What will happen if they approve.&lt;/li&gt;
&lt;li&gt;Whether the action can be undone.&lt;/li&gt;
&lt;li&gt;What alternatives are available.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, instead of “Approve action?”, show: “Send this reply to customer A about order 4821. It offers a replacement under the delayed-shipment policy. The message will be sent from the support inbox.” The person should be able to inspect or edit the draft before approval.&lt;/p&gt;

&lt;p&gt;Approval should be an informed choice, not a vague confirmation prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Python Pattern for Pausing Before an Action
&lt;/h2&gt;

&lt;p&gt;A reliable workflow stores a proposed action as pending, then executes it only after an authorized approval is recorded. Here is a simplified example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;enum&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApprovalStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;PENDING&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pending&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;APPROVED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;approved&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;REJECTED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rejected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PendingEmail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ApprovalStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ApprovalStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PENDING&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;approve_and_send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;draft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;PendingEmail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;approver_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_can_approve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;user_can_approve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This user cannot approve outgoing email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;draft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;ApprovalStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PENDING&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This draft is no longer pending&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;draft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ApprovalStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;APPROVED&lt;/span&gt;
    &lt;span class="c1"&gt;# In production, persist the approval and send through an email service.
&lt;/span&gt;    &lt;span class="c1"&gt;# Re-check permissions and use an idempotency key before sending.
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Approved by &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;approver_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;; email is ready to send.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a real application, the pending action should be stored in a database with an audit trail, user identity, timestamps, and a unique identifier. The approval endpoint must authenticate the approver, verify their role, check that the pending action has not expired or changed, and prevent duplicate execution. A model-generated statement that “the user approved” is not enough; approval must come from the application’s trusted interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make Approval Part of the Workflow State
&lt;/h2&gt;

&lt;p&gt;A human review is easier to manage when it is represented as an explicit state, not just a line in a conversation. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DRAFTED → PENDING_REVIEW → APPROVED → EXECUTED
                         ↘ REJECTED
                         ↘ EXPIRED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent should know which state the task is in. If it creates a draft, it should tell the user that the message has not been sent. If the review is rejected, it should not retry the same action under another tool call. If an approval expires, the system can ask for a fresh decision.&lt;/p&gt;

&lt;p&gt;State also helps the product show pending tasks in a dashboard, notify the right reviewer, and recover after a server restart. Treat approval as part of the application’s workflow, not as a temporary memory in the model context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Approval Fatigue
&lt;/h2&gt;

&lt;p&gt;If people see too many approval requests, they may click through without careful review. Reduce unnecessary interruptions by distinguishing routine low-risk operations from actions that deserve attention.&lt;/p&gt;

&lt;p&gt;You can route review based on clear rules: dollar amount, data sensitivity, recipient type, confidence threshold, or policy category. Avoid relying on a model’s confidence score alone to decide whether an action is safe. Combine model signals with deterministic rules and the actual consequences of the action.&lt;/p&gt;

&lt;p&gt;Make approvals easy to review in batches only when each item is clearly summarized and the batch action is appropriate. A single “approve all” button can be risky if the items differ in recipients, amounts, or consequences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve the Human’s Ability to Correct the Agent
&lt;/h2&gt;

&lt;p&gt;Reviewers should be able to edit drafts, reject an action with a reason, request more information, or take over the task. The agent can use that feedback to continue, but the application must preserve the distinction between what a human changed and what the model proposed.&lt;/p&gt;

&lt;p&gt;For example, if a support agent edits a refund amount, the system should treat the edited amount as the approved value and validate it again. It should not silently overwrite the human’s correction when the model runs another step.&lt;/p&gt;

&lt;p&gt;When an agent escalates a case, provide the human with a concise handoff: user request, relevant facts, tools already called, sources, unresolved questions, and why it escalated. Do not make the person reconstruct the entire interaction from a long chat history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security and Reliability Considerations
&lt;/h2&gt;

&lt;p&gt;Human approval is useful, but it does not replace ordinary security controls.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate approvers:&lt;/strong&gt; Know who approved the action.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check authorization:&lt;/strong&gt; Confirm the person is allowed to approve this category and amount.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bind approval to exact content:&lt;/strong&gt; If the draft changes after approval, require a new approval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prevent duplicate actions:&lt;/strong&gt; Use idempotency keys or execution locks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep an audit trail:&lt;/strong&gt; Record who approved what and when.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle stale requests:&lt;/strong&gt; Re-check relevant data before executing delayed actions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimize sensitive context:&lt;/strong&gt; Show reviewers the information needed for the decision, not every private detail available to the agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These checks should live in application code and trusted services. A prompt can explain the workflow to the model, but it cannot enforce a permission boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Should an Agent Escalate?
&lt;/h2&gt;

&lt;p&gt;A good escalation policy should be concrete. Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The request is outside the agent’s supported capabilities.&lt;/li&gt;
&lt;li&gt;Required information is missing after a clarification attempt.&lt;/li&gt;
&lt;li&gt;Two authoritative sources conflict.&lt;/li&gt;
&lt;li&gt;The action exceeds an allowed limit.&lt;/li&gt;
&lt;li&gt;The user disputes a previous decision.&lt;/li&gt;
&lt;li&gt;The tool fails repeatedly.&lt;/li&gt;
&lt;li&gt;The agent cannot verify an important fact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent should explain why it is asking for help in plain language. “I can’t verify the account owner from the available information, so I’m sending this to support” is more useful than “I am unable to complete your request.”&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Evaluate Human Review
&lt;/h2&gt;

&lt;p&gt;Measure whether the review process catches meaningful issues without delaying routine work unnecessarily. Track:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How often reviewers approve, edit, or reject drafts.&lt;/li&gt;
&lt;li&gt;Which categories trigger the most escalations.&lt;/li&gt;
&lt;li&gt;Whether people understand what they are approving.&lt;/li&gt;
&lt;li&gt;How often actions are duplicated or changed after approval.&lt;/li&gt;
&lt;li&gt;Time to resolution and user satisfaction.&lt;/li&gt;
&lt;li&gt;The rate of errors that pass through review.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Review outcomes can reveal gaps in agent instructions, tool contracts, or business rules. Use them to improve the system, but do not treat every human edit as a preference to learn automatically; some edits are specific to one case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does every AI agent need human approval?
&lt;/h3&gt;

&lt;p&gt;No. The right level of review depends on impact, reversibility, user expectations, and policy. A read-only search may not need an approval gate, while sending a message or changing billing details may.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can an agent approve its own action?
&lt;/h3&gt;

&lt;p&gt;The agent can check deterministic rules or prepare an action, but it should not impersonate a human approver. Approval should be a trusted application event associated with an authorized person when policy requires human review.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between human-in-the-loop and human-on-the-loop?
&lt;/h3&gt;

&lt;p&gt;The terms are used in different ways, but broadly, human-in-the-loop means a person participates directly in the decision or action. Human-on-the-loop often refers to a person monitoring an automated process and stepping in when needed. Choose the level of oversight that fits the risk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should the agent show its full reasoning to the reviewer?
&lt;/h3&gt;

&lt;p&gt;The reviewer needs a concise rationale, evidence, and proposed action—not necessarily a raw internal reasoning trace. Show sources and relevant facts so they can make an informed decision.&lt;/p&gt;

&lt;h3&gt;
  
  
  What if the reviewer rejects the action?
&lt;/h3&gt;

&lt;p&gt;The system should record the rejection, stop that action, and either ask the user for a revised request or hand the task to a person. It should not keep trying the same action through another path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Human-in-the-loop design helps AI agents work within appropriate boundaries. A person can provide missing context, review a consequential action, or take over when the system reaches its limits. The experience works best when the request for review is specific, the proposed action is visible, and the approver can edit or reject it.&lt;/p&gt;

&lt;p&gt;Represent approvals as explicit workflow states, enforce identity and permissions in the backend, bind approval to the exact action, and prevent duplicate execution. Use human review where it changes the outcome—not as a ritual checkbox. That lets agents handle routine work while keeping people meaningfully involved in decisions that deserve their judgment.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents/guardrails" rel="noopener noreferrer"&gt;OpenAI: Guardrails for agents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/function-calling" rel="noopener noreferrer"&gt;OpenAI: Function calling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Anthropic: Building effective agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: Which actions in your product would you never let an agent take without approval?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>ux</category>
      <category>llm</category>
    </item>
    <item>
      <title>Connecting AI Agents to Real APIs Safely: Narrow Tools, Backend Auth, Clean Errors</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Wed, 18 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/connecting-ai-agents-to-real-apis-safely-narrow-tools-backend-auth-clean-errors-3gn4</link>
      <guid>https://dev.to/shaheryaryousaf/connecting-ai-agents-to-real-apis-safely-narrow-tools-backend-auth-clean-errors-3gn4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with one specific task and design a narrow tool contract for it.&lt;/li&gt;
&lt;li&gt;Keep identity, authorization and API keys in the backend, never in prompts or frontend code.&lt;/li&gt;
&lt;li&gt;Read tools and action tools need different levels of care.&lt;/li&gt;
&lt;li&gt;Avoid generic HTTP request tools, validate every argument and return only the data the task needs.&lt;/li&gt;
&lt;li&gt;A timeout on a mutating call is not proof of failure; use idempotency and check status.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Tool contracts, authorization, timeouts and the integration mistakes to avoid&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An AI assistant can explain what a calendar API does. An agent connected to that API could check availability, suggest a meeting time, and create an event after the user confirms. The connection between language model and outside system is what makes these experiences possible.&lt;/p&gt;

&lt;p&gt;For developers, “connect the agent to an API” involves more than giving a model an endpoint URL. You need to define a safe tool contract, validate arguments, enforce authorization, execute the request, handle failures, and return a useful result. The model may select and prepare a tool call, but your application should control how it runs.&lt;/p&gt;

&lt;p&gt;This beginner-friendly guide explains how to build AI agents that use APIs and external tools, with Python examples. We’ll use a read-only order lookup as the running example, then discuss how to add actions safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is an External Tool?
&lt;/h2&gt;

&lt;p&gt;A tool is a capability the application makes available to an agent. It might be a Python function, an internal service, or an external API. Examples include searching documentation, retrieving an order, checking calendar availability, or creating a task.&lt;/p&gt;

&lt;p&gt;A model does not necessarily call an external service directly. In a typical tool-calling flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The application describes available tools to the model.&lt;/li&gt;
&lt;li&gt;The model returns a request to call one tool with structured arguments.&lt;/li&gt;
&lt;li&gt;The application validates the request and calls its function or API.&lt;/li&gt;
&lt;li&gt;The application returns the result to the model.&lt;/li&gt;
&lt;li&gt;The model uses that result to answer or choose a next step.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;OpenAI’s &lt;a href="https://developers.openai.com/api/docs/guides/function-calling" rel="noopener noreferrer"&gt;function calling guide&lt;/a&gt; explains this application-mediated pattern. Tool formats vary by provider, but the key design principle remains: the model can request a capability; your code decides whether to execute it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start With a Specific Task
&lt;/h2&gt;

&lt;p&gt;Avoid starting with “connect my agent to our whole backend.” Pick one task with clear inputs and outputs. For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given an authenticated customer and an order number, return the order’s current shipping status.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This task is read-only. The user needs to be authenticated, the order number must be valid, and the result should include only information the customer is allowed to see. A narrow task is easier to test than a general-purpose tool that can query arbitrary records.&lt;/p&gt;

&lt;p&gt;Before implementation, define what should happen when the order is missing, belongs to a different customer, or the shipping service is unavailable. Those cases are part of the feature, not optional details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a Narrow Tool Contract
&lt;/h2&gt;

&lt;p&gt;A tool contract should tell the model what the tool does, when to use it, and which arguments it needs. Keep the schema narrow. Do not expose raw SQL, arbitrary URLs, or an unrestricted shell as a shortcut to flexibility.&lt;/p&gt;

&lt;p&gt;A conceptual definition might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"get_order_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Look up the shipping status of an order belonging to the signed-in customer."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"parameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"order_number"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"order_number"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The description supports tool selection, but it does not enforce access control. Your backend must identify the signed-in customer from the authenticated session. Do not trust a &lt;code&gt;customer_id&lt;/code&gt; supplied by the model as proof of identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Call the API From Python
&lt;/h2&gt;

&lt;p&gt;The model’s tool request should reach your application code, where arguments are checked and an API client performs the operation. Here is a simplified example using Python’s &lt;code&gt;requests&lt;/code&gt; library. The endpoint and response format are placeholders; adapt them to your service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;API_BASE_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ORDERS_API_BASE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;API_TOKEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ORDERS_API_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_order_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;order_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;order_number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;order_number&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A valid order number is required&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;API_BASE_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/orders/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;order_number&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;API_TOKEN&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;customer_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;customer_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Order not available to this customer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;order_number&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;order_number&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;estimated_delivery&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;estimated_delivery&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example reads credentials from environment variables rather than embedding secrets in source code. A production application should use its secret-management system, validate API responses, avoid returning unnecessary personal data, and map provider errors to safe user-facing messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Identity and Authorization in the Backend
&lt;/h2&gt;

&lt;p&gt;A model can help extract an order number from a conversation, but it should not decide who the user is. The application should use its authentication layer to identify the person and enforce record-level permissions.&lt;/p&gt;

&lt;p&gt;A safe flow looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Signed-in user → application obtains trusted user identity
                → model requests order lookup with an order number
                → backend validates order and user access
                → API returns allowed fields
                → model explains the result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never rely only on a prompt such as “do not reveal other customers’ orders.” Prompts can guide model behavior, but authorization needs to be enforced by software around the tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read Tools and Action Tools Need Different Care
&lt;/h2&gt;

&lt;p&gt;A read-only tool returns information. An action tool changes something: it may send an email, create a meeting, update a record, issue a refund, or purchase a product.&lt;/p&gt;

&lt;p&gt;For an action, consider whether to require confirmation. A calendar assistant can prepare an event and show the details before creating it. A support agent can draft a refund request and ask an authorized person to approve it. The backend should re-check permissions at the moment of execution, because approval and user state may have changed since the model prepared the request.&lt;/p&gt;

&lt;p&gt;For actions that could be retried, use idempotency keys or another duplicate-prevention method. A timeout does not always mean the remote service failed; it may have completed the action but lost the response. Retrying blindly could create duplicate events or charges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle API Errors and Timeouts
&lt;/h2&gt;

&lt;p&gt;External services can be slow, unavailable, or return unexpected data. Your application should define how to handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Timeouts:&lt;/strong&gt; stop waiting after a sensible duration and report the lookup could not be completed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rate limits:&lt;/strong&gt; respect retry guidance and avoid rapid repeated calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication failures:&lt;/strong&gt; refresh credentials where appropriate or fail safely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not found:&lt;/strong&gt; explain that no matching record exists, without inventing one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Malformed responses:&lt;/strong&gt; treat invalid data as an error rather than passing it to the model as fact.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partial data:&lt;/strong&gt; return what is verified and mark missing fields clearly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tool result should distinguish success, no match, and service failure. That gives the model enough information to respond accurately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Return Small, Useful Results
&lt;/h2&gt;

&lt;p&gt;Do not send an entire database row or API payload to the model if the user only needs a shipping status. Return the minimum useful fields. This reduces unnecessary exposure, limits prompt size, and makes the model’s task clearer.&lt;/p&gt;

&lt;p&gt;If the result contains a date, include its time zone or format. If a status is an internal code, translate it into a clear label before or while passing it to the model. Keep source timestamps when freshness matters so the assistant can communicate when the information was checked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the Complete Integration
&lt;/h2&gt;

&lt;p&gt;Test more than the API function. Verify how the model, application, and external service work together. Include cases where the user provides a valid order, a misspelled number, another customer’s order, or no order number. Simulate a timeout, rate limit, and malformed API response. For action tools, test unauthorized attempts, duplicate submissions, and cancellation after confirmation.&lt;/p&gt;

&lt;p&gt;For each case, inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether the right tool was selected.&lt;/li&gt;
&lt;li&gt;Whether arguments were validated.&lt;/li&gt;
&lt;li&gt;Whether the backend enforced access rules.&lt;/li&gt;
&lt;li&gt;Whether the API was called only when appropriate.&lt;/li&gt;
&lt;li&gt;Whether the result was summarized accurately.&lt;/li&gt;
&lt;li&gt;Whether failure was reported honestly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep logs useful for debugging, but minimize sensitive data. Record tool name, outcome, timing, and safe identifiers rather than full credentials or unnecessary personal information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Integration Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Putting API keys in prompts or frontend code
&lt;/h3&gt;

&lt;p&gt;Secrets belong in backend configuration or a secret manager. Never expose privileged credentials to the model or browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exposing a generic HTTP request tool
&lt;/h3&gt;

&lt;p&gt;An unrestricted URL and method tool can create security risks. Prefer purpose-built functions with fixed hosts, methods, and narrow parameters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trusting model arguments without validation
&lt;/h3&gt;

&lt;p&gt;Tool arguments are still external input. Check their type, length, allowed values, and authorization before using them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Returning too much data
&lt;/h3&gt;

&lt;p&gt;Only return what the task needs. A result can contain confidential fields that the model does not need to see or repeat.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating a timeout as proof of failure
&lt;/h3&gt;

&lt;p&gt;For a mutating action, the remote service might have completed it even if the response timed out. Use idempotency and reconcile the action status before retrying.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assuming prompts are access controls
&lt;/h3&gt;

&lt;p&gt;Application code must enforce identity, permissions, and business rules. Instructions to the model are not a substitute.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can an AI agent call any API?
&lt;/h3&gt;

&lt;p&gt;Only APIs and operations that the application exposes. It is better to provide narrow functions than a generic capability that can reach arbitrary services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should the model receive an API key?
&lt;/h3&gt;

&lt;p&gt;Usually no. The application should keep credentials server-side and call the service after validating the model’s request.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do APIs make an agent more useful?
&lt;/h3&gt;

&lt;p&gt;They let an agent retrieve current, application-specific information or request actions through software. The model can interpret a natural-language request while the application handles the service interaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should an agent be allowed to update a database?
&lt;/h3&gt;

&lt;p&gt;Only when the task needs it and the application can enforce suitable permissions, validation, and approval. Start with read-only access if that is enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens if an API is unavailable?
&lt;/h3&gt;

&lt;p&gt;The agent should report that it could not complete the lookup or action, and explain a sensible next step. It should not invent a successful result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Connecting an AI agent to APIs turns language understanding into useful application capabilities. The safest design keeps the model’s role clear: it interprets the user’s request and can ask for a tool, while the backend validates arguments, applies permissions, calls the external service, and returns only the relevant result.&lt;/p&gt;

&lt;p&gt;Start with one narrow, read-only tool. Add timeouts, error handling, authorization, and logging from the beginning. When you add actions, consider user confirmation and duplicate prevention. Treat tool calls as software operations that need the same careful design as any other backend feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/function-calling" rel="noopener noreferrer"&gt;OpenAI: Function calling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/tracks/building-agents" rel="noopener noreferrer"&gt;OpenAI: Building agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: What's the riskiest API you've considered handing to an agent?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>api</category>
      <category>security</category>
    </item>
    <item>
      <title>Multi-Agent Systems: When to Split Work Across Agents and When Not To</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Sat, 14 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/multi-agent-systems-when-to-split-work-across-agents-and-when-not-to-5nk</link>
      <guid>https://dev.to/shaheryaryousaf/multi-agent-systems-when-to-split-work-across-agents-and-when-not-to-5nk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Split work across agents for distinct tools or permissions, different instructions, independent subtasks or clear ownership.&lt;/li&gt;
&lt;li&gt;Manager pattern: one agent stays responsible and calls specialists. Handoff pattern: control transfers to a specialist.&lt;/li&gt;
&lt;li&gt;Multiple agents add cost, latency, error points, harder debugging and conflicting outputs.&lt;/li&gt;
&lt;li&gt;Keep each agent's permissions narrow and enforce authorization outside prompts.&lt;/li&gt;
&lt;li&gt;Start with one agent or a fixed workflow and split only when a measured problem calls for it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Manager and handoff patterns, plus the cost, debugging and security trade-offs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine asking an AI system to research a product category, compare several options, check current pricing, and prepare a recommendation. One agent could do the whole task. Or a system could assign research to one specialist, calculations to another, and final synthesis to a manager.&lt;/p&gt;

&lt;p&gt;This is a &lt;strong&gt;multi-agent system&lt;/strong&gt;: multiple agent instances or roles collaborate within an application. The idea sounds powerful, but it introduces new questions. Who decides which agent should work? How do they share information? Which one owns the final answer? How does the system detect conflicting or low-quality results?&lt;/p&gt;

&lt;p&gt;A multi-agent architecture is useful when separate roles make the work clearer or more manageable. It can be wasteful when a single agent or fixed workflow already handles the task well. This guide explains the trade-offs with a beginner-friendly example and a simple Python orchestration pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Multi-Agent System?
&lt;/h2&gt;

&lt;p&gt;A multi-agent system uses two or more agents to handle a task. Each agent may have its own instructions, tools, or area of responsibility. A coordinator may route work to specialists, combine results, or transfer control to a specialist that takes over the interaction.&lt;/p&gt;

&lt;p&gt;For a research report, roles might include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Research agent:&lt;/strong&gt; finds information from approved sources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analysis agent:&lt;/strong&gt; compares data and identifies trade-offs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review agent:&lt;/strong&gt; checks that claims are supported and required sections are present.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coordinator:&lt;/strong&gt; decides which work to request and prepares the final response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These roles can be implemented as separate model calls, separate agent configurations, or a combination of models and ordinary code. The important thing is the division of responsibility, not the number of model instances.&lt;/p&gt;

&lt;p&gt;OpenAI’s &lt;a href="https://developers.openai.com/api/docs/guides/agents/orchestration" rel="noopener noreferrer"&gt;orchestration and handoffs guide&lt;/a&gt; describes two common patterns: a manager can call specialists as bounded tools, or a handoff can transfer control so a specialist owns the next response. Anthropic’s &lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Building Effective Agents&lt;/a&gt; also discusses workflow patterns such as routing, parallelization, and evaluator loops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Split Work Across Agents?
&lt;/h2&gt;

&lt;p&gt;There are several reasons teams consider multiple agents:&lt;/p&gt;

&lt;h3&gt;
  
  
  Distinct tools or permissions
&lt;/h3&gt;

&lt;p&gt;A research role may need read-only search tools. A publishing role may need access to a content platform and require approval before posting. Separating responsibilities can make the permission boundary clearer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Different instructions
&lt;/h3&gt;

&lt;p&gt;A data extraction agent and a customer-facing writer need different output styles. Focused instructions can reduce confusion compared with one very broad prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Independent subtasks
&lt;/h3&gt;

&lt;p&gt;If three sources can be reviewed independently, separate workers may process them at the same time. A coordinator can then merge the results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clear ownership
&lt;/h3&gt;

&lt;p&gt;A billing specialist may need to take over a billing conversation. A handoff pattern can make it clear which agent now owns the next response.&lt;/p&gt;

&lt;p&gt;These benefits only matter if the roles are genuinely different. Creating several agents with nearly identical instructions and tools may add overhead without improving quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Manager Pattern
&lt;/h2&gt;

&lt;p&gt;In a manager-style design, one agent remains responsible for the user-facing answer. It calls specialists as tools, receives their bounded outputs, and synthesizes them.&lt;/p&gt;

&lt;p&gt;For example, a product-comparison manager might ask a research specialist to retrieve current plan details and a calculator function to compute team cost. The manager still checks whether the information is enough and writes the final recommendation.&lt;/p&gt;

&lt;p&gt;This pattern works well when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user should receive one coherent answer.&lt;/li&gt;
&lt;li&gt;Specialists perform bounded subtasks.&lt;/li&gt;
&lt;li&gt;The manager needs to compare or reconcile their results.&lt;/li&gt;
&lt;li&gt;You want one stable owner for the final response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The manager itself needs safeguards. It should not treat a specialist’s claim as automatically true. It may need source links, timestamps, confidence markers, or structured fields to verify the result.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Handoff Pattern
&lt;/h2&gt;

&lt;p&gt;In a handoff design, a routing agent transfers control to a specialist. That specialist then takes responsibility for the next stage of the conversation. A support assistant might route a billing issue to a billing agent, which asks follow-up questions and handles the case under its own instructions.&lt;/p&gt;

&lt;p&gt;A handoff is appropriate when the specialist should own the conversation rather than merely provide information behind the scenes. Make the routing conditions clear, and ensure the specialist receives only the context it needs.&lt;/p&gt;

&lt;p&gt;If a user’s request crosses specialties, the system needs a way to transfer or coordinate again. Avoid confusing users with internal agent changes. The user-facing experience should still feel like one service, even if several components collaborate behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Practical Example: Preparing a Market Brief
&lt;/h2&gt;

&lt;p&gt;Suppose a user asks for a short market brief comparing three project management products for a small design team. A multi-agent workflow might be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The coordinator extracts constraints: team size, needs, budget, and deadline.&lt;/li&gt;
&lt;li&gt;A research specialist finds current product and pricing information from approved sources.&lt;/li&gt;
&lt;li&gt;An analysis specialist calculates team costs and compares features.&lt;/li&gt;
&lt;li&gt;A reviewer checks whether each claim has evidence and whether the recommendation addresses the user’s requirements.&lt;/li&gt;
&lt;li&gt;The coordinator writes the final brief, noting missing or uncertain details.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This plan has several explicit contracts. The researcher returns source URLs and dates. The analyst receives structured data rather than vague prose. The reviewer checks a defined rubric. The coordinator owns the final response.&lt;/p&gt;

&lt;p&gt;A structured response might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"product"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Example Tool"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"monthly_price_per_user"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;12.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"team_size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"source_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/pricing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"checked_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-10-22"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"unknowns"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Annual discount terms"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contracts like this help reduce ambiguity between agents. They also make it easier to inspect outputs and identify which stage introduced an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Python Orchestration Pattern
&lt;/h2&gt;

&lt;p&gt;The following example uses placeholder functions to show the control flow. It is not tied to a particular provider SDK; real agent APIs have their own interfaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ResearchResult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;facts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;unknowns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_market_brief&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;requirements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extract_requirements&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;research&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ResearchResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;research_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;requirements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;constraints&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;requirements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;constraints&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;analysis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;analysis_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;facts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;research&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;facts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;team_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;requirements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;team_size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;review&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;review_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;draft&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;analysis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;sources&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;research&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;required_checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claims have sources&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unknowns are disclosed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;review&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;passed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I could not verify enough information to prepare a reliable brief.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;coordinator_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;research&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;research&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;analysis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;analysis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The central lesson is that the coordinator controls sequence and completion. Each specialist has a bounded job, and the application can reject a result that fails a review. For predictable tasks, some of these “agents” could be regular functions instead. For example, multiplying a per-user price by team size should be done with Python arithmetic, not delegated to a language model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sequential or Parallel Agents?
&lt;/h2&gt;

&lt;p&gt;Some subtasks depend on earlier results. For instance, analysis cannot compare products until research has identified them. That work should happen sequentially.&lt;/p&gt;

&lt;p&gt;Other subtasks may be independent. Separate researchers could inspect different products at the same time. Parallelism may reduce total waiting time, but it can increase the number of model calls and make synthesis more important. Agents may use inconsistent definitions or find conflicting values.&lt;/p&gt;

&lt;p&gt;Before running tasks in parallel, define:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What each worker is responsible for.&lt;/li&gt;
&lt;li&gt;Which sources or tools it may use.&lt;/li&gt;
&lt;li&gt;The expected output format.&lt;/li&gt;
&lt;li&gt;How the coordinator resolves conflicts.&lt;/li&gt;
&lt;li&gt;What happens when a worker fails or returns incomplete data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Parallel work is most effective when the subtasks are truly independent and the combined result can be checked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Agent Risks and Trade-Offs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  More cost and latency
&lt;/h3&gt;

&lt;p&gt;Every agent may add model calls, tool calls, and time. A request that took one response may become a chain of several operations. Measure the improvement against the added expense and wait time.&lt;/p&gt;

&lt;h3&gt;
  
  
  More places for errors
&lt;/h3&gt;

&lt;p&gt;A researcher can retrieve a wrong fact, an analyst can misinterpret it, and a coordinator can present it too confidently. Each handoff can lose context or meaning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Harder debugging
&lt;/h3&gt;

&lt;p&gt;A single-agent failure may be easier to inspect than a failure spread across four traces. Use clear logs and stable identifiers to connect the steps of one run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conflicting outputs
&lt;/h3&gt;

&lt;p&gt;Two specialists may disagree. The coordinator needs an explicit policy: verify against the source of truth, ask for human review, or disclose the uncertainty. It should not select whichever answer sounds more confident.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security and permission complexity
&lt;/h3&gt;

&lt;p&gt;Every agent toolset creates an access surface. Keep permissions narrow, enforce authorization outside prompts, and ensure retrieved context cannot silently change system rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Decide If You Need Multiple Agents
&lt;/h2&gt;

&lt;p&gt;Start with one agent or a fixed workflow. Measure where it struggles. Consider splitting only when a concrete issue appears, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The prompt has become difficult to maintain because roles conflict.&lt;/li&gt;
&lt;li&gt;Different tasks genuinely need different tools or permissions.&lt;/li&gt;
&lt;li&gt;Independent work can safely run in parallel.&lt;/li&gt;
&lt;li&gt;A specialist produces a materially better result on a bounded task.&lt;/li&gt;
&lt;li&gt;The application needs a clear ownership transfer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then compare the single-agent version and multi-agent version on the same evaluation set. Check accuracy, completion rate, latency, cost, tool selection, and failure handling. More agents are justified only if they improve the outcomes that matter enough to offset the coordination cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Are multiple agents always better than one?
&lt;/h3&gt;

&lt;p&gt;No. Additional agents add prompts, calls, coordination, and opportunities for error. A single agent or normal program may be simpler and more reliable for many tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between an agent handoff and calling an agent as a tool?
&lt;/h3&gt;

&lt;p&gt;When an agent is called as a tool, a manager usually stays responsible for the final response. A handoff transfers control to a specialist that owns the next part of the conversation. Choose based on who should own the user-facing interaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can multi-agent systems work in parallel?
&lt;/h3&gt;

&lt;p&gt;Yes, when subtasks are independent. The system still needs to combine results, handle disagreements, and verify important claims.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should every specialist be a separate model?
&lt;/h3&gt;

&lt;p&gt;Not necessarily. A specialist may be a distinct prompt or configuration using the same underlying model. Some tasks are better handled by a regular function or service.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I prevent agents from trusting incorrect outputs from one another?
&lt;/h3&gt;

&lt;p&gt;Use structured outputs, preserve sources, validate claims against authoritative data, and define how to handle uncertainty. A handoff does not make information trustworthy by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Multi-agent systems can help when a task benefits from distinct roles, separate permissions, or parallel work. A manager can call specialists while keeping ownership of the final response, or a handoff can transfer control to a specialist that should take over the conversation.&lt;/p&gt;

&lt;p&gt;Start with the simplest design that works. Add specialists only when their responsibilities are meaningfully different, define the information they exchange, and make the coordinator accountable for validation and completion. Measure the result against a single-agent or fixed-workflow baseline. The goal is not to maximize the number of agents; it is to deliver a clearer, more reliable outcome for the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents/orchestration" rel="noopener noreferrer"&gt;OpenAI: Orchestration and handoffs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/tracks/building-agents" rel="noopener noreferrer"&gt;OpenAI: Building agents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Anthropic: Building effective agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: Have you hit a task where one agent wasn't enough? What made you split it?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>architecture</category>
    </item>
    <item>
      <title>6 Planning Patterns for AI Agents and When Each One Fits</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Tue, 10 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/6-planning-patterns-for-ai-agents-and-when-each-one-fits-3ac3</link>
      <guid>https://dev.to/shaheryaryousaf/6-planning-patterns-for-ai-agents-and-when-each-one-fits-3ac3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start from the task, not from a popular reasoning pattern.&lt;/li&gt;
&lt;li&gt;Use a fixed workflow for predictable steps; consider model-generated plans when tasks vary.&lt;/li&gt;
&lt;li&gt;Other patterns: plan then execute, ReAct-style tool use, routing to specialists, parallel work, and draft-evaluate-revise.&lt;/li&gt;
&lt;li&gt;A plan is a proposal, not a guarantee, so validate actions and results.&lt;/li&gt;
&lt;li&gt;Set stopping conditions (max steps, time limits) and let code handle exact arithmetic and rules.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Fixed workflows, plan-then-execute, ReAct, routing, parallel work and draft-evaluate-revise&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ask an AI assistant to “research three project management tools, compare their pricing, and recommend one for a five-person team.” A one-sentence answer may sound confident, but the task involves several pieces: identify suitable products, find current pricing, compare plans, consider the team’s needs, and present a recommendation with caveats.&lt;/p&gt;

&lt;p&gt;This is where planning patterns can help. They give an agent a structure for turning a goal into manageable steps. They can also make an application easier to debug: you can see what steps were attempted, what information was used, and where the process failed.&lt;/p&gt;

&lt;p&gt;Planning does not make an agent infallible. A model may misunderstand the goal, skip an important step, or rely on poor data. Developers need to choose a pattern that fits the task and add checks around tools and outputs. In this beginner-friendly guide, we’ll cover practical reasoning patterns, use a research example, and show a simple Python approach to a predictable plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Planning in an AI Agent?
&lt;/h2&gt;

&lt;p&gt;Planning is the process of deciding what actions may be needed to reach a goal. An agent may decompose a request into subtasks, select tools, gather results, and decide whether it has enough information to finish.&lt;/p&gt;

&lt;p&gt;For a research task, a plan might be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the team’s requirements from the user’s request.&lt;/li&gt;
&lt;li&gt;Find three candidate products.&lt;/li&gt;
&lt;li&gt;Visit or query reliable sources for current pricing.&lt;/li&gt;
&lt;li&gt;Compare plans that support five users.&lt;/li&gt;
&lt;li&gt;Summarize trade-offs and state what could not be verified.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This plan is useful because it exposes the work behind the final recommendation. It also gives developers opportunities to validate inputs and constrain the agent. The system can require that pricing come from a source and include an “as of” date, for example.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developers.openai.com/tracks/building-agents" rel="noopener noreferrer"&gt;OpenAI guide to building agents&lt;/a&gt; describes orchestration as handling multiple steps, tool use, handoffs, guardrails, and context. Anthropic’s &lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Building Effective Agents&lt;/a&gt; distinguishes predefined workflows from more flexible agents. That distinction matters: not every task needs a model to invent its own sequence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start With the Task, Not a Reasoning Trend
&lt;/h2&gt;

&lt;p&gt;A common mistake is to choose a popular pattern first and then try to fit a problem into it. Start by examining the task:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are the steps predictable?&lt;/li&gt;
&lt;li&gt;Does the next step depend on information returned by the previous one?&lt;/li&gt;
&lt;li&gt;Can independent parts run at the same time?&lt;/li&gt;
&lt;li&gt;What mistakes would matter most?&lt;/li&gt;
&lt;li&gt;Does a human need to approve the outcome?&lt;/li&gt;
&lt;li&gt;How will the system know it is finished?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the steps are fixed, ordinary code may be the best planner. For example, an invoice-processing workflow could validate the invoice, retrieve the supplier record, check required fields, and route it for review in a fixed order. A model could help extract information from the document, but the application can control the sequence.&lt;/p&gt;

&lt;p&gt;Use a model-driven plan when the request varies enough that a fixed path is awkward, or when the agent must adapt based on retrieved information. Keep the model’s options bounded: define available tools, approval rules, and a clear stopping point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 1: A Fixed Workflow
&lt;/h2&gt;

&lt;p&gt;A fixed workflow follows steps selected by the developer. It is a strong fit for repeatable processes, such as generating a weekly report or checking an application form.&lt;/p&gt;

&lt;p&gt;A report workflow might be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Retrieve the latest sales data.&lt;/li&gt;
&lt;li&gt;Calculate totals and percentage changes in code.&lt;/li&gt;
&lt;li&gt;Ask the model to explain the results in plain language.&lt;/li&gt;
&lt;li&gt;Validate the required sections exist.&lt;/li&gt;
&lt;li&gt;Return a draft for review.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The benefit is predictability. If the task always follows the same route, the application can control the order and handle each failure explicitly. The trade-off is flexibility: a fixed workflow may be less convenient when users ask for a task that requires a different sequence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 2: Plan, Then Execute
&lt;/h2&gt;

&lt;p&gt;In a plan-and-execute pattern, the model first proposes a series of steps. The application or another model call then carries them out, often with tools. This is useful when tasks vary but can still be decomposed into a list of actions.&lt;/p&gt;

&lt;p&gt;For the software comparison, the agent may propose gathering product candidates, retrieving pricing, comparing user limits, and composing a recommendation. The application can inspect the plan before execution. It could reject steps that use unapproved sources, ask for clarification about budget, or require confirmation before creating an account.&lt;/p&gt;

&lt;p&gt;A plan is not inherently trustworthy. It may omit a necessary step or include one the application cannot perform. Validate each action against an allowlist and make tool results visible to the final synthesis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 3: ReAct-Style Tool Use
&lt;/h2&gt;

&lt;p&gt;A ReAct-style loop alternates between reasoning about the next step and taking an action, such as calling a search tool. The agent observes the result and decides what to do next.&lt;/p&gt;

&lt;p&gt;A simplified loop is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Goal → choose next action → call tool → inspect result
     → choose another action or provide final answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be more adaptive than planning every step up front. If the first search finds that a product has changed its pricing page, the agent can adjust its next query. But the loop can also be less predictable. It may make unnecessary calls or keep searching after it has enough evidence.&lt;/p&gt;

&lt;p&gt;For a production system, set limits on iterations, tool types, time, and cost. Log each tool request and result. Define conditions for asking the user a question or handing the task to a person.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 4: Routing and Specialists
&lt;/h2&gt;

&lt;p&gt;A router classifies a request and sends it to a suitable workflow or specialist. A support system might route billing issues to a billing process and technical questions to a troubleshooting process.&lt;/p&gt;

&lt;p&gt;Routing can make instructions clearer and reduce the number of tools available to each path. It can also misclassify requests. Include an “uncertain” route, test borderline examples, and make it easy to hand a case to a human.&lt;/p&gt;

&lt;p&gt;Specialists should have a distinct role. If two agents have the same tools and instructions, splitting them may only add complexity. Use specialists when the task genuinely needs different policies, tools, or expertise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 5: Parallel Work
&lt;/h2&gt;

&lt;p&gt;Some tasks can be divided into independent subtasks. For example, one process can collect pricing, another can compare collaboration features, and a third can check deployment options. The application can then combine the results.&lt;/p&gt;

&lt;p&gt;Parallel work can reduce waiting time or provide multiple perspectives, but it does not guarantee accuracy. The combined output needs a synthesis step that resolves disagreements and checks that sources support claims. Running several copies of a model on the same question can also multiply cost without adding useful diversity.&lt;/p&gt;

&lt;p&gt;Use parallelization when the subtasks are genuinely independent and the results can be merged through a clear contract. Keep outputs structured enough for the application to compare.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 6: Draft, Evaluate, Revise
&lt;/h2&gt;

&lt;p&gt;For tasks where quality can be checked against criteria, an agent can produce a draft, evaluate it, and revise it. A writing assistant might draft a report, check whether every claim has a source, and revise gaps.&lt;/p&gt;

&lt;p&gt;This pattern works best when the evaluator has concrete criteria. “Make it better” is vague. “Every pricing claim must include a current source; include at least two trade-offs; mark missing data as unknown” is easier to check.&lt;/p&gt;

&lt;p&gt;Even a separate evaluator model can make mistakes. For factual claims, use deterministic checks or verify against source material where possible. Avoid endless critique loops by setting a maximum number of revisions and a fallback when the draft still fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Python Example: A Predictable Research Plan
&lt;/h2&gt;

&lt;p&gt;For a beginner project, you can represent the stages in ordinary Python rather than asking a model to generate an open-ended plan. Here, the research functions are placeholders; a real app would connect them to approved data sources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;monthly_price_per_user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;source_url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;compare_tools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;team_size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;team_size&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;team_size must be at least 1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;comparisons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;monthly_price_per_user&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;team_size&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;monthly_price_per_user&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;comparisons&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;team_monthly_cost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source_url&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;price_verified&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source_url&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;comparisons&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code handles a repeatable calculation, while a model can help interpret the user’s criteria and explain trade-offs. Notice that missing prices remain &lt;code&gt;None&lt;/code&gt; instead of being guessed. This is a small example of a useful division of labor: models can help with language and flexible interpretation; ordinary code can perform exact calculations and enforce rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make Plans Observable and Testable
&lt;/h2&gt;

&lt;p&gt;A plan should help the developer understand what happened. Store or trace the steps at a level appropriate to your privacy policy: the selected tool, validated arguments, outcome, and reason for stopping. You do not need to expose private internal reasoning to users to make a system observable. A concise action log can explain that the agent checked three official pricing pages and found one plan without a public price.&lt;/p&gt;

&lt;p&gt;Build test cases for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear requests with enough information.&lt;/li&gt;
&lt;li&gt;Ambiguous goals that should trigger a question.&lt;/li&gt;
&lt;li&gt;Missing or conflicting tool results.&lt;/li&gt;
&lt;li&gt;A tool failure or timeout.&lt;/li&gt;
&lt;li&gt;Unsupported steps in a proposed plan.&lt;/li&gt;
&lt;li&gt;Requests that should require approval.&lt;/li&gt;
&lt;li&gt;Plans that exceed the allowed step limit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Evaluate the result, not just the plan text. Did the agent use reliable sources? Did it calculate correctly? Did it stop when enough evidence was available? Did it distinguish verified facts from assumptions?&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequent Planning Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Overplanning simple tasks
&lt;/h3&gt;

&lt;p&gt;If a task takes one function call, a long agent loop adds latency and failure opportunities. Use a direct call or fixed function when it is enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating a plan as a guarantee
&lt;/h3&gt;

&lt;p&gt;A plan is a proposal. It can change, fail, or be based on incorrect assumptions. Validate actions and results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Giving the agent too many choices
&lt;/h3&gt;

&lt;p&gt;A huge tool list makes selection harder and expands the testing surface. Offer only tools relevant to the current task.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forgetting stopping conditions
&lt;/h3&gt;

&lt;p&gt;Specify maximum steps, time limits, and conditions that trigger a final answer, clarification, or human handoff.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a model for exact arithmetic
&lt;/h3&gt;

&lt;p&gt;Let code handle totals, dates, eligibility, and other deterministic rules. The model can explain results but should not be the source of exact calculations when a program can compute them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does every AI agent need to make a plan?
&lt;/h3&gt;

&lt;p&gt;No. A simple agent may choose a tool and answer in one turn. Planning is useful when a task has multiple steps or dependencies, but it adds overhead and should be used when it improves the outcome.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is chain-of-thought the same as a plan?
&lt;/h3&gt;

&lt;p&gt;No. A plan is an actionable structure for completing a task. An application can show a concise plan or action summary without exposing private internal reasoning. Focus on observable actions and verifiable results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I use a fixed workflow or a model-generated plan?
&lt;/h3&gt;

&lt;p&gt;Use a fixed workflow when the steps are predictable. Consider a model-generated plan when the task varies and the model needs to choose among bounded options. Many systems combine both.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I keep an agent from looping?
&lt;/h3&gt;

&lt;p&gt;Set maximum tool calls, timeouts, and explicit completion conditions. Detect repeated calls where possible and provide a clear fallback when the agent cannot finish.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can multiple agents improve planning?
&lt;/h3&gt;

&lt;p&gt;They can help when specialists have distinct roles or when independent perspectives are valuable. They also add coordination, latency, and cost. Start with one agent and split only when the workflow benefits from separation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Planning patterns help an AI agent organize multi-step work, but no single pattern is best for every task. Fixed workflows offer control, plan-and-execute supports flexible decomposition, tool-use loops adapt to new results, and parallel or evaluator patterns can help with independent subtasks and quality checks.&lt;/p&gt;

&lt;p&gt;Choose the simplest approach that fits the task. Keep the agent’s tools and decisions bounded, use ordinary code for exact rules, set clear stopping conditions, and evaluate the full outcome. A useful plan is not the one that looks most sophisticated; it is the one that reliably helps the system reach a verifiable result.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/tracks/building-agents" rel="noopener noreferrer"&gt;OpenAI: Building agents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/agents/orchestration" rel="noopener noreferrer"&gt;OpenAI: Orchestration and handoffs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;Anthropic: Building effective agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: Which planning pattern does your current agent use, and is it more complex than the task needs?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Designing Memory for AI Agents: What to Keep, Retrieve, Expire and Forget</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Fri, 06 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/designing-memory-for-ai-agents-what-to-keep-retrieve-expire-and-forget-4a4o</link>
      <guid>https://dev.to/shaheryaryousaf/designing-memory-for-ai-agents-what-to-keep-retrieve-expire-and-forget-4a4o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR for devs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory is not one thing: separate working memory, conversation history, long-term facts and external knowledge.&lt;/li&gt;
&lt;li&gt;Save a memory only when it is likely to improve future work, and store provenance for inferred facts.&lt;/li&gt;
&lt;li&gt;Retrieval matters as much as storage; keep retrieved memory separate from instructions.&lt;/li&gt;
&lt;li&gt;Enforce user and tenant boundaries, and use structured queries rather than vector search for exact facts.&lt;/li&gt;
&lt;li&gt;Let current input override stale memory, and give users a way to review, correct and delete what is saved.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Working memory, history, long-term facts and external knowledge, with common mistakes&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You tell an AI assistant, “I prefer short status updates.” A few days later, you ask it to draft a project update. If it remembers your preference, it can respond in the style you like without asking again.&lt;/p&gt;

&lt;p&gt;That experience may feel like the agent has a human-like memory. In reality, an AI system’s “memory” is built from stored data and carefully selected context. The model can only use information that the application supplies to it in a given interaction.&lt;/p&gt;

&lt;p&gt;Designing memory for AI agents is therefore not just a matter of saving every conversation. Developers need to decide which information is useful, how long it remains relevant, how to retrieve it, and how to respect privacy. This guide explains the main memory patterns, practical design choices, and common mistakes to avoid.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does Memory Mean in an AI Agent?
&lt;/h2&gt;

&lt;p&gt;In an agent application, memory is information kept or derived from earlier interactions so it can help with later tasks. It may include recent conversation messages, a summary of a long conversation, stable preferences, facts about an ongoing project, results from past tasks, or references to stored documents.&lt;/p&gt;

&lt;p&gt;The model itself does not necessarily retain this information between API requests. The application may store messages in a database, maintain conversation state, write a summary, or retrieve relevant facts from a search index. At each step, it chooses what context to provide.&lt;/p&gt;

&lt;p&gt;OpenAI’s &lt;a href="https://developers.openai.com/api/docs/guides/conversation-state" rel="noopener noreferrer"&gt;conversation state guide&lt;/a&gt; explains ways applications can preserve information across turns. Anthropic’s article on &lt;a href="https://www.anthropic.com/research/effective-context-engineering-for-ai-agents" rel="noopener noreferrer"&gt;effective context engineering for AI agents&lt;/a&gt; emphasizes that developers must curate what enters the model’s limited context rather than treating all history as equally useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory Is Not One Thing
&lt;/h2&gt;

&lt;p&gt;It helps to separate memory into practical categories. The labels vary between systems, but the needs are common.&lt;/p&gt;

&lt;h3&gt;
  
  
  Short-term or working memory
&lt;/h3&gt;

&lt;p&gt;This is the context needed for the current task or active conversation. It can include recent messages, tool results, and the user’s current constraints. If someone asks an assistant to compare laptops, working memory might include the models discussed, their budget, and features they care about. This information may no longer matter after the decision is complete.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conversation history
&lt;/h3&gt;

&lt;p&gt;A transcript records what was said. It can be useful for continuity, audit, or showing previous messages. But a transcript is not necessarily a good prompt to send to a model in full. Long histories can contain outdated details, repetition, and irrelevant digressions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Long-term facts and preferences
&lt;/h3&gt;

&lt;p&gt;These are details that may remain useful across sessions, such as a preferred writing tone, a project’s name, or a user’s chosen time zone. They should be saved selectively because personal information creates privacy and maintenance responsibilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  External knowledge
&lt;/h3&gt;

&lt;p&gt;Documents, product catalogs, project records, and other source material may belong in a system of record or searchable knowledge base, rather than a user profile. The agent can retrieve relevant content when needed instead of copying everything into memory.&lt;/p&gt;

&lt;p&gt;These categories can coexist. The key is to know why each piece of information is stored and how it will be used.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Practical Example: Remembering Writing Preferences
&lt;/h2&gt;

&lt;p&gt;Suppose a writing assistant learns that a user prefers concise, professional language and headings in technical tutorials. A naive implementation might append every past conversation to every new request. That wastes context and may surface irrelevant personal details.&lt;/p&gt;

&lt;p&gt;A better design might store a small preference record:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WritingPreferences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;tone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;professional and friendly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;concise&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;include_headings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="n"&gt;include_examples_for_technical_topics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_article_context&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;preferences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;WritingPreferences&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Combine durable preferences with the user&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s current request.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;headings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Use clear headings.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;preferences&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;include_headings&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;
    &lt;span class="n"&gt;examples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Add practical examples for technical topics.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;preferences&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;include_examples_for_technical_topics&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Default tone: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;preferences&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tone&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;. &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;headings&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;examples&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;Current request: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simplified example: real applications would store preferences with an account identifier in a database and apply authorization checks. The point is to keep a small, editable record rather than replaying a full transcript.&lt;/p&gt;

&lt;p&gt;If the user says, “For this one, make it more detailed,” the current request should take precedence. A saved preference is a default, not an unchangeable rule. Users should also be able to inspect, correct, or delete stored preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide What Is Worth Remembering
&lt;/h2&gt;

&lt;p&gt;A system should not save a fact simply because it can. A memory is valuable when it is likely to improve future interactions enough to justify storing and maintaining it.&lt;/p&gt;

&lt;p&gt;Consider four questions before saving a candidate memory:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Will it be useful again?&lt;/strong&gt; A one-time delivery instruction may not need to persist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is it stable enough?&lt;/strong&gt; A temporary deadline becomes stale quickly; a preferred language may last longer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is it sensitive?&lt;/strong&gt; Health, financial, identity, and personal details require special care and may not need to be retained.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can the user understand and control it?&lt;/strong&gt; People should have a clear way to inspect, correct, or remove stored memory where appropriate.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can also make memories expire. A project deadline might be kept until the project closes. A temporary preference could expire after a set period. Expiration reduces the chance that old information will quietly influence a new answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retrieval Matters as Much as Storage
&lt;/h2&gt;

&lt;p&gt;A database full of saved facts does not help if the system cannot find the right one. Conversely, retrieving too many memories can make responses confusing or expose information irrelevant to the task.&lt;/p&gt;

&lt;p&gt;For small applications, structured fields can be enough. If you store a user’s preferred units or writing tone, retrieve those fields directly by user ID. For larger collections of notes or documents, semantic search can find content by meaning, while metadata filters can narrow results by owner, date, project, or access level.&lt;/p&gt;

&lt;p&gt;A practical retrieval flow might be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Determine what kind of information the current request needs.&lt;/li&gt;
&lt;li&gt;Search only the relevant memory store.&lt;/li&gt;
&lt;li&gt;Filter results by user, project, and permission.&lt;/li&gt;
&lt;li&gt;Rank results by relevance and recency.&lt;/li&gt;
&lt;li&gt;Include a small number of useful items in context.&lt;/li&gt;
&lt;li&gt;Tell the model how to treat the retrieved information and its source.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When information is consequential, query the authoritative system directly. Do not rely on a remembered account balance if the current value can be retrieved from a secure financial service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Memory Separate From Instructions
&lt;/h2&gt;

&lt;p&gt;Retrieved text can contain claims, outdated content, or hostile instructions. A document that says “ignore your previous rules” should not override application instructions merely because it was retrieved as memory.&lt;/p&gt;

&lt;p&gt;Keep the distinction clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System and developer instructions define how the assistant should behave.&lt;/li&gt;
&lt;li&gt;User requests describe what the person wants now.&lt;/li&gt;
&lt;li&gt;Memories and retrieved documents provide information that may be relevant.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent should treat stored content as data to consider, not as new authority. This is especially important when memory comes from user uploads, external websites, or shared team documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summarizing Long Conversations
&lt;/h2&gt;

&lt;p&gt;When a conversation becomes too long to fit comfortably into the model’s context, an application may summarize older turns. A useful summary preserves facts that still affect the task, decisions already made, unresolved questions, and relevant constraints.&lt;/p&gt;

&lt;p&gt;A weak summary may flatten important distinctions. “The user chose the blue design” is misleading if the user only said they were considering it. A better summary preserves uncertainty and attribution: “The user is considering the blue design but has not decided.”&lt;/p&gt;

&lt;p&gt;You can give summaries a structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Goal:
Decisions confirmed:
Preferences:
Open questions:
Important constraints:
Sources or records to re-check:
Last updated:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Retain references to original messages or source records where possible. A summary is a convenient index, not always a trustworthy replacement for the underlying data. If an exact amount, date, or approval matters, retrieve and verify it from the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Memory Design Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Saving everything forever
&lt;/h3&gt;

&lt;p&gt;This increases storage, privacy exposure, and the chance of retrieving outdated or irrelevant information. Use retention rules, deletion controls, and scoped storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treating a guess as a fact
&lt;/h3&gt;

&lt;p&gt;Models can infer preferences from behavior, but an inference may be wrong. Store provenance and confidence where useful, or ask the user before turning an uncertain guess into a persistent profile item.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mixing users or projects
&lt;/h3&gt;

&lt;p&gt;Memory retrieval must enforce tenant and user boundaries. A missing filter can expose one person’s information to another. Authorization belongs in the retrieval layer, not only in a prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using semantic search for exact facts
&lt;/h3&gt;

&lt;p&gt;Vector search helps find related text, but exact identifiers, dates, amounts, and status values often need structured queries against a source of truth.&lt;/p&gt;

&lt;h3&gt;
  
  
  Letting stale memory override current input
&lt;/h3&gt;

&lt;p&gt;If a current instruction conflicts with an old default preference, use the current instruction for the present request. Provide a path for updating the long-term preference too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forgetting deletion and correction
&lt;/h3&gt;

&lt;p&gt;If users can ask an agent to remember information, they should have a clear way to review and remove it. Deletion may need to cover derived summaries and indexes, not just the original record.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Evaluate Agent Memory
&lt;/h2&gt;

&lt;p&gt;Memory quality can be tested. Create example conversations with facts that should be saved, facts that should not be saved, details that later change, and requests to forget information. Then check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did the system store only what its policy allows?&lt;/li&gt;
&lt;li&gt;Did it retrieve relevant memory for a later task?&lt;/li&gt;
&lt;li&gt;Did it ignore unrelated memories?&lt;/li&gt;
&lt;li&gt;Did it honor a newer instruction over an old preference?&lt;/li&gt;
&lt;li&gt;Did it preserve uncertainty and source attribution?&lt;/li&gt;
&lt;li&gt;Did deletion remove information from all relevant stores?&lt;/li&gt;
&lt;li&gt;Did access controls prevent cross-user or cross-project retrieval?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Track usefulness and mistakes. A system that remembers many details may seem personalized, but it can still perform poorly if it retrieves the wrong ones or cannot explain why a detail appeared.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do AI agents automatically remember past conversations?
&lt;/h3&gt;

&lt;p&gt;Not necessarily. The application needs to preserve conversation state or store information in a memory system, then provide relevant context in future interactions. The details depend on the platform and design.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is chat history the same as agent memory?
&lt;/h3&gt;

&lt;p&gt;No. A transcript is a record of messages. Memory usually refers to selected or processed information used to support later tasks. An application may retain a transcript without sending all of it to the model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should an agent remember personal preferences?
&lt;/h3&gt;

&lt;p&gt;It can, if the preference is useful and the user understands and can control the feature. Store only what is needed, protect it appropriately, and avoid treating inferred preferences as certain facts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I use a vector database for memory?
&lt;/h3&gt;

&lt;p&gt;Not automatically. Structured settings and exact records often belong in a regular database. A vector index can help search large collections of unstructured text by meaning. Some applications use both.&lt;/p&gt;

&lt;h3&gt;
  
  
  How can a user correct an agent’s memory?
&lt;/h3&gt;

&lt;p&gt;Provide a clear way to view, update, or remove saved information. Update the authoritative record and any derived summaries or indexes that could continue to surface the old value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Memory makes an AI agent more useful when it helps the system carry relevant context from one task to another. But reliable memory is not unlimited recall. It is a deliberate design that selects what to store, retrieves only what matters, preserves sources and uncertainty, and respects user control.&lt;/p&gt;

&lt;p&gt;Begin with a small set of clearly defined memories, such as explicit preferences or active project facts. Keep authoritative data in the systems that own it, set retention rules, enforce access controls, and test what happens when information changes or should be forgotten. A thoughtful memory design can make an agent feel continuous and helpful without treating every past detail as permanent or relevant.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/guides/conversation-state" rel="noopener noreferrer"&gt;OpenAI: Conversation state&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/effective-context-engineering-for-ai-agents" rel="noopener noreferrer"&gt;Anthropic: Effective context engineering for AI agents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/tracks/building-agents" rel="noopener noreferrer"&gt;OpenAI: Building agents&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: Which memory should your agent keep, and what should it forget?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Why LLMs Alone Are Not Agents</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Sat, 21 Feb 2026 08:54:32 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/why-llms-alone-are-not-agents-342e</link>
      <guid>https://dev.to/shaheryaryousaf/why-llms-alone-are-not-agents-342e</guid>
      <description>&lt;p&gt;Large language models are powerful, but calling them “agents” on their own is a category mistake. This confusion shows up constantly in real projects, especially when people expect a single prompt to behave like a system that can reason, act, and adapt.&lt;/p&gt;

&lt;p&gt;If you’ve built anything beyond a demo, you’ve likely hit this wall already.&lt;/p&gt;

&lt;p&gt;This article explains why LLMs alone are not agents, what’s missing, and where the responsibility actually lies when building agentic systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an LLM Actually Does
&lt;/h2&gt;

&lt;p&gt;At its core, an LLM performs one job:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Given a sequence of tokens, predict the next token.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything else—reasoning, planning, explanation—is an &lt;em&gt;emergent behavior&lt;/em&gt; of that process.&lt;/p&gt;

&lt;p&gt;Important constraints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The model has no memory beyond the prompt&lt;/li&gt;
&lt;li&gt;It has no awareness of outcomes&lt;/li&gt;
&lt;li&gt;It cannot observe the world unless you feed it observations&lt;/li&gt;
&lt;li&gt;It cannot act unless you explicitly wire actions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An LLM doesn’t “decide” to do something. It produces text that &lt;em&gt;describes&lt;/em&gt; a decision when asked.&lt;/p&gt;

&lt;p&gt;That distinction matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Fails in Real Systems
&lt;/h2&gt;

&lt;p&gt;When people treat an LLM as an agent, they usually expect it to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decide what to do next&lt;/li&gt;
&lt;li&gt;Verify its own outputs&lt;/li&gt;
&lt;li&gt;Recover from mistakes&lt;/li&gt;
&lt;li&gt;Adapt to new information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But none of those happen automatically.&lt;/p&gt;

&lt;p&gt;An LLM will happily generate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A plan it never executes&lt;/li&gt;
&lt;li&gt;A correction without knowing it failed&lt;/li&gt;
&lt;li&gt;A confident answer with missing data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because it has no feedback loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Missing Ingredient: Control Flow
&lt;/h2&gt;

&lt;p&gt;Agency comes from &lt;strong&gt;control flow&lt;/strong&gt;, not from language generation.&lt;/p&gt;

&lt;p&gt;An agent needs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A goal&lt;/li&gt;
&lt;li&gt;A loop&lt;/li&gt;
&lt;li&gt;Actions&lt;/li&gt;
&lt;li&gt;State&lt;/li&gt;
&lt;li&gt;Feedback&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An LLM provides &lt;em&gt;none&lt;/em&gt; of these by default.&lt;/p&gt;

&lt;p&gt;When you prompt a model to “think step by step,” you’re not giving it agency—you’re just asking it to &lt;em&gt;simulate reasoning in text&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Once the output is produced, the model is done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Planning Is Not Acting
&lt;/h2&gt;

&lt;p&gt;A common trap is equating planning with agency.&lt;/p&gt;

&lt;p&gt;You ask the model:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Plan how to solve this problem.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It produces a clean, multi-step plan.&lt;/p&gt;

&lt;p&gt;But nothing happens.&lt;/p&gt;

&lt;p&gt;The model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Doesn’t execute the steps&lt;/li&gt;
&lt;li&gt;Doesn’t check if a step succeeded&lt;/li&gt;
&lt;li&gt;Doesn’t revise the plan based on results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without execution and observation, a plan is just text.&lt;/p&gt;

&lt;p&gt;Real agents operate in a loop where each step changes the world—or at least the system state—and the next decision depends on that change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tool Calling Doesn’t Automatically Create an Agent
&lt;/h2&gt;

&lt;p&gt;Even with tool calling or function calling, an LLM is still not an agent on its own.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because the model does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decide when to stop&lt;/li&gt;
&lt;li&gt;Enforce constraints&lt;/li&gt;
&lt;li&gt;Validate tool outputs&lt;/li&gt;
&lt;li&gt;Retry intelligently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those behaviors must be implemented &lt;em&gt;around&lt;/em&gt; the model.&lt;/p&gt;

&lt;p&gt;The LLM can suggest actions.&lt;br&gt;
Your system must decide whether they’re allowed and what happens next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Developers Usually Misplace Responsibility
&lt;/h2&gt;

&lt;p&gt;The most common architectural mistake is expecting the model to manage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;li&gt;Retries&lt;/li&gt;
&lt;li&gt;Costs&lt;/li&gt;
&lt;li&gt;Safety&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;LLMs are not state machines.&lt;br&gt;
They are not schedulers.&lt;br&gt;
They are not supervisors.&lt;/p&gt;

&lt;p&gt;When systems fail, it’s usually because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There’s no max-step limit&lt;/li&gt;
&lt;li&gt;There’s no failure mode defined&lt;/li&gt;
&lt;li&gt;The agent keeps “thinking” without progress&lt;/li&gt;
&lt;li&gt;No one can explain why a decision was made&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s not an AI problem. It’s a system design problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Actually Turns an LLM Into an Agent
&lt;/h2&gt;

&lt;p&gt;An LLM becomes part of an agent &lt;strong&gt;only when embedded inside a loop&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That loop must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide observations&lt;/li&gt;
&lt;li&gt;Accept decisions&lt;/li&gt;
&lt;li&gt;Execute actions&lt;/li&gt;
&lt;li&gt;Update state&lt;/li&gt;
&lt;li&gt;Decide when to stop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent is the loop.&lt;br&gt;
The LLM is just one component inside it.&lt;/p&gt;

&lt;p&gt;Once you see this clearly, the hype disappears and the engineering work becomes obvious.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Useful Mental Shift
&lt;/h2&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Can the model do this?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What decisions am I allowing the model to influence?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This reframing forces you to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boundaries&lt;/li&gt;
&lt;li&gt;Permissions&lt;/li&gt;
&lt;li&gt;Failure modes&lt;/li&gt;
&lt;li&gt;Debuggability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And it keeps systems stable.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Short Closing Thought
&lt;/h2&gt;

&lt;p&gt;LLMs are powerful reasoning engines, but agency does not come from intelligence alone. It comes from structure, feedback, and limits.&lt;/p&gt;

&lt;p&gt;Treat models as components, not actors.&lt;/p&gt;

&lt;p&gt;The moment you do, agentic systems stop feeling magical—and start feeling buildable.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Agentic AI vs Chatbots vs Automation: What’s Actually Different in Practice</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Fri, 20 Feb 2026 09:16:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/agentic-ai-vs-chatbots-vs-automation-whats-actually-different-in-practice-4k85</link>
      <guid>https://dev.to/shaheryaryousaf/agentic-ai-vs-chatbots-vs-automation-whats-actually-different-in-practice-4k85</guid>
      <description>&lt;p&gt;These three terms—&lt;strong&gt;chatbots&lt;/strong&gt;, &lt;strong&gt;automation&lt;/strong&gt;, and &lt;strong&gt;agentic AI&lt;/strong&gt;—are often used interchangeably. In real systems, they are fundamentally different patterns with different trade-offs, failure modes, and engineering costs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdegvcyl2rs3b2tpbcsdk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdegvcyl2rs3b2tpbcsdk.png" alt="Agentic AI vs Chatbots vs Automation" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re building production software, confusing them leads to overengineering, unstable systems, or expensive solutions where a simple one would’ve worked better.&lt;/p&gt;

&lt;p&gt;This article breaks down how they differ &lt;em&gt;in practice&lt;/em&gt;, not in marketing definitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chatbots: Single-Step Reasoning With No Ownership
&lt;/h2&gt;

&lt;p&gt;A chatbot is the simplest form of AI integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;User sends input&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Model generates a response&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The interaction ends&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even when a chatbot uses retrieval (RAG), tools, or function calling, the structure remains the same:&lt;strong&gt;one input → one output&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There is no internal decision loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What chatbots are good at&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Answering questions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explaining concepts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Drafting content&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Summarizing or rewriting text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Acting as a conversational UI for humans&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What breaks quickly&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multi-step tasks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conditional workflows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error recovery&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tasks where the model must “check its own work”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once a chatbot gives an answer, it’s done. It doesn’t evaluate correctness, retry, or adapt unless the user manually pushes it.&lt;/p&gt;

&lt;p&gt;That’s not a limitation of intelligence—it’s a limitation of control flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation: Deterministic Systems With Fixed Paths
&lt;/h2&gt;

&lt;p&gt;Automation lives at the opposite end of the spectrum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A trigger fires&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Predefined steps execute&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The flow ends&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every decision is encoded ahead of time.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cron jobs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CI/CD pipelines&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Zapier or n8n workflows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rule-based alerting systems&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ETL pipelines&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What automation excels at&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reliability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Predictability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Speed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auditing and debugging&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If something fails, you know exactly where and why.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where automation struggles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ambiguous inputs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unstructured data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Situations where the “right” next step depends on context&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial or noisy information&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automation can’t reason. It can only follow instructions. When reality deviates from assumptions, automation either fails or silently produces wrong results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agentic AI: Decision Loops, Not Smarter Models
&lt;/h2&gt;

&lt;p&gt;Agentic AI sits between chatbots and automation.&lt;/p&gt;

&lt;p&gt;The key distinction is &lt;strong&gt;ownership of the next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How an agentic system works&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Observe current state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decide what to do next&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Execute an action&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Evaluate the result&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat until a condition is met&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The AI does not just respond—it &lt;strong&gt;chooses actions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Important detail:The intelligence still comes from the model.The &lt;em&gt;agency&lt;/em&gt; comes from the system design.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Concrete Comparison
&lt;/h2&gt;

&lt;p&gt;Let’s use the same task across all three patterns.&lt;/p&gt;

&lt;h3&gt;
  
  
  Task: “Answer a question using company documents”
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chatbot&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Retrieve documents&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Send them to the model&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return answer&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the answer is incomplete or wrong, the user has to intervene.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Always retrieve from the same source&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always apply the same filters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always format the same response&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Works only if the task is fully predictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic AI&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Decide if documents are needed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose which sources to query&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Evaluate relevance of retrieved chunks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retry if confidence is low&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare conflicting sources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then answer&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same data. Same model.Different control structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why “Agentic” Is Not Just Fancy Automation
&lt;/h2&gt;

&lt;p&gt;A common mistake is calling any AI-powered workflow “agentic”.&lt;/p&gt;

&lt;p&gt;If the steps are fixed, it’s still automation—even if an LLM is involved.&lt;/p&gt;

&lt;p&gt;The moment a system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chooses between multiple possible actions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adjusts behavior based on outcomes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can fail, recover, and continue without user input&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You’re in agentic territory.&lt;/p&gt;

&lt;p&gt;This flexibility comes at a cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Breaks First in Agentic Systems
&lt;/h2&gt;

&lt;p&gt;Agentic systems fail in predictable ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Infinite or Wasteful Loops
&lt;/h3&gt;

&lt;p&gt;Without hard limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Max steps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Max cost&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Confidence thresholds&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Agents will keep going because they technically can.&lt;/p&gt;

&lt;p&gt;Guardrails are not optional.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Overexposed Tools
&lt;/h3&gt;

&lt;p&gt;Giving an agent access to too many actions early leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unintended side effects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hard-to-debug behavior&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security risks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Agents should earn capabilities gradually.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Opaque State
&lt;/h3&gt;

&lt;p&gt;If you can’t inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What the agent knew&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why it chose an action&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What alternatives existed&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You won’t be able to debug failures.&lt;/p&gt;

&lt;p&gt;Observability matters more than prompts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the Right Pattern (Most People Overreach)
&lt;/h2&gt;

&lt;p&gt;Here’s the practical rule most teams learn the hard way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a chatbot&lt;/strong&gt; when the user is in control and correctness isn’t mission-critical.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use automation&lt;/strong&gt; when the steps are known and repeatable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use agentic AI&lt;/strong&gt; only when the path to the goal is genuinely dynamic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can express the logic as a flowchart, you probably don’t need an agent.&lt;/p&gt;

&lt;p&gt;If you can’t predict the next step until you see the result of the previous one, automation alone won’t cut it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Mental Model That Helps
&lt;/h2&gt;

&lt;p&gt;Think of these patterns as increasing levels of responsibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chatbots: &lt;em&gt;Answering&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automation: &lt;em&gt;Executing&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Agentic AI: &lt;em&gt;Deciding&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model doesn’t become “smarter” as you move up this ladder.You simply allow it to influence more of the system.&lt;/p&gt;

&lt;p&gt;That decision should always be intentional.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Short Closing Thought
&lt;/h2&gt;

&lt;p&gt;Agentic AI isn’t a replacement for chatbots or automation. It’s a different tool with a higher engineering cost and a narrower set of problems it solves well.&lt;/p&gt;

&lt;p&gt;The real skill isn’t knowing how to build agents—it’s knowing &lt;strong&gt;when not to&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That judgment matters more than any framework or prompt ever will.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>automation</category>
      <category>llm</category>
    </item>
    <item>
      <title>What “Agentic AI” Actually Means (In Practice)</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Thu, 19 Feb 2026 07:50:00 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/what-agentic-ai-actually-means-in-practice-14ih</link>
      <guid>https://dev.to/shaheryaryousaf/what-agentic-ai-actually-means-in-practice-14ih</guid>
      <description>&lt;p&gt;“Agentic AI” is one of those terms that sounds impressive but becomes vague the moment you try to implement it. In real systems, the confusion usually comes from treating agents as a feature rather than as a system behavior.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffz7afjynwd3kjsva0ym2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffz7afjynwd3kjsva0ym2.png" alt="What “Agentic AI” Actually Means" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article explains what agentic AI actually means from a builder’s perspective: how it behaves, how it’s wired, what breaks first, and where the real complexity lives.&lt;/p&gt;

&lt;p&gt;No theory-heavy framing. Just how these systems work in practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Idea: Agency Is About Control Flow, Not Intelligence
&lt;/h2&gt;

&lt;p&gt;At its simplest, &lt;strong&gt;agentic AI refers to systems where an AI model can decide what to do next&lt;/strong&gt;, rather than being limited to a single prompt → response cycle.&lt;/p&gt;

&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;Not autonomy in a human sense.Not “thinking for itself.”Not replacing developers.&lt;/p&gt;

&lt;p&gt;Agency is about &lt;strong&gt;control flow&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In a non-agentic system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You ask a question&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The model answers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The process ends&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In an agentic system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The model evaluates a goal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chooses an action&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Observes the result&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decides the next step&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeats until a condition is met&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The intelligence comes from the model, but the &lt;em&gt;agency&lt;/em&gt; comes from how you structure decisions and feedback loops around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Makes a System “Agentic”
&lt;/h2&gt;

&lt;p&gt;In practice, agentic systems usually have four moving parts:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. A Goal (Explicit or Implied)
&lt;/h3&gt;

&lt;p&gt;Agents operate toward something:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“Answer this question using documents”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Fix the failing test”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Summarize new support tickets daily”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If there’s no goal, there’s no agent—just a chatbot.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. A Decision Loop
&lt;/h3&gt;

&lt;p&gt;This is the defining trait.&lt;/p&gt;

&lt;p&gt;Instead of one LLM call, you have a loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Observe state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decide next action&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Execute action&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This loop can be short (2–3 steps) or long-running. Most real systems should be short.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Tools or Actions
&lt;/h3&gt;

&lt;p&gt;Agents don’t just generate text. They &lt;em&gt;do things&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Call APIs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query databases&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search documents&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Trigger workflows&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If an “agent” can’t act, it’s just a planner generating text.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Memory or State
&lt;/h3&gt;

&lt;p&gt;Agents need context beyond a single prompt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Previous steps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tool outputs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial results&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constraints&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can be as simple as a JSON state object or as complex as a vector store. The complexity grows fast if you’re not careful.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Practical Example: Document Q&amp;amp;A vs Agentic Q&amp;amp;A
&lt;/h2&gt;

&lt;p&gt;Let’s ground this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-Agentic Version
&lt;/h3&gt;

&lt;p&gt;You build a RAG system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;User asks a question&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You retrieve documents&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You send them to the LLM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You return an answer&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This works fine for most cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agentic Version
&lt;/h3&gt;

&lt;p&gt;Now imagine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The model first decides whether it needs documents at all&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If yes, it decides which source to search&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It evaluates the retrieved chunks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If confidence is low, it searches again&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If sources conflict, it compares them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then it answers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same model. Same data.&lt;/p&gt;

&lt;p&gt;The difference is &lt;strong&gt;decision authority&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But here’s the key insight:&lt;strong&gt;The agent doesn’t magically know how to do this—you explicitly allow it to.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Things Usually Break
&lt;/h2&gt;

&lt;p&gt;Most agentic systems fail not because the model is weak, but because the &lt;em&gt;system design is sloppy&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Unbounded Loops
&lt;/h3&gt;

&lt;p&gt;If you don’t enforce:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Step limits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cost limits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Confidence thresholds&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your agent will happily keep going forever.&lt;/p&gt;

&lt;p&gt;Always cap iterations.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Overpowered Agents
&lt;/h3&gt;

&lt;p&gt;Giving an agent too many tools early on creates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unpredictable behavior&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hard-to-debug flows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security risks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start with one or two actions. Add more only when needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Vague Instructions
&lt;/h3&gt;

&lt;p&gt;“Decide the best next step” is not enough.&lt;/p&gt;

&lt;p&gt;Agents need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clear action schemas&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strict output formats&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explicit failure handling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ambiguity compounds with every step.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Memory Bloat
&lt;/h3&gt;

&lt;p&gt;Storing everything “just in case” kills performance and clarity.&lt;/p&gt;

&lt;p&gt;Agents don’t need perfect memory.They need &lt;strong&gt;relevant state&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agentic AI Is Not the Same as Automation
&lt;/h2&gt;

&lt;p&gt;This is another common misconception.&lt;/p&gt;

&lt;p&gt;Automation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Predefined rules&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fixed flows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deterministic behavior&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Agentic AI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dynamic decisions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Context-sensitive actions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Probabilistic outcomes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An agent might &lt;em&gt;trigger&lt;/em&gt; automations, but it’s not the same thing.&lt;/p&gt;

&lt;p&gt;Think of agents as &lt;strong&gt;decision-makers inside automated systems&lt;/strong&gt;, not replacements for them.&lt;/p&gt;

&lt;h2&gt;
  
  
  When You Actually Need an Agent (And When You Don’t)
&lt;/h2&gt;

&lt;p&gt;You probably &lt;em&gt;don’t&lt;/em&gt; need an agent if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The task is linear&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The steps are always the same&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The failure modes are simple&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A standard pipeline will be faster, cheaper, and more reliable.&lt;/p&gt;

&lt;p&gt;You &lt;em&gt;might&lt;/em&gt; need an agent if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The path to the goal changes per input&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need conditional reasoning&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The system must recover from partial failure&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You don’t know all steps upfront&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Agents shine in &lt;strong&gt;messy, semi-structured problems&lt;/strong&gt;, not clean ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Engineering Challenge
&lt;/h2&gt;

&lt;p&gt;The hardest part of agentic AI is not prompts.&lt;/p&gt;

&lt;p&gt;It’s:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;State management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Observability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debugging decisions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reproducibility&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When an agent fails, you need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Why it chose a step&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What information it saw&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What alternative actions were possible&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can’t inspect that, you don’t have an agent—you have a black box.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Useful Mental Model
&lt;/h2&gt;

&lt;p&gt;If you’re building agentic systems, stop thinking in terms of “smart AI” and start thinking in terms of:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State machines with probabilistic transitions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The LLM proposes transitions.Your system decides whether they’re allowed.&lt;/p&gt;

&lt;p&gt;That framing alone will save you weeks of confusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Short Closing Thought
&lt;/h2&gt;

&lt;p&gt;Agentic AI isn’t about making models more powerful.It’s about &lt;strong&gt;giving models controlled responsibility inside well-defined systems&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The moment you treat agency as a system design problem—not a model capability—the term stops being mysterious and starts being usable.&lt;/p&gt;

&lt;p&gt;That’s where real progress happens.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Firebase Studio: A Gemini-Powered Environment to Accelerate AI App Development</title>
      <dc:creator>Shaheryar Yousaf</dc:creator>
      <pubDate>Thu, 10 Apr 2025 00:10:59 +0000</pubDate>
      <link>https://dev.to/shaheryaryousaf/--241g</link>
      <guid>https://dev.to/shaheryaryousaf/--241g</guid>
      <description>&lt;p&gt;Google has unveiled Firebase Studio, a groundbreaking cloud-based development environment designed to streamline the creation of full-stack AI applications. This innovative platform integrates seamlessly with Firebase services and leverages the power of Gemini AI to provide a comprehensive, agentic workspace accessible from anywhere.&lt;/p&gt;

&lt;p&gt;Key Features of Firebase Studio:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rapid Prototyping with Multimodal Inputs:&lt;/strong&gt; Quickly prototype AI applications using natural language, images, and drawing tools, facilitating a more intuitive development process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI-Powered Iteration:&lt;/strong&gt; Engage in real-time AI chat interactions to refine and enhance your applications, making the development cycle more efficient.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Code Integration:&lt;/strong&gt; Transition effortlessly between visual prototyping and code, providing flexibility for developers to dive into the codebase whenever necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Instant Preview Across Devices:&lt;/strong&gt; Instantly preview your applications on various devices, ensuring a consistent and responsive user experience across platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficient Publishing with Firebase App Hosting:&lt;/strong&gt; Deploy your applications swiftly using Firebase App Hosting, simplifying the path from development to production.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Collaboration:&lt;/strong&gt; Share and collaborate on projects in real-time, enhancing teamwork and productivity within development teams. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This launch marks a significant advancement in AI application development, offering developers an integrated environment to prototype, build, and manage applications with unprecedented ease and speed.&lt;/p&gt;

&lt;p&gt;For a comprehensive overview and to get started with Firebase Studio, visit the official announcement here: &lt;a href="https://firebase.blog/posts/2025/04/introducing-firebase-studio/" rel="noopener noreferrer"&gt;https://firebase.blog/posts/2025/04/introducing-firebase-studio/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>firebase</category>
      <category>google</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
