[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"post:\u002Fpost\u002Ffrom-chaos-to-production-how-to-orchestrate-deterministic-agents-with-vercel-ai-sdk":3,"categories-en":573},{"post":4,"related":502,"translations":571,"resolved":17},{"id":5,"slug":6,"title":7,"excerpt":8,"image":9,"featured":10,"groupId":11,"publishedAt":12,"readingTime":13,"views":14,"author":15,"category":18,"tags":22,"contentJson":35,"metaTitle":499,"metaDescription":500,"updatedAt":501},"411dbae1-b129-4cb0-85fc-59f4faab7685","from-chaos-to-production-how-to-orchestrate-deterministic-agents-with-vercel-ai-sdk","From Chaos to Production: How to Orchestrate Deterministic Agents with Vercel AI SDK","Discover how to orchestrate AI agents professionally using universal connectors, Zod-typed outputs, and tool calling for real-world systems.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1781939447970-featured-xd9lsb.webp",false,"5e388549-d08d-4eaf-b505-667f6e00718e","2026-06-20T08:10:10.066533+00:00",10,0,{"name":16,"avatar":17},"Genildo Souza",null,{"slug":19,"name":20,"color":21},"inteligencia-artificial","Artificial Intelligence","#6366f1",[23,26,29,32],{"slug":24,"name":25},"ai","AI",{"slug":27,"name":28},"claude","Claude",{"slug":30,"name":31},"llm","LLM",{"slug":33,"name":34},"openai","OpenAI",{"type":36,"content":37},"doc",[38,49,57,63,69,71,79,85,91,106,112,125,134,146,152,158,170,188,195,201,207,213,226,256,263,318,324,330,336,342,348,360,367,373,379,385,407,418,424,454,460,466,472,478,484,490,491],{"type":39,"attrs":40},"summaryBox",{"id":41,"items":42,"title":48},"sum_c4qy9pti",[43,44,45,46,47],"Use an abstraction layer like the Vercel AI SDK to avoid vendor lock-in and make it easier to switch models.","Ensure data integrity using Zod schemas with generateObject to convert probabilistic outputs into typed objects.","Implement tool calling to allow models to interact with external systems, such as databases and APIs.","Update agent control logic to the stopWhen pattern of AI SDK 5, replacing the old maxSteps parameter.","Adopt the AI Gateway to centralize calls, ensuring resilience, unified authentication, and efficient telemetry.","AI Orchestration with Vercel AI SDK",{"type":50,"attrs":51,"content":53},"paragraph",{"id":52},"p_fshyrm09",[54],{"text":55,"type":56},"Language models are probabilistic. Software is deterministic. Almost everything that is hard about putting AI into production lives in the gap between these two sentences.","text",{"type":50,"attrs":58,"content":60},{"id":59},"p_7jrewxfg",[61],{"text":62,"type":56},"In a demo, the gap doesn't appear — there is a human in the loop, reading the response and forgiving the rough edges. In production, what comes after the model is software: a database that expects a number, a function that expects an exact format, a UI that expects a field that always exists. Free text doesn't cut it. The work is engineering: closing this gap without pretending the model has become deterministic.",{"type":50,"attrs":64,"content":66},{"id":65},"p_ycfooyqh",[67],{"text":68,"type":56},"This article is the ladder to close it, step by step: a universal connector, typed outputs, tool calling, and, when tool calling isn't enough, isolation via sub-agents. I use the Vercel AI SDK as a concrete tool — but the patterns are what matter, not the brand.",{"type":70},"horizontalRule",{"type":72,"attrs":73,"content":76},"heading",{"id":74,"level":75},"h_d96cug9n",2,[77],{"text":78,"type":56},"The chaos where you start",{"type":50,"attrs":80,"content":82},{"id":81},"p_tfck9dum",[83],{"text":84,"type":56},"The first version of any AI feature usually starts out messy. You install a provider's SDK, write the stream parsing by hand, pray for the model to return valid JSON, and couple the business logic to a specific API. Then the provider releases a better model — or goes down — and you discover that switching means rewriting everything.",{"type":50,"attrs":86,"content":88},{"id":87},"p_hqot2vj1",[89],{"text":90,"type":56},"Every provider has a different API, a different stream format, a different way of asking for structured output. The result is disposable boilerplate and lock-in: you are stuck with the first vendor you chose, even when a better one appears.",{"type":92,"attrs":93},"speedCards",{"id":94,"cards":95,"title":104,"caption":105},"speed_p78w409q",[96,100],{"label":97,"value":98,"detail":99},"The naive approach","One SDK per provider","Parsing de stream na mão, tipagem fraca e trocar de provedor exige reescrever a lógica de negócio.",{"label":101,"value":102,"detail":103},"A unified layer","A single API","O mesmo código invoca qualquer LLM, com stream e tipos consistentes. Trocar de modelo é trocar uma linha.","The naive approach vs. a unified layer","Why stitching providers together by hand doesn't scale.",{"type":72,"attrs":107,"content":109},{"id":108,"level":75},"h_j0cdz99z",[110],{"text":111,"type":56},"The universal connector",{"type":50,"attrs":113,"content":115},{"id":114},"p_3h4e5zfp",[116,118,123],{"text":117,"type":56},"The first step is to stop speaking to each provider in their own language. A unified layer — the Vercel AI SDK is the most widely adopted in the JavaScript world — abstracts the differences: the same function ",{"text":119,"type":56,"marks":120},"generateText",[121],{"type":122},"code",{"text":124,"type":56}," talks to OpenAI, Anthropic, Google, or xAI, and switching models is just changing one line.",{"type":126,"attrs":127,"content":131},"codeBlock",{"id":128,"language":129,"highlighted":130},"code_maz69r7m","typescript","\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { generateText } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"ai\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { anthropic } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"@ai-sdk\u002Fanthropic\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F\u002F import { openai } from \"@ai-sdk\u002Fopenai\"; \u002F\u002F trocar de provedor = trocar 1 linha\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">text\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> generateText\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  model: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">anthropic\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"claude-sonnet-4-6\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  prompt: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Resuma este relatório em três frases.\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">});\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[132],{"text":133,"type":56},"import { generateText } from \"ai\";\nimport { anthropic } from \"@ai-sdk\u002Fanthropic\";\n\u002F\u002F import { openai } from \"@ai-sdk\u002Fopenai\"; \u002F\u002F trocar de provedor = trocar 1 linha\n\nconst { text } = await generateText({\n  model: anthropic(\"claude-sonnet-4-6\"),\n  prompt: \"Resuma este relatório em três frases.\",\n});",{"type":50,"attrs":135,"content":137},{"id":136},"p_8qn4u286",[138,140,144],{"text":139,"type":56},"On top of this lives the AI Gateway: a single endpoint that adds resilience without perceptible latency. You reference the model as a string — ",{"text":141,"type":56,"marks":142},"anthropic\u002Fclaude-sonnet-4.6",[143],{"type":122},{"text":145,"type":56}," — and gain automatic fallback (if one provider goes down, another takes over), OIDC authentication (without managing keys), and telemetry. Routing takes about 20 ms.",{"type":50,"attrs":147,"content":149},{"id":148},"p_9sxx1gqd",[150],{"text":151,"type":56},"None of this is magic, and the AI SDK is not the only option — Mastra and LangChain cover similar ground, and Cloudflare and AWS compete for the same integration layer. But the pattern is what counts: a provider-agnostic interface, so your architecture doesn't marry a single model.",{"type":72,"attrs":153,"content":155},{"id":154,"level":75},"h_m1bpicav",[156],{"text":157,"type":56},"Order from chaos: structured outputs",{"type":50,"attrs":159,"content":161},{"id":160},"p_mczhsmm4",[162,164,168],{"text":163,"type":56},"Now the gap, concretely. Ask a model for data in free text and you get something like “Hmm, let me see… the name is John Doe and I think he is 30 years old…”. Nice for a human to read, useless for software to consume. The model is probabilistic; the ",{"text":165,"type":56,"marks":166},"if",[167],{"type":122},{"text":169,"type":56}," that comes after is deterministic.",{"type":50,"attrs":171,"content":173},{"id":172},"p_b8ujnzqb",[174,176,180,182,186],{"text":175,"type":56},"The functions ",{"text":177,"type":56,"marks":178},"generateObject",[179],{"type":122},{"text":181,"type":56}," and ",{"text":183,"type":56,"marks":184},"streamObject",[185],{"type":122},{"text":187,"type":56}," close this. You pass a Zod schema, and the SDK forces the model to adhere to that structure — typed and validated end-to-end. It’s not “almost JSON”; it’s the object you declared.",{"type":126,"attrs":189,"content":192},{"id":190,"language":129,"highlighted":191},"code_yi7j7xm4","\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { generateObject } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"ai\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { anthropic } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"@ai-sdk\u002Fanthropic\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { z } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"zod\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">object\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> generateObject\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  model: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">anthropic\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"claude-sonnet-4-6\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  schema: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">object\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    nome: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">string\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    idade: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">number\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    prioridade: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">enum\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">([\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"baixa\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"media\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"alta\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  }),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  prompt: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Extraia os dados do cadastro: ...\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">});\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">object.prioridade; \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F\u002F tipado e validado — o TypeScript conhece a forma\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[193],{"text":194,"type":56},"import { generateObject } from \"ai\";\nimport { anthropic } from \"@ai-sdk\u002Fanthropic\";\nimport { z } from \"zod\";\n\nconst { object } = await generateObject({\n  model: anthropic(\"claude-sonnet-4-6\"),\n  schema: z.object({\n    nome: z.string(),\n    idade: z.number(),\n    prioridade: z.enum([\"baixa\", \"media\", \"alta\"]),\n  }),\n  prompt: \"Extraia os dados do cadastro: ...\",\n});\n\nobject.prioridade; \u002F\u002F tipado e validado — o TypeScript conhece a forma",{"type":50,"attrs":196,"content":198},{"id":197},"p_mos31osf",[199],{"text":200,"type":56},"If you read the Data Refinery article, this is the contract in action: the schema is the frontier between the model's probabilistic output and the typed system that consumes it. Ideal for extraction, classification, and generative UIs.",{"type":72,"attrs":202,"content":204},{"id":203,"level":75},"h_vi742kag",[205],{"text":206,"type":56},"Giving AI hands: tool calling",{"type":50,"attrs":208,"content":210},{"id":209},"p_zjn42lq1",[211],{"text":212,"type":56},"A model, no matter how smart, has no agency. It doesn't look up today's weather, it doesn't check a client's balance in your database, it doesn't send an email. It is trapped in its own box, frozen at the training cutoff, isolated from the real world — and no clean JSON changes that.",{"type":50,"attrs":214,"content":216},{"id":215},"p_oiq0ojat",[217,219,224],{"text":218,"type":56},"Tool calling solves this. The model doesn't execute code; it emits an ",{"text":220,"type":56,"marks":221},"intention",[222],{"type":223},"italic",{"text":225,"type":56}," (“call fetchOrder with orderId=A-1042”). The SDK executes your TypeScript function, returns the result to the model, and repeats the cycle until the task is finished.",{"type":50,"attrs":227,"content":229},{"id":228},"p_2au6j7eq",[230,232,236,238,242,244,248,250,254],{"text":231,"type":56},"Here lies the first important update — and where many tutorials are outdated. In AI SDK 4, you controlled the loop with ",{"text":233,"type":56,"marks":234},"maxSteps",[235],{"type":122},{"text":237,"type":56},". In AI SDK 5 (July 2025), this was removed: the loop is now controlled by ",{"text":239,"type":56,"marks":240},"stopWhen",[241],{"type":122},{"text":243,"type":56},", and tools declare ",{"text":245,"type":56,"marks":246},"inputSchema",[247],{"type":122},{"text":249,"type":56},", no longer ",{"text":251,"type":56,"marks":252},"parameters",[253],{"type":122},{"text":255,"type":56},".",{"type":126,"attrs":257,"content":260},{"id":258,"language":129,"highlighted":259},"code_pk9s8atr","\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { generateText, tool, stepCountIs } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"ai\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { anthropic } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"@ai-sdk\u002Fanthropic\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { z } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"zod\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">text\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> generateText\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  model: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">anthropic\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"claude-sonnet-4-6\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  stopWhen: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">stepCountIs\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">5\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),          \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F\u002F antes era `maxSteps: 5`\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  tools: {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    buscarPedido: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">tool\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      description: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Busca um pedido pelo ID\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      inputSchema: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">object\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({ pedidoId: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">string\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">() }), \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F\u002F antes era `parameters`\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">      execute\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">async\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ({ \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">pedidoId\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=>\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> db.pedidos.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">find\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(pedidoId),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    }),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  },\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  prompt: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Qual o status do pedido A-1042?\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">});\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[261],{"text":262,"type":56},"import { generateText, tool, stepCountIs } from \"ai\";\nimport { anthropic } from \"@ai-sdk\u002Fanthropic\";\nimport { z } from \"zod\";\n\nconst { text } = await generateText({\n  model: anthropic(\"claude-sonnet-4-6\"),\n  stopWhen: stepCountIs(5),          \u002F\u002F antes era `maxSteps: 5`\n  tools: {\n    buscarPedido: tool({\n      description: \"Busca um pedido pelo ID\",\n      inputSchema: z.object({ pedidoId: z.string() }), \u002F\u002F antes era `parameters`\n      execute: async ({ pedidoId }) => db.pedidos.find(pedidoId),\n    }),\n  },\n  prompt: \"Qual o status do pedido A-1042?\",\n});",{"type":264,"attrs":265,"content":269},"callout",{"id":266,"type":267,"title":268},"call_p7ngzu76","tip","The API has changed: from maxSteps to stopWhen",[270],{"type":50,"attrs":271,"content":273},{"id":272},"p_4uz8ntvf",[274,276,280,282,286,287,290,291,294,295,299,301,305,307,311,312,316],{"text":275,"type":56},"If you followed a 2024 tutorial, swap ",{"text":277,"type":56,"marks":278},"maxSteps: n",[279],{"type":122},{"text":281,"type":56}," for ",{"text":283,"type":56,"marks":284},"stopWhen: stepCountIs(n)",[285],{"type":122},{"text":181,"type":56},{"text":251,"type":56,"marks":288},[289],{"type":122},{"text":281,"type":56},{"text":245,"type":56,"marks":292},[293],{"type":122},{"text":255,"type":56},{"text":296,"type":56,"marks":297},"stepCountIs(20)",[298],{"type":122},{"text":300,"type":56},"The standard today is ",{"text":302,"type":56,"marks":303},"hasToolCall(nome)",[304],{"type":122},{"text":306,"type":56},". There is also ",{"text":308,"type":56,"marks":309},"isLoopFinished()",[310],{"type":122},{"text":181,"type":56},{"text":313,"type":56,"marks":314},"prepareStep",[315],{"type":122},{"text":317,"type":56}," to let the agent stop on its own, and ",{"type":72,"attrs":319,"content":321},{"id":320,"level":75},"h_435y2y6x",[322],{"text":323,"type":56}," to adjust context and model at each step.",{"type":50,"attrs":325,"content":327},{"id":326},"p_5op669hn",[328],{"text":329,"type":56},"The wall: context collapse",{"type":50,"attrs":331,"content":333},{"id":332},"p_no53knfg",[334],{"text":335,"type":56},"Tool calling is excellent for point-in-time actions. But when the task requires exploring a lot of information — reading dozens of files, scanning a database, traversing logs — each tool result goes back entirely into the main agent's context. And then three things happen at once: token consumption explodes, latency spikes, and the agent forgets the original instruction and loses coherence.",{"type":72,"attrs":337,"content":339},{"id":338,"level":75},"h_8dl6xs00",[340],{"text":341,"type":56},"It is the paradox of naive tool calling: the more the tool works, the more cognitive junk it dumps back into the agent. The solution is not a better tool; it is a boundary.",{"type":50,"attrs":343,"content":345},{"id":344},"p_2fl9fxfo",[346],{"text":347,"type":56},"The agentic frontier: isolation via sub-agents",{"type":50,"attrs":349,"content":351},{"id":350},"p_8xrqeiaf",[352,354,358],{"text":353,"type":56},"A sub-agent is an autonomous agent wrapped as a tool. The main agent calls it as it would any tool — sends a task, receives a result — but the sub-agent runs with its own context window, from scratch. It does the heavy lifting in isolation and returns only a focused summary.",{"text":355,"type":56,"marks":356},"toModelOutput",[357],{"type":122},{"text":359,"type":56},"The detail that closes the argument is ",{"type":126,"attrs":361,"content":364},{"id":362,"language":129,"highlighted":363},"code_r5s1zvek","\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { tool, generateText, stepCountIs } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"ai\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { anthropic } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"@ai-sdk\u002Fanthropic\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { z } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"zod\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F\u002F Um subagente é um agente autônomo invocado como ferramenta.\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> pesquisaProfunda\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> tool\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  description: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Pesquisa profunda e independente sobre um tópico\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  inputSchema: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">object\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({ tarefa: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">string\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">() }),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">  execute\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">async\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ({ \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">tarefa\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=>\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">    \u002F\u002F janela de contexto própria: queima 100k tokens explorando...\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">text\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> generateText\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      model: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">anthropic\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"claude-sonnet-4-6\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      stopWhen: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">stepCountIs\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">20\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      tools: { \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">\u002F* buscar, ler, etc. *\u002F\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> },\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      prompt: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`Investigue a fundo e resuma: ${\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">tarefa\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}`\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    });\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> text;\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  },\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">  \u002F\u002F ...mas o orquestrador só vê o resumo de ~1k tokens\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">  toModelOutput\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: ({ \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">output\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=>\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ({ type: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"text\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, value: output }),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">});\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[365],{"text":366,"type":56},"import { tool, generateText, stepCountIs } from \"ai\";\nimport { anthropic } from \"@ai-sdk\u002Fanthropic\";\nimport { z } from \"zod\";\n\n\u002F\u002F Um subagente é um agente autônomo invocado como ferramenta.\nconst pesquisaProfunda = tool({\n  description: \"Pesquisa profunda e independente sobre um tópico\",\n  inputSchema: z.object({ tarefa: z.string() }),\n  execute: async ({ tarefa }) => {\n    \u002F\u002F janela de contexto própria: queima 100k tokens explorando...\n    const { text } = await generateText({\n      model: anthropic(\"claude-sonnet-4-6\"),\n      stopWhen: stepCountIs(20),\n      tools: { \u002F* buscar, ler, etc. *\u002F },\n      prompt: `Investigue a fundo e resuma: ${tarefa}`,\n    });\n    return text;\n  },\n  \u002F\u002F ...mas o orquestrador só vê o resumo de ~1k tokens\n  toModelOutput: ({ output }) => ({ type: \"text\", value: output }),\n});",{"type":50,"attrs":368,"content":370},{"id":369},"p_l17y35g0",[371],{"text":372,"type":56},". It separates what the tool produces from what the main model sees: the sub-agent can burn 100k tokens exploring, but the orchestrator consumes only the 1k summary. The user follows all progress in streaming; the main model sees only the distillate. The main agent's context remains clean and coherent.",{"type":72,"attrs":374,"content":376},{"id":375,"level":75},"h_55webf98",[377],{"text":378,"type":56},"It is the orchestrator-worker pattern: a central agent divides the task, sub-agents execute in parallel and in isolation, and the central one synthesizes. Each sub-agent starts with a clean context — that is precisely what allows it to explore freely without bloating the main conversation.",{"type":50,"attrs":380,"content":382},{"id":381},"p_k7wgeksg",[383],{"text":384,"type":56},"Choosing the right architecture",{"type":92,"attrs":386},{"id":387,"cards":388,"title":405,"caption":406},"speed_ifdp611j",[389,393,397,401],{"label":390,"value":391,"detail":392},"Choose based on exploration volume and the need for independence.","Traditional tool calling","Pouca exploração, baixa complexidade. Ex.: buscar o clima, calcular um frete.",{"label":394,"value":395,"detail":396},"Point-in-time action","Multi-step tool calling","Vários passos encadeados, mas ainda no contexto do agente principal.",{"label":398,"value":399,"detail":400},"Sequential orchestration","Embeddings & RAG","Muito dado para varrer, baixa complexidade de decisão. Recupere o relevante, não tudo.",{"label":402,"value":403,"detail":404},"Semantic search","Sub-agent architecture","Muita exploração E independência: delegue para agentes isolados que devolvem resumos.","A sub-agent is not the answer to everything — they add latency and complexity, and over-engineering is a form of failure just as real as the lack of it. The AI SDK lets you compose all strategies on the same foundation; the work is matching the architecture to the task, looking at two axes: the volume of data to explore and the need for independence.","Delegation strategy matrix",{"type":264,"attrs":408,"content":411},{"id":409,"type":267,"title":410},"call_vzpbvb3l","Deep exploration",[412],{"type":50,"attrs":413,"content":415},{"id":414},"p_kj7k261b",[416],{"text":417,"type":56},"Not everything needs a sub-agent",{"type":72,"attrs":419,"content":421},{"id":420,"level":75},"h_mbcon4vy",[422],{"text":423,"type":56},"Start with the lowest step that solves the problem. A point-in-time action is a tool; a simple sequence is multi-step; a search in a corpus is RAG. Move up to sub-agents only when the task requires deep and independent exploration — and the gain of clean context pays for the extra latency.",{"type":50,"attrs":425,"content":427},{"id":426},"p_9otbm9og",[428,430,434,436,440,442,446,448,452],{"text":429,"type":56},"Putting into production: resilience and observability",{"text":431,"type":56,"marks":432},"providerOptions.gateway",[433],{"type":122},{"text":435,"type":56},"Multi-agent architectures break in ways a demo never shows, and they need infrastructure to match. The AI Gateway and the ",{"text":437,"type":56,"marks":438},"order",[439],{"type":122},{"text":441,"type":56}," parameter manage operational chaos: automatic model fallback if a provider fails (",{"text":443,"type":56,"marks":444},"only",[445],{"type":122},{"text":447,"type":56},", ",{"text":449,"type":56,"marks":450},"sort",[451],{"type":122},{"text":453,"type":56}," for cost, latency, or throughput), Zero Data Retention per call for privacy, and OIDC authentication that eliminates key management.",{"type":50,"attrs":455,"content":457},{"id":456},"p_8ue67r05",[458],{"text":459,"type":56},"And there is the invisible cost. Autonomous systems spend in silence — a sub-agent that triggers twenty steps can cost much more than the orchestrator. That is why observability is not a luxury: you need traceability by function and by provider, with costs segregated by model, token metrics, and Time to First Token (TTFT). Without this, you discover the bill at the end of the month.",{"type":72,"attrs":461,"content":463},{"id":462,"level":75},"h_xuc2j9hy",[464],{"text":465,"type":56},"The architecture, assembled",{"type":50,"attrs":467,"content":469},{"id":468},"p_n7ybwdl1",[470],{"text":471,"type":56},"Put the steps together and the final piece appears: a main orchestrator (a strong model) receives the request and decides; it calls specialized tools and sub-agents (perhaps other models, perhaps cheaper ones), which explore in isolation and return summaries; the data passes through a Zod schema and becomes typed JSON; and everything goes back to the user in streaming. One SDK, crossing provider, model, and security boundaries.",{"type":473,"attrs":474},"svgDiagram",{"id":475,"svg":476,"label":477},"svg_fbf4dqis","\u003Csvg viewBox=\"0 0 848 524\" xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" font-family=\"system-ui, -apple-system, sans-serif\">\n\u003Cdefs>\u003Cmarker id=\"dgArrow\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\">\u003Cpath d=\"M 0 1 L 9 5 L 0 9 z\" fill=\"#64748b\"\u002F>\u003C\u002Fmarker>\u003C\u002Fdefs>\n\u003Crect x=\"0\" y=\"0\" width=\"848\" height=\"524\" fill=\"#ffffff\" rx=\"0\"\u002F>\n\u003Ctext x=\"424\" y=\"36\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"16\" font-weight=\"700\" fill=\"#0f172a\">Arquitetura Final do Sistema de Orquestração\u003C\u002Ftext>\n\u003Cpath d=\"M 423.5078125 143 C 423.5078125 171, 215.3125 171, 215.3125 199\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#dgArrow)\"\u002F>\n\u003Ctext x=\"319.41015625\" y=\"171\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"11\" fill=\"#475569\" paint-order=\"stroke\" stroke=\"#ffffff\" stroke-width=\"4\" stroke-linejoin=\"round\">chama para execução\u003C\u002Ftext>\n\u003Cpath d=\"M 215.3125 262 C 215.3125 290, 423.5078125 290, 423.5078125 318\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#dgArrow)\"\u002F>\n\u003Ctext x=\"319.41015625\" y=\"290\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"11\" fill=\"#475569\" paint-order=\"stroke\" stroke=\"#ffffff\" stroke-width=\"4\" stroke-linejoin=\"round\">resumos convertidos\u003C\u002Ftext>\n\u003Cpath d=\"M 423.5078125 381 C 423.5078125 409, 423.515625 409, 423.515625 437\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#dgArrow)\"\u002F>\n\u003Ctext x=\"423.51171875\" y=\"409\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"11\" fill=\"#475569\" paint-order=\"stroke\" stroke=\"#ffffff\" stroke-width=\"4\" stroke-linejoin=\"round\">dados validados\u003C\u002Ftext>\n\u003Cpath d=\"M 423.5078125 143 C 423.5078125 171, 628.828125 171, 628.828125 199\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#dgArrow)\"\u002F>\n\u003Ctext x=\"526.16796875\" y=\"171\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"11\" fill=\"#475569\" paint-order=\"stroke\" stroke=\"#ffffff\" stroke-width=\"4\" stroke-linejoin=\"round\">integração\u003C\u002Ftext>\n\u003Cpath d=\"M 628.828125 262 C 628.828125 290, 423.515625 409, 423.515625 437\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#dgArrow)\"\u002F>\n\u003Ctext x=\"526.171875\" y=\"349.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"11\" fill=\"#475569\" paint-order=\"stroke\" stroke=\"#ffffff\" stroke-width=\"4\" stroke-linejoin=\"round\">envia resposta\u003C\u002Ftext>\n\u003Crect x=\"287.4375\" y=\"80\" width=\"272.140625\" height=\"63\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\n\u003Ctext x=\"423.5078125\" y=\"101.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Orquestrador Principal\u003C\u002Ftext>\n\u003Ctext x=\"423.5078125\" y=\"123\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"12\" font-weight=\"400\" fill=\"#64748b\">Modelo forte que recebe pedidos e decide\u003C\u002Ftext>\n\u003Crect x=\"24\" y=\"199\" width=\"382.625\" height=\"63\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\n\u003Ctext x=\"215.3125\" y=\"220.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Ferramentas e Subagentes\u003C\u002Ftext>\n\u003Ctext x=\"215.3125\" y=\"242\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"12\" font-weight=\"400\" fill=\"#64748b\">Modelos especializados ou mais baratos que executam tarefas\u003C\u002Ftext>\n\u003Crect x=\"271.734375\" y=\"318\" width=\"303.546875\" height=\"63\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\n\u003Ctext x=\"423.5078125\" y=\"339.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Schema Zod\u003C\u002Ftext>\n\u003Ctext x=\"423.5078125\" y=\"361\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"12\" font-weight=\"400\" fill=\"#64748b\">Validação e tipagem segura dos dados em JSON\u003C\u002Ftext>\n\u003Crect x=\"285.734375\" y=\"437\" width=\"275.5625\" height=\"63\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\n\u003Ctext x=\"423.515625\" y=\"458.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Retorno ao Usuário\u003C\u002Ftext>\n\u003Ctext x=\"423.515625\" y=\"480\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"12\" font-weight=\"400\" fill=\"#64748b\">Resposta em streaming com dados tipados\u003C\u002Ftext>\n\u003Crect x=\"434.625\" y=\"199\" width=\"388.40625\" height=\"63\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\n\u003Ctext x=\"628.828125\" y=\"220.5\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">SDK Universal\u003C\u002Ftext>\n\u003Ctext x=\"628.828125\" y=\"242\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"12\" font-weight=\"400\" fill=\"#64748b\">Conector único atravessando provedores, modelos e segurança\u003C\u002Ftext>\n\u003C\u002Fsvg>","Final Orchestration System Architecture",{"type":50,"attrs":479,"content":481},{"id":480},"p_2l7havuj",[482],{"text":483,"type":56},"The arc is this: from scattered APIs to a universal connector; from probabilistic text to secure typing; from isolated chat boxes to systems with agency; from context collapse to sub-agent orchestration. Fragile prompt engineering becomes software architecture.",{"type":50,"attrs":485,"content":487},{"id":486},"p_xl11wnoq",[488],{"text":489,"type":56},"And note what hasn't changed along the way: the model remains probabilistic. You haven't tamed it. You have built deterministic software around it — a connector that doesn't lock you in, a schema that guarantees the shape, a loop that knows when to stop, a boundary that protects the context. Intelligence is probabilistic; the architecture is not. That is where, in this carefully stitched gap, the difference between a demo and a product lives.",{"type":70},{"type":50,"attrs":492,"content":494},{"id":493},"p_l3356yj0",[495],{"text":496,"type":56,"marks":497},"Written in June 2026. The API references — loop control with stopWhen\u002FstepCountIs (AI SDK 5, July 2025), tools with inputSchema, the sub-agent pattern with toModelOutput, and AI Gateway features (fallbacks, ZDR, OIDC, BYOK, and observability) — reflect the state of the Vercel AI SDK at that date. The AI SDK is not the only way to implement these patterns.",[498],{"type":223},"Orchestrating Agents with Vercel AI SDK: Production Guide","Learn to orchestrate AI agents with Vercel AI SDK. Bridge the gap between probabilistic models and deterministic systems with robust patterns.","2026-08-24T14:53:53.315534+00:00",[503,526,543,557],{"id":504,"slug":505,"title":506,"excerpt":507,"image":508,"featured":10,"groupId":509,"publishedAt":510,"readingTime":511,"views":14,"author":512,"category":513,"tags":514},"10ee04ce-fa53-44d7-9603-2e375733d313","the-rise-of-shadow-deployment-and-the-dna-behind-the-hidden-ox-alpha-model","The Rise of Shadow Deployment and the DNA Behind the Hidden Ox Alpha Model","The ghost launch of Ox Alpha revealed a new era in software engineering, where strategic anonymity redefines the future of AI models.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1787604179257-featured-byxw99.webp","ba241d77-9b03-4c87-8e52-ba727a888e59","2026-08-24T22:56:11.386568+00:00",7,{"name":16,"avatar":17},{"slug":19,"name":20,"color":21},[515,518,519,522,523],{"slug":516,"name":517},"china","China",{"slug":30,"name":31},{"slug":520,"name":521},"infraestrutura","Infraestrutura",{"slug":24,"name":25},{"slug":524,"name":525},"performance","Performance",{"id":527,"slug":528,"title":529,"excerpt":530,"image":531,"featured":10,"groupId":532,"publishedAt":533,"readingTime":534,"views":14,"author":535,"category":536,"tags":537},"99d8b7bf-03aa-4c01-8bc7-ef1aca804b30","conversational-ai-exhausted-how-to-migrate-to-agentic-workflows-and-execute-real-actions","Conversational AI Exhausted? How to Migrate to Agentic Workflows and Execute Real Actions","The chat paradigm is exhausted. Discover agentic workflows: systems that plan, execute, and verify tasks autonomously and in a testable manner.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1773194326109-featured-g0e36z.jpeg","2438fae0-5c5e-41ce-9543-89007a6888cc","2026-07-08T23:42:19.403576+00:00",4,{"name":16,"avatar":17},{"slug":19,"name":20,"color":21},[538,539,540],{"slug":24,"name":25},{"slug":30,"name":31},{"slug":541,"name":542},"openclaw","OpenClaw",{"id":544,"slug":545,"title":546,"excerpt":547,"image":548,"featured":10,"groupId":549,"publishedAt":550,"readingTime":551,"views":14,"author":552,"category":553,"tags":554},"011ee3e7-61c8-4877-a99b-edc119022f4d","glm-52-vs-kimi-k27-why-glm-wins-the-code-reliability-test","GLM-5.2 vs. Kimi K2.7: Why GLM Wins the Code Reliability Test","Five independent evaluators tested GLM-5.2 and Kimi K2.7 on coding tasks. Discover which model wins the battle for reliability and development speed.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1782256309298-featured-ubiuao.webp","8707b037-1af8-46ff-972a-99c4ead20adc","2026-07-08T22:58:35.7148+00:00",5,{"name":16,"avatar":17},{"slug":19,"name":20,"color":21},[555,556],{"slug":24,"name":25},{"slug":524,"name":525},{"id":558,"slug":559,"title":560,"excerpt":561,"image":562,"featured":10,"groupId":563,"publishedAt":564,"readingTime":565,"views":14,"author":566,"category":567,"tags":568},"e595e2c6-e464-46d7-ba67-810f8d0cd234","how-to-choose-an-ai-sdk-why-the-fear-of-lock-in-is-a-mistake-and-how-to-decide-based-on-your-apps-format","How to choose an AI SDK: why the fear of lock-in is a mistake and how to decide based on your app's format","The fear of being locked into an AI provider is a common mistake. Learn how to choose the best SDK based on your project's format and productivity.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1782794440171-featured-aqj363.webp","7839c171-0b65-418a-87dc-7ded7786a84a","2026-07-04T19:26:16.054373+00:00",6,{"name":16,"avatar":17},{"slug":19,"name":20,"color":21},[569,570],{"slug":24,"name":25},{"slug":30,"name":31},{"en":6,"pt":572},"do-caos-a-producao-como-orquestrar-agentes-deterministicos-com-vercel-ai-sdk",[574,580,586,590,595],{"id":575,"slug":576,"name":577,"colorHex":578,"iconName":17,"postCount":579},"0e2c1225-f78a-4c20-8c93-998ab9dc93b9","frontend","Frontend","#40484f",25,{"id":581,"slug":582,"name":583,"colorHex":584,"iconName":17,"postCount":585},"bc8df70e-b7fb-4d89-a80c-fd458d36d58c","code-development","Code & Development","#8b5cf6",23,{"id":587,"slug":19,"name":20,"colorHex":21,"iconName":588,"postCount":589},"550e8400-e29b-41d4-a716-446655440001","brain",14,{"id":591,"slug":592,"name":593,"colorHex":594,"iconName":17,"postCount":534},"ea63b69c-2eb4-4100-81f3-70ce52d33743","tech-news","Tech News","#e50606",{"id":596,"slug":597,"name":598,"colorHex":599,"iconName":600,"postCount":75},"550e8400-e29b-41d4-a716-446655440017","how-to-guides","How-To & Guides","#be123c","book-open"]