[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"categories-en":3,"post:\u002Fpost\u002Forchestrating-ai-in-production-with-firebase-genkit":37},[4,11,17,24,30],{"id":5,"slug":6,"name":7,"colorHex":8,"iconName":9,"postCount":10},"0e2c1225-f78a-4c20-8c93-998ab9dc93b9","frontend","Frontend","#40484f",null,25,{"id":12,"slug":13,"name":14,"colorHex":15,"iconName":9,"postCount":16},"bc8df70e-b7fb-4d89-a80c-fd458d36d58c","code-development","Code & Development","#8b5cf6",23,{"id":18,"slug":19,"name":20,"colorHex":21,"iconName":22,"postCount":23},"550e8400-e29b-41d4-a716-446655440001","inteligencia-artificial","Artificial Intelligence","#6366f1","brain",14,{"id":25,"slug":26,"name":27,"colorHex":28,"iconName":9,"postCount":29},"ea63b69c-2eb4-4100-81f3-70ce52d33743","tech-news","Tech News","#e50606",4,{"id":31,"slug":32,"name":33,"colorHex":34,"iconName":35,"postCount":36},"550e8400-e29b-41d4-a716-446655440017","how-to-guides","How-To & Guides","#be123c","book-open",2,{"post":38,"related":664,"translations":731,"resolved":9},{"id":39,"slug":40,"title":41,"excerpt":42,"image":43,"featured":44,"groupId":45,"publishedAt":46,"readingTime":47,"views":48,"author":49,"category":51,"tags":52,"contentJson":62,"metaTitle":41,"metaDescription":662,"updatedAt":663},"8156bc27-9cae-4419-a052-a4a1918eff62","orchestrating-ai-in-production-with-firebase-genkit","Orchestrating AI in production with Firebase Genkit","That AI tutorial that seems trivial hides a tangle of responsibilities that only emerges when code meets real traffic.","https:\u002F\u002Fmfgiomkkbihnlpfdxwrt.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Fblog-assets\u002Fmedia\u002Ffeatured\u002F1781574594476-featured-nugas0.webp",false,"c99a8d08-ec19-4932-8459-5db850165617","2026-06-16T02:07:34.225334+00:00",6,0,{"name":50,"avatar":9},"Genildo Souza",{"slug":19,"name":20,"color":21},[53,56,59],{"slug":54,"name":55},"ai","AI",{"slug":57,"name":58},"llm","LLM",{"slug":60,"name":61},"rag","RAG",{"type":63,"content":64},"doc",[65,80,92,94,101,114,177,189,190,196,202,208,220,227,245,254,272,278,290,298,304,305,311,323,328,334,340,352,357,363,380,387,388,394,406,418,424,623,629,634,635,641,653,659],{"type":66,"attrs":67,"content":69},"paragraph",{"id":68},"p_gk001intro",[70,73,78],{"text":71,"type":72},"Integrating AI seems simple: call an LLM API and read the response. That simplicity is a ","text",{"text":74,"type":72,"marks":75},"illusion",[76],{"type":77},"bold",{"text":79,"type":72},". In production, that single arrow becomes a tangled mess of responsibilities — and that's exactly the problem Firebase Genkit proposes to solve, acting as an orchestration layer that decouples business logic from AI infrastructure.",{"type":66,"attrs":81,"content":83},{"id":82},"p_gk002thesis",[84,86,90],{"text":85,"type":72},"The central thesis is straightforward: ",{"text":87,"type":72,"marks":88},"an orchestration framework turns fragile LLM calls into predictable, typed, and observable architecture",[89],{"type":77},{"text":91,"type":72},". The gain isn't in magical prompts, but in rigid contracts, mature abstractions, and infrastructure isolation.",{"type":93},"horizontalRule",{"type":95,"attrs":96,"content":98},"heading",{"id":97,"level":36},"h_gk01",[99],{"text":100,"type":72},"Part 1 — Why isolated calls fail",{"type":66,"attrs":102,"content":104},{"id":103},"p_gk010",[105,107,112],{"text":106,"type":72},"The linear flow we imagine — ",{"text":108,"type":72,"marks":109},"App → LLM → Response",[110],{"type":111},"italic",{"text":113,"type":72}," — in practice, unfolds into a set of responsibilities that nobody asked for but all show up in production: context management, retry with backoff, broken JSON parsing, key rotation, document chunking, and vector store integration. Four structural problems emerge from this coupling:",{"type":115,"attrs":116,"content":119},"bulletList",{"id":117,"tight":118},"ul_gk01",true,[120,135,149,163],{"type":121,"attrs":122,"content":124},"listItem",{"id":123},"li_gk011",[125],{"type":66,"attrs":126,"content":128},{"id":127},"p_gk011",[129,133],{"text":130,"type":72,"marks":131},"Lack of typing",[132],{"type":77},{"text":134,"type":72}," — without rigid contracts, the model's response is unpredictable JSON that silently breaks the consumer.",{"type":121,"attrs":136,"content":138},{"id":137},"li_gk012",[139],{"type":66,"attrs":140,"content":142},{"id":141},"p_gk012",[143,147],{"text":144,"type":72,"marks":145},"Hardcoded prompts",[146],{"type":77},{"text":148,"type":72}," — the LLM's intent lives embedded in the application code, impossible to version or test in isolation.",{"type":121,"attrs":150,"content":152},{"id":151},"li_gk013",[153],{"type":66,"attrs":154,"content":156},{"id":155},"p_gk013",[157,161],{"text":158,"type":72,"marks":159},"Vendor lock-in",[160],{"type":77},{"text":162,"type":72}," — business logic gets tied to a specific proprietary model.",{"type":121,"attrs":164,"content":166},{"id":165},"li_gk014",[167],{"type":66,"attrs":168,"content":170},{"id":169},"p_gk014",[171,175],{"text":172,"type":72,"marks":173},"Zero observability",[174],{"type":77},{"text":176,"type":72}," — without visibility into latency and cost, every call is a financial black box.",{"type":66,"attrs":178,"content":180},{"id":179},"p_gk015",[181,183,187],{"text":182,"type":72},"The professional response is ",{"text":184,"type":72,"marks":185},"decompose the integration before it turns into technical debt",[186],{"type":77},{"text":188,"type":72},": separate each concern into a module with its own contract. That's what Genkit organizes into three layers.",{"type":93},{"type":95,"attrs":191,"content":193},{"id":192,"level":36},"h_gk02",[194],{"text":195,"type":72},"Part 2 — The three-layer operational model",{"type":66,"attrs":197,"content":199},{"id":198},"p_gk020",[200],{"text":201,"type":72},"Genkit organizes itself into three overlapping layers. The bottom one is provider-agnostic; the middle one concentrates reusable abstractions; the top one delivers the development experience.",{"type":203,"attrs":204},"svgDiagram",{"id":205,"svg":206,"label":207},"svg_gk01","\u003Csvg viewBox=\"0 0 600 300\" xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" font-family=\"system-ui, -apple-system, sans-serif\">\u003Crect x=\"0\" y=\"0\" width=\"600\" height=\"300\" fill=\"#ffffff\"\u002F>\u003Ctext x=\"300\" y=\"32\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#0f172a\">As três camadas do Genkit\u003C\u002Ftext>\u003Crect x=\"40\" y=\"56\" width=\"520\" height=\"64\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"60\" y=\"84\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Developer experience\u003C\u002Ftext>\u003Ctext x=\"60\" y=\"106\" font-size=\"12\" fill=\"#64748b\">Tipagem (Zod\u002FPydantic) · Dev UI · traces · deploy nativo\u003C\u002Ftext>\u003Crect x=\"40\" y=\"136\" width=\"520\" height=\"64\" rx=\"10\" fill=\"#f5f3ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"60\" y=\"164\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Abstrações centrais\u003C\u002Ftext>\u003Ctext x=\"60\" y=\"186\" font-size=\"12\" fill=\"#64748b\">Flows · RAG (retrievers &amp; indexers) · Tools\u003C\u002Ftext>\u003Crect x=\"40\" y=\"216\" width=\"520\" height=\"64\" rx=\"10\" fill=\"#ecfeff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"60\" y=\"244\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Infraestrutura agnóstica\u003C\u002Ftext>\u003Ctext x=\"60\" y=\"266\" font-size=\"12\" fill=\"#64748b\">Google · OpenAI · Ollama · Pinecone · Chroma · pgvector\u003C\u002Ftext>\u003C\u002Fsvg>","The three layers of Genkit",{"type":66,"attrs":209,"content":211},{"id":210},"p_gk021",[212,214,218],{"text":213,"type":72},"The key idea of this architecture is ",{"text":215,"type":72,"marks":216},"write the logic once; swap the infrastructure with one line of code",[217],{"type":111},{"text":219,"type":72},". The first-class runtime is JS\u002FTS, but the framework also has SDKs in Go, Python, and Dart.",{"type":95,"attrs":221,"content":224},{"id":222,"level":223},"h_gk022",3,[225],{"text":226,"type":72},"Typed Flows and rigid contracts",{"type":66,"attrs":228,"content":230},{"id":229},"p_gk023",[231,233,237,239,243],{"text":232,"type":72},"A ",{"text":234,"type":72,"marks":235},"Flow",[236],{"type":77},{"text":238,"type":72}," is an observable operation with input and output contracts defined by Zod schemas. The secret lies in the field ",{"text":240,"type":72,"marks":241},"output: { schema }",[242],{"type":77},{"text":244,"type":72},": Genkit injects the schema rules into the model instruction (constrained generation) and validates the response back.",{"type":246,"attrs":247,"content":251},"codeBlock",{"id":248,"language":249,"highlighted":250},"code_gk01","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\"> { genkit, z } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> 'genkit'\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\"> { googleAI } \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">from\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> '@genkit-ai\u002Fgoogleai'\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:#005CC5;--shiki-dark:#79B8FF\"> ai\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> genkit\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({ plugins: [\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">googleAI\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 contrato de saída: nada de JSON solto\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\"> Relatorio\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> 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\">  titulo: 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\">  risco: 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\">'baixo'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'medio'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'alto'\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\">  pontos: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">array\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(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\">});\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> gerarRelatorio\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ai.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">defineFlow\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\">    name: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'gerarRelatorio'\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\">({ texto: 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\">    outputSchema: Relatorio,\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\">  async\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ({ \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">texto\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:#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\">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:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ai.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">generate\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:#032F62;--shiki-dark:#9ECBFF\">'googleai\u002Fgemini-1.5-flash'\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\">`Analise e resuma: ${\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">texto\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\">      output: { schema: Relatorio },\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\"> output\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:#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>\u003C\u002Fcode>\u003C\u002Fpre>",[252],{"text":253,"type":72},"import { genkit, z } from 'genkit';\nimport { googleAI } from '@genkit-ai\u002Fgoogleai';\n\nconst ai = genkit({ plugins: [googleAI()] });\n\n\u002F\u002F contrato de saída: nada de JSON solto\nconst Relatorio = z.object({\n  titulo: z.string(),\n  risco: z.enum(['baixo', 'medio', 'alto']),\n  pontos: z.array(z.string()),\n});\n\nexport const gerarRelatorio = ai.defineFlow(\n  {\n    name: 'gerarRelatorio',\n    inputSchema: z.object({ texto: z.string() }),\n    outputSchema: Relatorio,\n  },\n  async ({ texto }) => {\n    const { output } = await ai.generate({\n      model: 'googleai\u002Fgemini-1.5-flash',\n      prompt: `Analise e resuma: ${texto}`,\n      output: { schema: Relatorio },\n    });\n    return output!;\n  }\n);\n",{"type":66,"attrs":255,"content":257},{"id":256},"p_gk024",[258,260,264,266,270],{"text":259,"type":72},"The ",{"text":261,"type":72,"marks":262},"enum",[263],{"type":77},{"text":265,"type":72}," in the field ",{"text":267,"type":72,"marks":268},"risk",[269],{"type":77},{"text":271,"type":72}," isn't decoration: it eliminates an entire class of bugs where the model would invent \"moderate-high risk\" and break the consumer's switch. Treat the LLM's output schema with the same rigor as a REST API contract.",{"type":95,"attrs":273,"content":275},{"id":274,"level":223},"h_gk025",[276],{"text":277,"type":72},"Dotprompt: prompts as code",{"type":66,"attrs":279,"content":281},{"id":280},"p_gk026",[282,284,288],{"text":283,"type":72},"To get rid of hardcoded prompts, Genkit uses files ",{"text":285,"type":72,"marks":286},".prompt",[287],{"type":77},{"text":289,"type":72}," versionable and testable. A YAML frontmatter declares configuration (model, temperature, schemas, tools) and a Handlebars template defines the messages, with embedded conditional logic.",{"type":246,"attrs":291,"content":295},{"id":292,"language":293,"highlighted":294},"code_gk02","yaml","\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:#6F42C1;--shiki-dark:#B392F0\">---\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">model\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">googleai\u002Fgemini-1.5-flash\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">config\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">  temperature\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">0.4\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">input\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">  schema\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">UserSchema\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">output\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">  schema\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">ReportSchema\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">tools\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: [\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">buscarClima\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\">---\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">{{\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">role \"system\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">Você é um assistente técnico especializado.\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">{{\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">role \"user\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">Analise os dados de {{usuario.nome}} e a imagem\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>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">media url=imagemPerfil\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:#24292E;--shiki-dark:#E1E4E8\">{{#\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">if isPremium\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}}\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">Forneça resposta detalhada.{{\u002Fif}}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[296],{"text":297,"type":72},"---\nmodel: googleai\u002Fgemini-1.5-flash\nconfig:\n  temperature: 0.4\ninput:\n  schema: UserSchema\noutput:\n  schema: ReportSchema\ntools: [buscarClima]\n---\n{{role \"system\"}}\nVocê é um assistente técnico especializado.\n\n{{role \"user\"}}\nAnalise os dados de {{usuario.nome}} e a imagem:\n{{media url=imagemPerfil}}\n\n{{#if isPremium}}Forneça resposta detalhada.{{\u002Fif}}\n",{"type":66,"attrs":299,"content":301},{"id":300},"p_gk027",[302],{"text":303,"type":72},"Adjusting a prompt becomes a text diff, reviewable in a pull request, without recompiling the application.",{"type":93},{"type":95,"attrs":306,"content":308},{"id":307,"level":36},"h_gk03",[309],{"text":310,"type":72},"Part 3 — RAG, reranking and tools",{"type":66,"attrs":312,"content":314},{"id":313},"p_gk030",[315,317,321],{"text":316,"type":72},"Ask an LLM about an internal term at your company and it hallucinates, because the data doesn't exist in its training. Injecting the entire document fixes the hallucination but consumes ~4,000 tokens per question. The architectural answer is the ",{"text":318,"type":72,"marks":319},"RAG (Retrieval-Augmented Generation)",[320],{"type":77},{"text":322,"type":72},": retrieve only the relevant snippets. The native pipeline has two paths that share the same vector store.",{"type":203,"attrs":324},{"id":325,"svg":326,"label":327},"svg_gk02","\u003Csvg viewBox=\"0 0 600 470\" xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" font-family=\"system-ui, -apple-system, sans-serif\">\u003Cdefs>\u003Cmarker id=\"ragArrow\" 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>\u003Crect x=\"0\" y=\"0\" width=\"600\" height=\"470\" fill=\"#ffffff\"\u002F>\u003Ctext x=\"300\" y=\"30\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#0f172a\">Pipeline RAG nativo do Genkit\u003C\u002Ftext>\u003Crect x=\"80\" y=\"52\" width=\"200\" height=\"52\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"180\" y=\"78\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">Query do usuário\u003C\u002Ftext>\u003Cline x1=\"180\" y1=\"106\" x2=\"180\" y2=\"134\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#ragArrow)\"\u002F>\u003Crect x=\"80\" y=\"136\" width=\"200\" height=\"52\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"180\" y=\"162\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">Embedder\u003C\u002Ftext>\u003Cline x1=\"180\" y1=\"190\" x2=\"180\" y2=\"218\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#ragArrow)\"\u002F>\u003Crect x=\"80\" y=\"220\" width=\"200\" height=\"52\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"180\" y=\"246\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">Retriever\u003C\u002Ftext>\u003Crect x=\"330\" y=\"220\" width=\"230\" height=\"52\" rx=\"10\" fill=\"#ecfeff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"445\" y=\"246\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">Vector store (indexado)\u003C\u002Ftext>\u003Cline x1=\"328\" y1=\"246\" x2=\"284\" y2=\"246\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#ragArrow)\"\u002F>\u003Cline x1=\"180\" y1=\"274\" x2=\"180\" y2=\"302\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#ragArrow)\"\u002F>\u003Crect x=\"80\" y=\"304\" width=\"200\" height=\"52\" rx=\"10\" fill=\"#ffffff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"180\" y=\"330\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">Augmentation\u003C\u002Ftext>\u003Cline x1=\"180\" y1=\"358\" x2=\"180\" y2=\"386\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#ragArrow)\"\u002F>\u003Crect x=\"80\" y=\"388\" width=\"200\" height=\"52\" rx=\"10\" fill=\"#fef2f2\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"180\" y=\"414\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"13\" font-weight=\"600\" fill=\"#1e293b\">LLM\u003C\u002Ftext>\u003C\u002Fsvg>","Genkit's native RAG pipeline",{"type":66,"attrs":329,"content":331},{"id":330},"p_gk031",[332],{"text":333,"type":72},"The concrete gain: consumption drops from ~4,000 to ~830 tokens per query, while maintaining accuracy. You pay the cost of vectorizing once, at ingestion, and reap cheap, precise responses on every query.",{"type":95,"attrs":335,"content":337},{"id":336,"level":223},"h_gk032",[338],{"text":339,"type":72},"Reranking: two-stage retrieval",{"type":66,"attrs":341,"content":343},{"id":342},"p_gk033",[344,346,350],{"text":345,"type":72},"A vector retriever is fast but noisy. The ",{"text":347,"type":72,"marks":348},"two-stage retrieval",[349],{"type":111},{"text":351,"type":72}," pattern adds a reranker (cross-encoder) that reorders candidates by exact relevance and narrows the output to the top — only what has the highest statistical value occupies the context window. The first stage prioritizes recall; the second, precision.",{"type":203,"attrs":353},{"id":354,"svg":355,"label":356},"svg_gk03","\u003Csvg viewBox=\"0 0 600 300\" xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" font-family=\"system-ui, -apple-system, sans-serif\">\u003Cdefs>\u003Cmarker id=\"rerArrow\" 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>\u003Crect x=\"0\" y=\"0\" width=\"600\" height=\"300\" fill=\"#ffffff\"\u002F>\u003Ctext x=\"300\" y=\"30\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#0f172a\">Two-stage retrieval (reranking)\u003C\u002Ftext>\u003Crect x=\"150\" y=\"52\" width=\"300\" height=\"56\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"300\" y=\"76\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Retriever básico\u003C\u002Ftext>\u003Ctext x=\"300\" y=\"96\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">10–20 docs por similaridade (com ruído)\u003C\u002Ftext>\u003Cline x1=\"300\" y1=\"110\" x2=\"300\" y2=\"138\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#rerArrow)\"\u002F>\u003Crect x=\"180\" y=\"140\" width=\"240\" height=\"56\" rx=\"10\" fill=\"#f5f3ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"300\" y=\"164\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Reranker (cross-encoder)\u003C\u002Ftext>\u003Ctext x=\"300\" y=\"184\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">reordena pela relevância exata\u003C\u002Ftext>\u003Cline x1=\"300\" y1=\"198\" x2=\"300\" y2=\"226\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#rerArrow)\"\u002F>\u003Crect x=\"210\" y=\"228\" width=\"180\" height=\"52\" rx=\"10\" fill=\"#ecfeff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"300\" y=\"250\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Saída estreita\u003C\u002Ftext>\u003Ctext x=\"300\" y=\"268\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">só o top 3 vai ao LLM\u003C\u002Ftext>\u003C\u002Fsvg>","Two-stage retrieval with reranking",{"type":95,"attrs":358,"content":360},{"id":359,"level":223},"h_gk034",[361],{"text":362,"type":72},"Tools: from passive LLMs to agents",{"type":66,"attrs":364,"content":366},{"id":365},"p_gk035",[367,368,372,374,378],{"text":259,"type":72},{"text":369,"type":72,"marks":370},"Tools",[371],{"type":77},{"text":373,"type":72}," allow the model to ",{"text":375,"type":72,"marks":376},"request",[377],{"type":111},{"text":379,"type":72}," external data. You send the catalog of tools; when the model needs something it doesn't have, it pauses generation, Genkit intercepts and executes the tool locally, returns the result, and the model synthesizes the response. A tool is just a Zod-typed function that the model learns to invoke.",{"type":246,"attrs":381,"content":384},{"id":382,"language":249,"highlighted":383},"code_gk03","\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\">export\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> buscarClima\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ai.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">defineTool\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\">    name: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'buscarClima'\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\">'Retorna o clima atual de uma cidade'\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\">({ cidade: 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\">    outputSchema: z.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">object\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({ tempC: 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\">  },\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\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\">cidade\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 código real: chama uma API de clima\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\"> r\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\"> fetch\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`\u002Fapi\u002Fclima?c=${\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">cidade\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:#D73A49;--shiki-dark:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { tempC: (\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> r.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">json\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()).temp };\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\">\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>",[385],{"text":386,"type":72},"export const buscarClima = ai.defineTool(\n  {\n    name: 'buscarClima',\n    description: 'Retorna o clima atual de uma cidade',\n    inputSchema: z.object({ cidade: z.string() }),\n    outputSchema: z.object({ tempC: z.number() }),\n  },\n  async ({ cidade }) => {\n    \u002F\u002F código real: chama uma API de clima\n    const r = await fetch(`\u002Fapi\u002Fclima?c=${cidade}`);\n    return { tempC: (await r.json()).temp };\n  }\n);\n",{"type":93},{"type":95,"attrs":389,"content":391},{"id":390,"level":36},"h_gk04",[392],{"text":393,"type":72},"Part 4 — Production: multimodality, security and lifecycle",{"type":66,"attrs":395,"content":397},{"id":396},"p_gk040",[398,400,404],{"text":399,"type":72},"Raw text, media via Handlebars, HTTPS URLs, and Base64 PDFs enter through uniform abstractions: the framework handles conversion and encoding and assembles a homogeneous multimodal array. Before deploy, the command ",{"text":401,"type":72,"marks":402},"genkit start",[403],{"type":77},{"text":405,"type":72}," spins up a local Dev UI with a trace inspector (waterfall and timing of each step), model runner, and token counting.",{"type":66,"attrs":407,"content":409},{"id":408},"p_gk041",[410,412,416],{"text":411,"type":72},"At the edge, exposing generative endpoints without protection is ",{"text":413,"type":72,"marks":414},"severe financial risk",[415],{"type":77},{"text":417,"type":72},". Keys go to Secret Manager (outside the code), authentication is native via Cloud Functions, and App Check blocks fraudulent requests at the perimeter (DeviceCheck \u002F Play Integrity), ensuring that only genuine app instances incur charges.",{"type":66,"attrs":419,"content":421},{"id":420},"p_gk042",[422],{"text":423,"type":72},"Structural isolation also defines the deploy targets by language — and here is the direct bridge to the frontend: Next.js and Angular enter via Firebase App Hosting.",{"type":425,"attrs":426,"content":428},"table",{"id":427},"tbl_gk01",[429,470,509,547,585],{"type":430,"content":431},"tableRow",[432,443,452,461],{"type":433,"attrs":434,"content":436},"tableHeader",{"align":9,"colspan":435,"rowspan":435,"colwidth":9},1,[437],{"type":66,"attrs":438,"content":440},{"id":439},"p_th1",[441],{"text":442,"type":72},"Language",{"type":433,"attrs":444,"content":445},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[446],{"type":66,"attrs":447,"content":449},{"id":448},"p_th2",[450],{"text":451,"type":72},"Model (ex.)",{"type":433,"attrs":453,"content":454},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[455],{"type":66,"attrs":456,"content":458},{"id":457},"p_th3",[459],{"text":460,"type":72},"Vector store",{"type":433,"attrs":462,"content":463},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[464],{"type":66,"attrs":465,"content":467},{"id":466},"p_th4",[468],{"text":469,"type":72},"Deploy target",{"type":430,"content":471},[472,482,491,500],{"type":473,"attrs":474,"content":475},"tableCell",{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[476],{"type":66,"attrs":477,"content":479},{"id":478},"p_tc11",[480],{"text":481,"type":72},"JS \u002F TS",{"type":473,"attrs":483,"content":484},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[485],{"type":66,"attrs":486,"content":488},{"id":487},"p_tc12",[489],{"text":490,"type":72},"Gemini",{"type":473,"attrs":492,"content":493},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[494],{"type":66,"attrs":495,"content":497},{"id":496},"p_tc13",[498],{"text":499,"type":72},"Cloud Firestore",{"type":473,"attrs":501,"content":502},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[503],{"type":66,"attrs":504,"content":506},{"id":505},"p_tc14",[507],{"text":508,"type":72},"Firebase App Hosting (Next.js \u002F Angular)",{"type":430,"content":510},[511,520,529,538],{"type":473,"attrs":512,"content":513},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[514],{"type":66,"attrs":515,"content":517},{"id":516},"p_tc21",[518],{"text":519,"type":72},"Go",{"type":473,"attrs":521,"content":522},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[523],{"type":66,"attrs":524,"content":526},{"id":525},"p_tc22",[527],{"text":528,"type":72},"Claude",{"type":473,"attrs":530,"content":531},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[532],{"type":66,"attrs":533,"content":535},{"id":534},"p_tc23",[536],{"text":537,"type":72},"Pinecone",{"type":473,"attrs":539,"content":540},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[541],{"type":66,"attrs":542,"content":544},{"id":543},"p_tc24",[545],{"text":546,"type":72},"Cloud Run (binary)",{"type":430,"content":548},[549,558,567,576],{"type":473,"attrs":550,"content":551},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[552],{"type":66,"attrs":553,"content":555},{"id":554},"p_tc31",[556],{"text":557,"type":72},"Python",{"type":473,"attrs":559,"content":560},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[561],{"type":66,"attrs":562,"content":564},{"id":563},"p_tc32",[565],{"text":566,"type":72},"GPT-4o",{"type":473,"attrs":568,"content":569},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[570],{"type":66,"attrs":571,"content":573},{"id":572},"p_tc33",[574],{"text":575,"type":72},"pgvector",{"type":473,"attrs":577,"content":578},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[579],{"type":66,"attrs":580,"content":582},{"id":581},"p_tc34",[583],{"text":584,"type":72},"Cloud Functions",{"type":430,"content":586},[587,596,605,614],{"type":473,"attrs":588,"content":589},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[590],{"type":66,"attrs":591,"content":593},{"id":592},"p_tc41",[594],{"text":595,"type":72},"Dart",{"type":473,"attrs":597,"content":598},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[599],{"type":66,"attrs":600,"content":602},{"id":601},"p_tc42",[603],{"text":604,"type":72},"Ollama (local)",{"type":473,"attrs":606,"content":607},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[608],{"type":66,"attrs":609,"content":611},{"id":610},"p_tc43",[612],{"text":613,"type":72},"Redis",{"type":473,"attrs":615,"content":616},{"align":9,"colspan":435,"rowspan":435,"colwidth":9},[617],{"type":66,"attrs":618,"content":620},{"id":619},"p_tc44",[621],{"text":622,"type":72},"Local telemetry",{"type":66,"attrs":624,"content":626},{"id":625},"p_gk043",[627],{"text":628,"type":72},"Everything ties together in a four-phase cycle around Genkit:",{"type":203,"attrs":630},{"id":631,"svg":632,"label":633},"svg_gk04","\u003Csvg viewBox=\"0 0 680 170\" xmlns=\"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg\" font-family=\"system-ui, -apple-system, sans-serif\">\u003Cdefs>\u003Cmarker id=\"cycArrow\" 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>\u003Crect x=\"0\" y=\"0\" width=\"680\" height=\"170\" fill=\"#ffffff\"\u002F>\u003Ctext x=\"340\" y=\"30\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"#0f172a\">Ciclo operacional\u003C\u002Ftext>\u003Crect x=\"24\" y=\"56\" width=\"140\" height=\"56\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"94\" y=\"82\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Construir\u003C\u002Ftext>\u003Ctext x=\"94\" y=\"100\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">Tipagem · Tools\u003C\u002Ftext>\u003Cline x1=\"166\" y1=\"84\" x2=\"190\" y2=\"84\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#cycArrow)\"\u002F>\u003Crect x=\"192\" y=\"56\" width=\"130\" height=\"56\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"257\" y=\"82\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Iterar\u003C\u002Ftext>\u003Ctext x=\"257\" y=\"100\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">Dev UI · traces\u003C\u002Ftext>\u003Cline x1=\"324\" y1=\"84\" x2=\"348\" y2=\"84\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#cycArrow)\"\u002F>\u003Crect x=\"350\" y=\"56\" width=\"130\" height=\"56\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"415\" y=\"82\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Deploy\u003C\u002Ftext>\u003Ctext x=\"415\" y=\"100\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">App Hosting\u003C\u002Ftext>\u003Cline x1=\"482\" y1=\"84\" x2=\"506\" y2=\"84\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#cycArrow)\"\u002F>\u003Crect x=\"508\" y=\"56\" width=\"148\" height=\"56\" rx=\"10\" fill=\"#eff6ff\" stroke=\"#94a3b8\" stroke-width=\"1.5\"\u002F>\u003Ctext x=\"582\" y=\"82\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"600\" fill=\"#1e293b\">Monitorar\u003C\u002Ftext>\u003Ctext x=\"582\" y=\"100\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">Telemetry · avaliações\u003C\u002Ftext>\u003Cpath d=\"M 582 112 L 582 140 L 94 140 L 94 112\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" stroke-dasharray=\"4 4\" marker-end=\"url(#cycArrow)\"\u002F>\u003Ctext x=\"340\" y=\"156\" text-anchor=\"middle\" font-size=\"12\" fill=\"#64748b\">ciclo contínuo\u003C\u002Ftext>\u003C\u002Fsvg>","Genkit operational cycle",{"type":93},{"type":95,"attrs":636,"content":638},{"id":637,"level":36},"h_gk05",[639],{"text":640,"type":72},"Conclusion: orchestration instead of magic prompts",{"type":66,"attrs":642,"content":644},{"id":643},"p_gk050",[645,647,651],{"text":646,"type":72},"The arc of this material describes a maturation that other computing disciplines have already gone through: AI integration is leaving the artisanal phase — in which the result depended on nailing the prompt — and entering the engineering phase, in which the result depends on the quality of the ",{"text":648,"type":72,"marks":649},"system",[650],{"type":111},{"text":652,"type":72},".",{"type":66,"attrs":654,"content":656},{"id":655},"p_gk051",[657],{"text":658,"type":72},"Each abstraction presented — typed Flows, Dotprompt, RAG, reranking, Tools, edge security — is an engineering response to a specific and reproducible failure of isolated LLM calls. Reliability in production is no longer a stroke of luck; it is an orchestrated and observable process.",{"type":66,"attrs":660},{"id":661},"p_gk052","Discover how Firebase Genkit orchestrates LLMs in production with Zod and RAG. Reduce from ~4,000 to ~830 tokens per query without losing precision.","2026-08-24T14:53:53.315534+00:00",[665,688,704,718],{"id":666,"slug":667,"title":668,"excerpt":669,"image":670,"featured":44,"groupId":671,"publishedAt":672,"readingTime":673,"views":48,"author":674,"category":675,"tags":676},"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":50,"avatar":9},{"slug":19,"name":20,"color":21},[677,680,681,684,685],{"slug":678,"name":679},"china","China",{"slug":57,"name":58},{"slug":682,"name":683},"infraestrutura","Infraestrutura",{"slug":54,"name":55},{"slug":686,"name":687},"performance","Performance",{"id":689,"slug":690,"title":691,"excerpt":692,"image":693,"featured":44,"groupId":694,"publishedAt":695,"readingTime":29,"views":48,"author":696,"category":697,"tags":698},"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",{"name":50,"avatar":9},{"slug":19,"name":20,"color":21},[699,700,701],{"slug":54,"name":55},{"slug":57,"name":58},{"slug":702,"name":703},"openclaw","OpenClaw",{"id":705,"slug":706,"title":707,"excerpt":708,"image":709,"featured":44,"groupId":710,"publishedAt":711,"readingTime":712,"views":48,"author":713,"category":714,"tags":715},"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":50,"avatar":9},{"slug":19,"name":20,"color":21},[716,717],{"slug":54,"name":55},{"slug":686,"name":687},{"id":719,"slug":720,"title":721,"excerpt":722,"image":723,"featured":44,"groupId":724,"publishedAt":725,"readingTime":47,"views":48,"author":726,"category":727,"tags":728},"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",{"name":50,"avatar":9},{"slug":19,"name":20,"color":21},[729,730],{"slug":54,"name":55},{"slug":57,"name":58},{"pt":732,"en":40},"orquestrando-ia-em-producao-com-firebase-genkit-como-reduzir-o-tempo-de-deploy-em-30"]