<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Xavier Portilla Edo on Medium]]></title>
        <description><![CDATA[Stories by Xavier Portilla Edo on Medium]]></description>
        <link>https://medium.com/@xavidop?source=rss-933813d028b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TQxktbPiaV4Yp45RKP3Lhw.jpeg</url>
            <title>Stories by Xavier Portilla Edo on Medium</title>
            <link>https://medium.com/@xavidop?source=rss-933813d028b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 03:48:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xavidop/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Genkit Middleware: Intercept, Extend and Harden your Gen AI Pipelines]]></title>
            <link>https://xavidop.medium.com/genkit-middleware-intercept-extend-and-harden-your-gen-ai-pipelines-5f1faefe6f4d?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f1faefe6f4d</guid>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 14 May 2026 11:16:03 GMT</pubDate>
            <atom:updated>2026-05-14T11:16:03.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZbvvMHg3pZSanF9L2JbDA.png" /></figure><h3>Introduction</h3><p>If you have been building anything non-trivial with Genkit, you have probably bumped into the same set of cross-cutting concerns over and over again: retrying transient model errors, falling back to a cheaper model when quota explodes, gating tool execution behind human approval, injecting filesystem access for coding agents, logging every request and response for observability…</p><p>Until now, you ended up either wrapping ai.generate() calls by hand or writing ad-hoc helpers that ended up duplicated across flows. The new <strong>Genkit Middleware</strong> changes that. It introduces a first-class, composable middleware layer for the generate() pipeline, with hooks for the <strong>model</strong>, the <strong>tool execution</strong> and the <strong>high-level generation loop</strong>, plus a small but very useful set of official middlewares published in the brand new @genkit-ai/middleware package.</p><p>This article is a practical tour of what the new middleware system gives you, the built-in middlewares you can drop in today, and how to write your own with generateMiddleware.</p><blockquote><em>The official documentation lives at </em><a href="https://genkit.dev/docs/js/middleware/"><em>Genkit Middleware</em></a><em>. All examples below assume the JavaScript/TypeScript SDK.</em></blockquote><blockquote><em>A quick reminder: although this article focuses on the JS/TS middleware API, </em><strong><em>Genkit is a multi-language framework</em></strong><em>. The official SDKs cover </em><strong><em>JavaScript/TypeScript</em></strong><em> (primary, stable), </em><strong><em>Go</em></strong><em>, </em><strong><em>Python</em></strong><em> (preview) and </em><strong><em>Dart/Flutter</em></strong><em> (preview), and there is a community-maintained </em><strong><em>Java</em></strong><em> SDK used in production. The middleware concepts described here are JS/TS-specific today, but the underlying </em><em>generate() pipeline exists across all SDKs and the same patterns are landing on the other runtimes.</em></blockquote><h3>What is middleware in Genkit</h3><p>Conceptually, Genkit middleware behaves like the middleware you already know from Express or Koa, only applied to the LLM lifecycle instead of HTTP requests:</p><ol><li>A generate() call is intercepted before it reaches the model.</li><li>Each middleware can inspect or modify the request, decide whether to call next(), and inspect or modify the response on the way back.</li><li>Multiple middlewares can be chained. They run in the order they are declared and unwind in reverse order, exactly like an onion.</li></ol><p>What makes Genkit’s design interesting is that it does not give you a single chokepoint, it gives you <strong>three orthogonal interception phases</strong>:</p><ul><li><strong>model</strong> — wraps the call to the underlying model. Perfect for retries, fallbacks, request/response logging or response transformations.</li><li><strong>tool</strong> — wraps tool execution. Ideal for approvals, sandboxing, audit logs or input/output validation.</li><li><strong>generate</strong> — wraps the whole high-level generation loop (prompting, tool calling, output parsing). Best for things like injecting tools or system instructions before the loop starts.</li></ul><p>You opt in per call via a use: array, which keeps things explicit and avoids global side effects:</p><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>  prompt: &#39;Hello&#39;,<br>  use: [retry({ maxRetries: 3 }), loggerMiddleware({ verbose: true })],<br>});</pre><h3>Installation</h3><p>The official middlewares ship in their own package, decoupled from the Genkit core:</p><pre>npm install @genkit-ai/middleware<br># or<br>pnpm add @genkit-ai/middleware</pre><p>You still need genkit itself and a model provider plugin (for example @genkit-ai/google-genai).</p><h3>The built-in middleware catalogue</h3><p>Let’s go through the five middlewares the Genkit team ships out of the box.</p><h3>filesystem — give the model a sandboxed file system</h3><p>filesystem injects a standard set of file manipulation tools (list_files, read_file, write_file, search_and_replace) into the generation loop, restricted to a root directory of your choice.</p><pre>import { genkit } from &#39;genkit&#39;;<br>import { googleAI } from &#39;@genkit-ai/google-genai&#39;;<br>import { filesystem } from &#39;@genkit-ai/middleware&#39;;</pre><pre>const ai = genkit({ plugins: [googleAI()] });</pre><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>  prompt: &#39;Create a hello world Node app in the workspace&#39;,<br>  use: [<br>    filesystem({<br>      rootDirectory: &#39;./workspace&#39;,<br>      allowWriteAccess: true,<br>    }),<br>  ],<br>});</pre><p>Useful options:</p><ul><li>rootDirectory (required) — sandbox root, all paths are confined to it.</li><li>allowWriteAccess — defaults to false. Read-only by default is a sane choice for safety.</li><li>toolNamePrefix — namespace the injected tools to avoid collisions with your own.</li></ul><p>This is essentially the building block for a “coding agent” pattern, without you having to write tool definitions or path validation logic.</p><h3>skills — auto-load Markdown skills as system context</h3><p>skills scans a directory for SKILL.md files (plus their YAML frontmatter), injects relevant ones into the system prompt, and exposes a use_skill tool the model can call when it needs more specific guidance.</p><pre>import { skills } from &#39;@genkit-ai/middleware&#39;;</pre><pre>const response = await ai.generate({<br>  prompt: &#39;How do I run tests in this repo?&#39;,<br>  use: [skills({ skillPaths: [&#39;./skills&#39;] })],<br>});</pre><p>Think of it as a lightweight, file-based knowledge layer: every skill is a self-contained Markdown file with metadata, and the middleware decides when to surface them. It is a really clean alternative to ad-hoc system prompt soup.</p><h3>toolApproval — human-in-the-loop for tool calls</h3><p>toolApproval enforces an allowlist of tools the model is allowed to execute autonomously. Anything outside the list raises a ToolInterruptError, so you can pause execution, ask the user, and resume.</p><pre>import { genkit, restartTool } from &#39;genkit&#39;;<br>import { toolApproval } from &#39;@genkit-ai/middleware&#39;;</pre><pre>const response = await ai.generate({<br>  prompt: &#39;write a file&#39;,<br>  tools: [writeFileTool],<br>  use: [toolApproval({ approved: [] })], // empty list -&gt; always interrupt<br>});</pre><pre>if (response.finishReason === &#39;interrupted&#39;) {<br>  const interrupt = response.interrupts[0];</pre><pre>  // ... ask the user, then mark the tool call as approved<br>  const approvedPart = restartTool(interrupt, { toolApproved: true });</pre><pre>  const resumedResponse = await ai.generate({<br>    messages: response.messages,<br>    resume: { restart: [approvedPart] },<br>    use: [toolApproval({ approved: [] })],<br>  });<br>}</pre><p>This is exactly the pattern you want for any agent that touches the real world (filesystem writes, payments, sending emails). No more home-grown approval flags scattered across the codebase.</p><h3>retry — exponential backoff with jitter for transient errors</h3><p>The retry middleware retries failed model calls on transient status codes (UNAVAILABLE, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED, ABORTED, INTERNAL) using exponential backoff with jitter.</p><pre>import { retry } from &#39;@genkit-ai/middleware&#39;;</pre><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-pro-latest&#39;),<br>  prompt: &#39;Heavy reasoning task...&#39;,<br>  use: [<br>    retry({<br>      maxRetries: 3,<br>      initialDelayMs: 1000,<br>      backoffFactor: 2,<br>    }),<br>  ],<br>});</pre><p>Knobs you actually care about:</p><ul><li>maxRetries (default 3)</li><li>statuses — which status codes to retry on</li><li>initialDelayMs / maxDelayMs / backoffFactor</li><li>noJitter — if you really want deterministic delays</li></ul><p>This is one of those things every team writes once, badly. Having it in the framework is a very welcome change.</p><h3>fallback — gracefully degrade to a different model</h3><p>fallback switches to an alternate model when the primary one fails on configurable status codes. The classic use case is &quot;try Pro first, fall back to Flash when quota is exhausted&quot;:</p><pre>import { fallback } from &#39;@genkit-ai/middleware&#39;;</pre><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-pro-latest&#39;),<br>  prompt: &#39;Try the pro model first...&#39;,<br>  use: [<br>    fallback({<br>      models: [googleAI.model(&#39;gemini-flash-latest&#39;)],<br>      statuses: [&#39;RESOURCE_EXHAUSTED&#39;],<br>    }),<br>  ],<br>});</pre><p>You can chain multiple fallback models, and isolateConfig lets you decide whether the fallback inherits the original request configuration or starts clean (handy when the fallback model does not support the same options as the primary).</p><h3>Building your own middleware with generateMiddleware</h3><p>The same primitive that powers all the built-ins is exposed for you. The generateMiddleware helper gives you typed config schemas (via Zod) and access to the ai instance.</p><p>Here is the canonical “logger” example, straight from the docs but lightly annotated:</p><pre>import { generateMiddleware, z } from &#39;genkit&#39;;</pre><pre>export const loggerMiddleware = generateMiddleware(<br>  {<br>    name: &#39;loggerMiddleware&#39;,<br>    description: &#39;Logs requests and responses&#39;,<br>    configSchema: z.object({<br>      verbose: z.boolean().optional(),<br>    }),<br>  },<br>  ({ config, ai }) =&gt; {<br>    return {<br>      // Phase 1: intercept the model call<br>      model: async (req, ctx, next) =&gt; {<br>        if (config?.verbose) {<br>          console.log(&#39;Request:&#39;, JSON.stringify(req));<br>        }<br>        const resp = await next(req, ctx);<br>        if (config?.verbose) {<br>          console.log(&#39;Response:&#39;, JSON.stringify(resp));<br>        }<br>        return resp;<br>      },<br>      // You could also add `tool: ...` and `generate: ...` hooks here.<br>    };<br>  }<br>);</pre><p>Using it is identical to the official ones:</p><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>  prompt: &#39;Hello&#39;,<br>  use: [loggerMiddleware({ verbose: true })],<br>});</pre><p>A few patterns I have found very useful:</p><ul><li><strong>PII redaction</strong> — implement a model hook that scrubs the request prompt and the response text against a regex/dictionary, returning the cleaned version.</li><li><strong>Cost accounting</strong> — wrap the model hook to read usage tokens from the response, and emit them to your metrics backend tagged by user/feature.</li><li><strong>Per-tenant quotas</strong> — use the generate hook to check a counter (Redis, Firestore...) before calling next(); throw your own custom error if the tenant is over quota.</li><li><strong>Caching</strong> — keyed on a hash of the model + request, return a cached response if hit, otherwise call next() and persist the result.</li></ul><p>For more inspiration, the source of the official middlewares is open in the <a href="https://github.com/genkit-ai/genkit/tree/main/js/plugins/middleware">Genkit GitHub repository</a>, and reading them is genuinely educational.</p><h3>Composition: stacking middlewares</h3><p>Middlewares compose in array order. A reasonable production stack might look like this:</p><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-pro-latest&#39;),<br>  prompt: userPrompt,<br>  tools: myTools,<br>  use: [<br>    loggerMiddleware({ verbose: false }),       // outermost: see everything<br>    retry({ maxRetries: 3 }),                   // recover from transient failures<br>    fallback({                                  // degrade if Pro is overloaded<br>      models: [googleAI.model(&#39;gemini-flash-latest&#39;)],<br>      statuses: [&#39;RESOURCE_EXHAUSTED&#39;],<br>    }),<br>    toolApproval({ approved: [&#39;searchDocs&#39;] }), // gate dangerous tools<br>  ],<br>});</pre><p>The order matters: outer middlewares see the result of the inner ones. Put logging on the outside if you want it to record the final state after retries and fallbacks; put it on the inside if you want to see every individual model attempt.</p><h3>The importance of middleware for production agents</h3><p>Genkit Middleware is one of those features that does not look flashy in a changelog but quietly fixes a lot of real-world friction. It pushes Genkit closer to a “batteries-included” framework for production agents:</p><ul><li>Cross-cutting concerns are no longer copy-pasted across flows.</li><li>Safety-critical behavior (approvals, sandboxes, fallbacks) is declarative.</li><li>The model / tool / generate split gives you precise control without forcing you to monkey-patch.</li><li>The middleware contract is small enough that the community can ship plugins that interoperate.</li></ul><p>If you maintain any non-trivial Genkit application, the upgrade is a no-brainer. Drop in retry and fallback first, you will probably see incidents disappear within the week. Then start writing your own middlewares for the things that are unique to your domain.</p><h3>Conclusion</h3><p>Middleware turns Genkit’s generate() from &quot;a function you call&quot; into &quot;a pipeline you compose&quot;. The official @genkit-ai/middleware package covers the most common production needs (filesystem access, skills, tool approval, retries, fallbacks), and generateMiddleware makes writing your own a 20-line affair instead of a refactor.</p><p>For the next steps, take a look at:</p><ul><li><a href="https://genkit.dev/docs/js/middleware/">Genkit Middleware documentation</a></li><li><a href="https://github.com/genkit-ai/genkit/tree/main/js/plugins/middleware">Genkit middleware source on GitHub</a></li><li><a href="https://genkit.dev/docs/js/flows/">Genkit flows</a> — middleware composes especially well with typed flows</li><li><a href="https://genkit.dev/docs/js/tool-calling/">Tool calling</a> and <a href="https://genkit.dev/docs/js/interrupts/">Interrupts</a> — the foundation that toolApproval builds on</li></ul><p>Happy hacking, and may your fallback models always be cheaper than your primary one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f1faefe6f4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vercel AI SDK Middleware vs Genkit Middleware: a Hands-On Comparison]]></title>
            <link>https://xavidop.medium.com/vercel-ai-sdk-middleware-vs-genkit-middleware-a-hands-on-comparison-03b97bf4c0e4?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/03b97bf4c0e4</guid>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 14 May 2026 11:07:47 GMT</pubDate>
            <atom:updated>2026-05-14T11:07:47.631Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qs_0Jyd3dhLhTZmoxSDedA.png" /></figure><h3>Introduction</h3><p>Two of the most popular Gen AI frameworks in JavaScript/TypeScript, <strong>Vercel AI SDK</strong> and <strong>Genkit</strong>, both ship a middleware system to extend their model calls with cross-cutting behavior: logging, caching, RAG, retries, fallbacks, guardrails, tool approval, etc.</p><p>On the surface they look very similar. In practice, they sit at different abstraction levels and embody different philosophies. This article puts them side by side using their official docs as the source of truth:</p><ul><li><a href="https://ai-sdk.dev/docs/ai-sdk-core/middleware">Vercel AI SDK — Language Model Middleware</a></li><li><a href="https://genkit.dev/docs/js/middleware/">Genkit — Middleware</a></li></ul><p>I’ll walk through the API surface, the built-ins, how composition works, how you write your own, and finish with a concrete decision matrix.</p><blockquote><em>One scope note before we dive in: </em><strong><em>Vercel AI SDK is JavaScript/TypeScript only</em></strong><em>, while </em><strong><em>Genkit is a multi-language framework</em></strong><em> with official SDKs for </em><strong><em>JavaScript/TypeScript</em></strong><em> (primary, stable), </em><strong><em>Go</em></strong><em>, </em><strong><em>Python</em></strong><em> (preview) and </em><strong><em>Dart/Flutter</em></strong><em> (preview), plus a community-maintained </em><strong><em>Java</em></strong><em> SDK. The middleware comparison below is JS/TS-to-JS/TS, but if you also need to share patterns with Go, Python, Dart or Java services, that is a Genkit-only conversation.</em></blockquote><h3>The mental model</h3><h3>Vercel AI SDK: wrap the model</h3><p>In Vercel’s world, middleware is a <strong>decorator over the language model itself</strong>. You take a model, wrap it, and the result is “still a model”. It plugs into generateText, streamText, generateObject, etc. without those functions even knowing middleware exists.</p><pre>import { wrapLanguageModel, streamText } from &#39;ai&#39;;</pre><pre>const wrappedLanguageModel = wrapLanguageModel({<br>  model: yourModel,<br>  middleware: yourLanguageModelMiddleware,<br>});</pre><pre>const result = streamText({<br>  model: wrappedLanguageModel,<br>  prompt: &#39;What cities are in the United States?&#39;,<br>});</pre><p>This is very clean: the middleware travels with the model and is transparent to the rest of your code.</p><h3>Genkit: opt in per call</h3><p>Genkit takes the opposite stance. Instead of wrapping the model, you pass middlewares as part of each generate() call via the use: array, and you can intercept three different phases of the pipeline: the <strong>model</strong>, the <strong>tools</strong>, and the high-level <strong>generate</strong> loop.</p><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>  prompt: &#39;Hello&#39;,<br>  use: [retry({ maxRetries: 3 }), loggerMiddleware({ verbose: true })],<br>});</pre><p>Trade-off: it is more explicit (you see exactly what runs at each call site), at the cost of being noisier when you want a global behavior. Both styles are easy to wrap in a small helper.</p><h3>The hooks side by side</h3><h3>Vercel AI SDK</h3><p>Three hooks, all centered on the language model contract:</p><ul><li>transformParams — mutate the request before it hits doGenerate or doStream.</li><li>wrapGenerate — wrap the non-streaming call, observe and modify the result.</li><li>wrapStream — wrap the streaming call. You typically pipe the stream through a TransformStream to inspect or rewrite chunks.</li></ul><p>Example: the canonical logging middleware, including streaming:</p><pre>import type {<br>  LanguageModelV3Middleware,<br>  LanguageModelV3StreamPart,<br>} from &#39;@ai-sdk/provider&#39;;</pre><pre>export const yourLogMiddleware: LanguageModelV3Middleware = {<br>  wrapGenerate: async ({ doGenerate, params }) =&gt; {<br>    console.log(&#39;doGenerate called&#39;, params);<br>    const result = await doGenerate();<br>    console.log(&#39;generated text:&#39;, result.text);<br>    return result;<br>  },</pre><pre>  wrapStream: async ({ doStream, params }) =&gt; {<br>    const { stream, ...rest } = await doStream();<br>    let generatedText = &#39;&#39;;</pre><pre>    const transformStream = new TransformStream&lt;<br>      LanguageModelV3StreamPart,<br>      LanguageModelV3StreamPart<br>    &gt;({<br>      transform(chunk, controller) {<br>        if (chunk.type === &#39;text-delta&#39;) generatedText += chunk.delta;<br>        controller.enqueue(chunk);<br>      },<br>      flush() {<br>        console.log(&#39;stream finished:&#39;, generatedText);<br>      },<br>    });</pre><pre>    return { stream: stream.pipeThrough(transformStream), ...rest };<br>  },<br>};</pre><h3>Genkit</h3><p>Three hooks too, but cutting along <strong>execution phase</strong> instead of stream vs non-stream:</p><ul><li>model — wraps the model invocation. Streaming and non-streaming go through the same hook.</li><li>tool — wraps tool execution. This has no equivalent in Vercel&#39;s spec (tools are not part of the language-model middleware contract there).</li><li>generate — wraps the entire high-level generation loop, including tool calling and output parsing.</li></ul><pre>import { generateMiddleware, z } from &#39;genkit&#39;;</pre><pre>export const loggerMiddleware = generateMiddleware(<br>  {<br>    name: &#39;loggerMiddleware&#39;,<br>    description: &#39;Logs requests and responses&#39;,<br>    configSchema: z.object({ verbose: z.boolean().optional() }),<br>  },<br>  ({ config }) =&gt; ({<br>    model: async (req, ctx, next) =&gt; {<br>      if (config?.verbose) console.log(&#39;Request:&#39;, JSON.stringify(req));<br>      const resp = await next(req, ctx);<br>      if (config?.verbose) console.log(&#39;Response:&#39;, JSON.stringify(resp));<br>      return resp;<br>    },<br>  })<br>);</pre><p>Two important differences:</p><ol><li><strong>Tools are first-class citizens</strong> in Genkit middleware. You can intercept tool execution itself, which is exactly what powers toolApproval. In Vercel AI SDK, tool gating typically lives in your application code or inside experimental_prepareStep for agents, not in the middleware spec.</li><li><strong>Genkit middleware factories carry a Zod config schema</strong>, so misconfigured middleware fails fast with a clear error. Vercel middleware is a plain object that conforms to LanguageModelV3Middleware; configuration is your responsibility.</li></ol><h3>Built-ins, head to head</h3><h3>Vercel AI SDK</h3><p>Centered on adapting the model contract to real-world quirks:</p><ul><li>extractReasoningMiddleware — pulls &lt;think&gt;...&lt;/think&gt; blocks (and similar) out of the text and surfaces them as a reasoning property. Crucial for DeepSeek R1 and friends.</li><li>extractJsonMiddleware — strips Markdown code fences from JSON outputs so Output.object() keeps working with chatty models.</li><li>simulateStreamingMiddleware — fakes a streaming interface on top of a non-streaming model, so your UI code stays consistent.</li><li>defaultSettingsMiddleware — pins default settings (temperature, max output tokens, provider options).</li><li>addToolInputExamplesMiddleware — for providers that don&#39;t support inputExamples natively, serializes them into the tool description.</li></ul><p>The theme is clear: <strong>smooth over differences between providers</strong>. Vercel runs an SDK that has to talk to dozens of model providers, so its middleware library reflects that.</p><h3>Genkit</h3><p>Centered on production patterns and agentic behavior:</p><ul><li>filesystem — sandboxed file tools (list_files, read_file, write_file, search_and_replace) restricted to a root directory.</li><li>skills — auto-injects SKILL.md files into the system prompt and exposes a use_skill tool.</li><li>toolApproval — human-in-the-loop gating for tool calls, with first-class ToolInterruptError and resume support.</li><li>retry — exponential backoff with jitter for transient errors.</li><li>fallback — automatic switch to a different model on failure.</li></ul><p>Theme: <strong>production hardening and agent ergonomics</strong>. Genkit assumes you’ll plug in your own providers but want batteries for retry/fallback/approval/skills.</p><p>Notice the very small overlap. If you wanted “extract reasoning” in Genkit you’d write it as a custom middleware (10–20 lines). If you wanted “retry with backoff” in Vercel AI SDK, same thing. Each ecosystem chose to ship the middlewares its users were asking for the most.</p><h3>Composition</h3><h3>Vercel AI SDK</h3><p>You pass an array to wrapLanguageModel. The order is &quot;outermost first&quot;: the first middleware in the array runs outside the second one.</p><pre>const wrappedLanguageModel = wrapLanguageModel({<br>  model: yourModel,<br>  middleware: [firstMiddleware, secondMiddleware],<br>});<br>// applied as: firstMiddleware(secondMiddleware(yourModel))</pre><p>Composition is <strong>static</strong>. The wrapped model is a long-lived value. Great for “configure once at startup” scenarios.</p><h3>Genkit</h3><p>You pass an array to use: on every call. Order is the same onion model: outer middlewares wrap inner ones.</p><pre>const response = await ai.generate({<br>  model: googleAI.model(&#39;gemini-pro-latest&#39;),<br>  prompt: userPrompt,<br>  use: [<br>    loggerMiddleware({ verbose: false }),<br>    retry({ maxRetries: 3 }),<br>    fallback({<br>      models: [googleAI.model(&#39;gemini-flash-latest&#39;)],<br>      statuses: [&#39;RESOURCE_EXHAUSTED&#39;],<br>    }),<br>    toolApproval({ approved: [&#39;searchDocs&#39;] }),<br>  ],<br>});</pre><p>Composition is <strong>dynamic</strong>. You can change the stack per request based on user, tenant, A/B test, environment, etc. without rebuilding model instances.</p><h3>Per-request metadata</h3><p>A common need is to pass per-request context (user id, tenant, trace id…) into a middleware.</p><p><strong>Vercel AI SDK</strong> uses providerOptions, namespaced by the middleware name:</p><pre>export const yourLogMiddleware: LanguageModelV3Middleware = {<br>  wrapGenerate: async ({ doGenerate, params }) =&gt; {<br>    console.log(&#39;METADATA&#39;, params?.providerMetadata?.yourLogMiddleware);<br>    return doGenerate();<br>  },<br>};</pre><pre>await generateText({<br>  model: wrapLanguageModel({ model: &#39;anthropic/claude-sonnet-4.5&#39;, middleware: yourLogMiddleware }),<br>  prompt: &#39;Invent a new holiday and describe its traditions.&#39;,<br>  providerOptions: {<br>    yourLogMiddleware: { hello: &#39;world&#39; },<br>  },<br>});</pre><p><strong>Genkit</strong> is more direct: middleware is invoked as a factory, so you pass config when you instantiate it for that call:</p><pre>use: [loggerMiddleware({ verbose: true, requestId: &#39;abc-123&#39; })],</pre><p>Both work, but the Genkit approach is type-checked end-to-end thanks to the Zod config schema, while Vercel’s providerOptions is more loosely typed.</p><h3>Streaming</h3><p>Vercel AI SDK has <strong>separate hooks</strong> for streaming and non-streaming, which is honest because the two have very different semantics. You almost always need to pipe the stream through a TransformStream.</p><p>Genkit folds streaming into the same model hook. The middleware sees the request and the response, and the underlying engine handles whether it was streamed. This is more ergonomic when your middleware doesn&#39;t need per-chunk logic, but if you do need to inspect chunks (say, for guardrails on partial output), you&#39;ll need to drop down to lower-level APIs.</p><h3>Tools and agents</h3><p>This is where the two systems diverge most.</p><p>In <strong>Vercel AI SDK</strong>, tools live above the middleware layer. The LanguageModelV3Middleware spec sits at the model level; agentic loops are handled by higher-level abstractions like generateText, streamText and the agent APIs (experimental_prepareStep, etc.).</p><p>In <strong>Genkit</strong>, the tool and generate hooks make tool execution and the agent loop first-class targets for middleware. This is what enables clean implementations of:</p><ul><li>Tool approval (toolApproval)</li><li>Tool sandboxing (filesystem)</li><li>Agent-level skill injection (skills)</li></ul><p>If you build a lot of agents with tool calling, Genkit’s middleware surface is genuinely more expressive.</p><h3>Observability and tracing</h3><p>Both frameworks are observable but in different shapes:</p><ul><li><strong>Genkit</strong> has a built-in Developer UI that shows traces of every generate() call, including middleware, tools, and nested flows. Middleware automatically participates in traces.</li><li><strong>Vercel AI SDK</strong> is OpenTelemetry-friendly and integrates naturally with Vercel’s @vercel/otel, AI Gateway and Vercel Observability. You can wire your middleware into spans yourself.</li></ul><p>If “open the Dev UI and see what every middleware did” is high on your list, Genkit wins. If you already live inside the Vercel platform, the AI SDK plays beautifully with the rest of the stack.</p><h3>A concrete decision guide</h3><p>I would reach for <strong>Vercel AI SDK middleware</strong> when:</p><ul><li>I want a very small, well-defined surface area: tweak params, wrap generate, wrap stream.</li><li>I am bouncing between many model providers and need normalization (reasoning extraction, JSON cleanup, default settings).</li><li>I prefer “configure the model once at startup” over “compose per call”.</li><li>I am already deep in the Vercel ecosystem (Next.js, AI Gateway, Vercel Observability).</li><li>Streaming-aware behavior with per-chunk transforms is a hard requirement.</li></ul><p>I would reach for <strong>Genkit middleware</strong> when:</p><ul><li>I am building agents with tool calling, and I need tool approval, sandboxing or skill injection.</li><li>I want production-grade retry and fallback behavior out of the box.</li><li>I want to compose middleware <strong>per request</strong> based on user, tenant or experiment.</li><li>I value the Developer UI and rich tracing over my entire pipeline.</li><li>I want typed, validated middleware configuration via Zod.</li></ul><p>And honestly, in many real systems you might use both: Vercel AI SDK on the front-end / edge for chat UX, and Genkit on the backend for orchestration, tool calling and agentic flows. The middleware contracts are scoped, you won’t get the kind of conflicts you would expect.</p><h3>Conclusion</h3><p>Vercel AI SDK middleware and Genkit middleware are two well-thought-out answers to the same question, asked from different vantage points.</p><ul><li>Vercel AI SDK treats middleware as a <strong>provider abstraction layer</strong>: you adapt and normalize what providers give you.</li><li>Genkit treats middleware as a <strong>production-pipeline composition layer</strong>: you orchestrate models, tools and agentic loops with reusable building blocks.</li></ul><p>Pick the one that matches the shape of your problem, and don’t be afraid to mix them. The best part of 2026 in JS/TS Gen AI is that both are mature, both are open source, and both let you write your own middleware in a handful of lines.</p><p>Further reading:</p><ul><li><a href="https://ai-sdk.dev/docs/ai-sdk-core/middleware">Vercel AI SDK — Language Model Middleware</a></li><li><a href="https://genkit.dev/docs/js/middleware/">Genkit Middleware documentation</a></li><li><a href="https://dev.to/genkit/2026-04-16-top-jsts-genai-frameworks-2026/">Top JS/TS Gen AI Frameworks for 2026</a></li><li><a href="https://github.com/genkit-ai/genkit">Genkit GitHub repository</a></li><li><a href="https://github.com/vercel/ai">Vercel AI SDK GitHub repository</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03b97bf4c0e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Using Python for Your Gen AI Apps, Use Go and Genkit Instead]]></title>
            <link>https://xavidop.medium.com/stop-using-python-for-your-gen-ai-apps-use-go-and-genkit-instead-68cda467be5d?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/68cda467be5d</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[genkit]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Wed, 06 May 2026 03:57:43 GMT</pubDate>
            <atom:updated>2026-05-06T04:07:47.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nwmf_wG5u9FyrGl2q1KuXg.png" /></figure><h3>Introduction</h3><p>For the last few years, every Gen AI tutorial, framework, and “hello world” has assumed one thing: that you are writing Python. It made sense at the start. The research community lives in Python, the model providers ship Python SDKs first, and the notebook culture is hard to beat for prototyping. But there is a quiet, important shift happening in 2026: the teams actually shipping AI features at scale are increasingly moving their <strong>production</strong> Gen AI workloads off Python, and onto languages built for services.</p><p>Go is at the center of that shift. And <a href="https://genkit.dev/docs/go/get-started/"><strong>Genkit Go</strong></a>, the Go flavor of Google’s open-source Gen AI framework, is the cleanest path I have seen to build production-ready AI services in Go: typed flows, structured output, built-in HTTP serving, observability, and a Developer UI, all from a single binary.</p><p>This article is two things at once. First, an honest argument about why Python is a poor fit for production Gen AI services. Second, a hands-on getting-started with Genkit Go so you can replace that Python microservice this week.</p><h3>Why Python Hurts in Production Gen AI</h3><p>Python is great for research and prototyping. But Gen AI applications are not really “AI code”, they are mostly <strong>I/O-heavy network services</strong> that happen to call a model. And that is exactly where Python struggles.</p><h3>Concurrency is a constant fight</h3><p>Gen AI workloads are dominated by long, concurrent network calls: streaming completions, tool calls, embedding requests, vector DB lookups, MCP servers. Go’s goroutines and channels were literally designed for this. In Python you have a choice between three uncomfortable options: threads (limited by the GIL), asyncio (which infects your entire codebase and breaks the moment one library is sync), or multiprocessing (heavy, awkward, and unfriendly to shared state). None of them feel native. All of them leak through your abstractions.</p><h3>Cold starts and memory footprint</h3><p>A Python AI service typically pulls in pydantic, httpx, an SDK or two, and a tokenizer. You are easily looking at 200, 400 MB of resident memory and several seconds of cold start before you serve a single request. A Go binary doing the same job is one statically linked file, tens of MB of RAM, and starts in milliseconds. On Cloud Run, Lambda, Azure Functions, or any autoscaling platform, this difference is not a micro-optimization, it is the difference between a service that scales to zero gracefully and one that does not.</p><h3>Dependency hell is worse for AI</h3><p>pip, poetry, uv, conda, venv, requirements.txt, pyproject.toml. Pin a Torch version, break a transitive dep. Upgrade an SDK, break Pydantic v1 vs v2. Every Python AI repo I have inherited has spent at least a day fixing the environment before running a single prompt. Go’s module system, with a single go.mod and go.sum, is boring, reproducible, and just works.</p><h3>Types are optional, and it shows</h3><p>Structured output, tool calling, and MCP all rely on <strong>schemas</strong>. In Python, the schema lives in Pydantic models, in docstrings, in comments, and sometimes in your head. In Go, the schema <strong>is</strong> the struct. The compiler enforces it. Genkit picks it up automatically via JSON schema tags. You cannot ship a flow whose input does not match what the model returns, because it will not compile.</p><h3>Deployment is a packaging exercise</h3><p>Python deployments are Dockerfiles full of system packages, base images that drift, and “works on my machine” surprises. Go deploys as a single static binary. FROM scratch, copy the binary, done. For AI services that need to run on Cloud Run, on Kubernetes, on the edge, or as a sidecar, that is a massive operational win.</p><h3>The performance ceiling is real</h3><p>Yes, the heavy lifting happens on the model provider’s GPUs. But your service still has to parse tokens off a streaming response, fan out tool calls, merge results, enforce timeouts, and push telemetry, <strong>per request, at concurrency</strong>. Go does that work an order of magnitude more efficiently than CPython, and without you having to think about it.</p><blockquote><em>None of this means Python is wrong for </em><strong><em>research</em></strong><em>. It means Python is the wrong default for the </em><strong><em>service</em></strong><em> that exposes that research to your users.</em></blockquote><h3>Go Is the Best Language for Agentic Coders</h3><p>There is one more reason to pick Go in 2026 that did not really exist two years ago: <strong>agentic coders</strong>. Tools like Claude Code, Cursor’s agent mode, GitHub Copilot’s agent, Gemini Code Assist, Codex, Aider, and the growing ecosystem of autonomous coding agents are now a real part of how software gets written. And it turns out that <strong>Go is the language they thrive in</strong>.</p><p>Why? It comes down to three properties of the language that align almost perfectly with how an LLM-based agent reasons about code:</p><h3>Strong, static typing closes the feedback loop</h3><p>Agentic coders work in a tight loop: write code, compile, read the error, fix, repeat. Go’s compiler is fast, strict, and brutally honest. When an agent generates a wrong call, the compiler tells it exactly what is wrong and where, in seconds. In Python, the same mistake might only surface at runtime, three layers deep, with a stack trace that requires the agent to spend tokens reasoning about dynamic behavior. Strong typing turns “guess and pray” into “verify and continue”.</p><h3>There is usually one obvious way to do something</h3><p>Python has at least four HTTP clients, three async paradigms, two type systems, and an opinion war about every major design decision. An agent has to choose, and choices cost tokens and increase the chance of going off the rails. Go is famously opinionated: one formatter (gofmt), one module system, one idiomatic way to handle errors, one standard layout. Less surface area means less ambiguity, which means <strong>less token consumption and more correct code per iteration</strong>.</p><h3>Tooling is built for machines, not just humans</h3><p>go build, go test, go vet, gopls, and staticcheck produce structured, parseable output. Agents can read it directly without heuristics. Combine that with go doc and the standard library being uniformly documented, and you give an agent a self-describing environment it can navigate without hallucinating.</p><h3>And then Genkit Go takes it one level further</h3><p>Genkit Go leans into the same properties:</p><ul><li>Flow inputs and outputs are <strong>Go structs</strong>, the schema is the type. An agent generating a new flow knows exactly what shape the data has, because the compiler will reject anything else.</li><li>The API surface is small and consistent: genkit.Init, genkit.DefineFlow, genkit.DefineTool, genkit.GenerateData, genkit.Handler. There is one obvious way to define a flow, one obvious way to expose it, one obvious way to call a model.</li><li>Tool definitions are typed end-to-end, so an agent writing a new tool gets compile-time guarantees that its signature matches what the runtime expects.</li></ul><p>The net effect is that an agentic coder pointed at a Genkit Go codebase will produce <strong>more correct code, in fewer iterations, with fewer tokens</strong> than the same agent pointed at an equivalent Python codebase. In a world where you are increasingly going to be the reviewer of agent-generated code rather than the author, that compounds fast.</p><h3>Why Genkit Go Specifically</h3><p>If you accept the premise that Go is the better runtime for Gen AI services, the next question is: which framework? You can absolutely call the Gemini, OpenAI, or Anthropic SDKs directly from Go. But you will quickly end up rebuilding the same primitives every Genkit user already has for free.</p><p>It is the same philosophy as <a href="https://xavidop.me/genkit/gcp/2026-02-10-genkit-java-101/">Genkit Java</a> and the JavaScript flavor I covered in <a href="https://xavidop.me/genkit/2026-04-16-top-jsts-genai-frameworks-2026/">my 2026 JS/TS Gen AI frameworks comparison</a>: a thin, opinionated, cloud-agnostic layer that turns “AI logic” into a <strong>typed function</strong> you can call, test, deploy, and observe.</p><h3>What We Are Going to Build</h3><p>A Go service exposing a single AI flow that generates a structured <strong>recipe</strong> from a main ingredient and optional dietary restrictions. It will:</p><ul><li>Accept a typed RecipeInput as input.</li><li>Call <strong>Gemini 3 Pro</strong> via the Google AI plugin.</li><li>Return a strongly-typed Recipe struct (no manual JSON parsing).</li><li>Be served as an HTTP endpoint on :3400.</li><li>Be testable visually in the <strong>Genkit Developer UI</strong>.</li></ul><p>All in <strong>a single </strong><strong>main.go file</strong>. No web framework. No code generation. Just Go.</p><h3>Prerequisites</h3><ul><li><strong>Go 1.24+</strong> (<a href="https://go.dev/doc/install">install</a>)</li><li><strong>Node.js 18+</strong> (only required for the Genkit CLI / Developer UI)</li><li>A <strong>Google GenAI API key</strong> (free, no credit card, from <a href="https://aistudio.google.com/apikey">Google AI Studio</a>)</li></ul><h3>Install the Genkit CLI</h3><p>The Genkit CLI is your local companion for running and inspecting flows in the Developer UI:</p><pre>curl -sL cli.genkit.dev | bash</pre><p>Verify it:</p><pre>genkit --version</pre><h3>Set Up the Project</h3><p>Create a fresh module:</p><pre>mkdir genkit-go-recipes &amp;&amp; cd genkit-go-recipes<br>go mod init example/genkit-go-recipes</pre><p>Install the Genkit Go package:</p><pre>go get github.com/firebase/genkit/go</pre><p>Set your API key:</p><pre>export GEMINI_API_KEY=&lt;your API key&gt;</pre><h3>The Code: a Single main.go</h3><p>Create main.go with the following content. This is the entire service.</p><pre>package main</pre><pre>import (<br>    &quot;context&quot;<br>    &quot;encoding/json&quot;<br>    &quot;fmt&quot;<br>    &quot;log&quot;<br>    &quot;net/http&quot;</pre><pre>    &quot;github.com/firebase/genkit/go/ai&quot;<br>    &quot;github.com/firebase/genkit/go/genkit&quot;<br>    &quot;github.com/firebase/genkit/go/plugins/googlegenai&quot;<br>    &quot;github.com/firebase/genkit/go/plugins/server&quot;<br>)</pre><pre>// Input schema, picked up automatically by Genkit and the Dev UI.<br>type RecipeInput struct {<br>    Ingredient          string `json:&quot;ingredient&quot; jsonschema:&quot;description=Main ingredient or cuisine type&quot;`<br>    DietaryRestrictions string `json:&quot;dietaryRestrictions,omitempty&quot; jsonschema:&quot;description=Any dietary restrictions&quot;`<br>}</pre><pre>// Output schema, returned directly by the model as a typed Go struct.<br>type Recipe struct {<br>    Title        string   `json:&quot;title&quot;`<br>    Description  string   `json:&quot;description&quot;`<br>    PrepTime     string   `json:&quot;prepTime&quot;`<br>    CookTime     string   `json:&quot;cookTime&quot;`<br>    Servings     int      `json:&quot;servings&quot;`<br>    Ingredients  []string `json:&quot;ingredients&quot;`<br>    Instructions []string `json:&quot;instructions&quot;`<br>    Tips         []string `json:&quot;tips,omitempty&quot;`<br>}</pre><pre>func main() {<br>    ctx := context.Background()</pre><pre>    // Initialize Genkit with the Google AI plugin and a default model.<br>    g := genkit.Init(ctx,<br>        genkit.WithPlugins(&amp;googlegenai.GoogleAI{}),<br>        genkit.WithDefaultModel(&quot;googleai/gemini-3-pro&quot;),<br>    )</pre><pre>    // Define a typed flow: (RecipeInput) -&gt; (Recipe, error)<br>    recipeGeneratorFlow := genkit.DefineFlow(g, &quot;recipeGeneratorFlow&quot;,<br>        func(ctx context.Context, input *RecipeInput) (*Recipe, error) {<br>            dietary := input.DietaryRestrictions<br>            if dietary == &quot;&quot; {<br>                dietary = &quot;none&quot;<br>            }</pre><pre>            prompt := fmt.Sprintf(`Create a recipe with the following requirements:<br>                Main ingredient: %s<br>                Dietary restrictions: %s`, input.Ingredient, dietary)</pre><pre>            // Structured generation: Gemini returns a Recipe directly.<br>            recipe, _, err := genkit.GenerateData[Recipe](ctx, g,<br>                ai.WithPrompt(prompt),<br>            )<br>            if err != nil {<br>                return nil, fmt.Errorf(&quot;failed to generate recipe: %w&quot;, err)<br>            }<br>            return recipe, nil<br>        },<br>    )</pre><pre>    // Smoke-test the flow once at boot.<br>    recipe, err := recipeGeneratorFlow.Run(ctx, &amp;RecipeInput{<br>        Ingredient:          &quot;avocado&quot;,<br>        DietaryRestrictions: &quot;vegetarian&quot;,<br>    })<br>    if err != nil {<br>        log.Fatalf(&quot;could not generate recipe: %v&quot;, err)<br>    }<br>    out, _ := json.MarshalIndent(recipe, &quot;&quot;, &quot;  &quot;)<br>    fmt.Println(&quot;Sample recipe generated:&quot;)<br>    fmt.Println(string(out))</pre><pre>    // Expose the flow as an HTTP endpoint.<br>    mux := http.NewServeMux()<br>    mux.HandleFunc(&quot;POST /recipeGeneratorFlow&quot;, genkit.Handler(recipeGeneratorFlow))</pre><pre>    log.Println(&quot;Starting server on http://localhost:3400&quot;)<br>    log.Println(&quot;Flow available at: POST http://localhost:3400/recipeGeneratorFlow&quot;)<br>    log.Fatal(server.Start(ctx, &quot;127.0.0.1:3400&quot;, mux))<br>}</pre><p>Take a moment to count what is <strong>not</strong> in this file:</p><ul><li>No web framework.</li><li>No JSON parsing of the model output.</li><li>No manual OpenTelemetry setup.</li><li>No request/response DTO duplication.</li><li>No Dockerfile yet (we will not need much).</li></ul><p>The struct <strong>is</strong> the contract. The flow <strong>is</strong> the endpoint. The compiler enforces both.</p><h3>Run It</h3><pre>go run .</pre><p>You should see a structured recipe printed as JSON, then the server logging that it is listening on :3400.</p><p>In another terminal, hit it with curl:</p><pre>curl -X POST &quot;http://localhost:3400/recipeGeneratorFlow&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;data&quot;: {&quot;ingredient&quot;: &quot;tomato&quot;, &quot;dietaryRestrictions&quot;: &quot;vegan&quot;}}&#39;</pre><p>You will get back a fully structured JSON recipe. That is it, you have a production-shaped Gen AI microservice in one file.</p><h3>Test It Visually with the Developer UI</h3><p>The Genkit Developer UI is one of the strongest reasons to adopt Genkit, regardless of language. It gives you a local web app to run flows, inspect traces, tweak prompts, and debug tool calls.</p><p>From the project root:</p><pre>genkit start -- go run .</pre><p>Open <a href="http://localhost:4000/">http://localhost:4000</a>, pick recipeGeneratorFlow, paste:</p><pre>{<br>  &quot;ingredient&quot;: &quot;avocado&quot;,<br>  &quot;dietaryRestrictions&quot;: &quot;vegetarian&quot;<br>}</pre><p>Click <strong>Run</strong>. You will see the typed output and a full trace of the model call: tokens, latency, prompt, response. This is the kind of inner loop Python frameworks are still catching up on.</p><h3>Deploying It</h3><p>Because it is Go, deployment is almost anticlimactic. A minimal Dockerfile:</p><pre>FROM golang:1.24 AS build<br>WORKDIR /src<br>COPY . .<br>RUN CGO_ENABLED=0 go build -o /out/server .</pre><pre>FROM gcr.io/distroless/static<br>COPY --from=build /out/server /server<br>ENV PORT=3400<br>EXPOSE 3400<br>ENTRYPOINT [&quot;/server&quot;]</pre><p>That is your entire production image. Deploy it to <strong>Cloud Run</strong>, <strong>Cloud Run Jobs</strong>, <strong>Kubernetes</strong>, <strong>AWS Lambda</strong> (via container image), <strong>Azure Container Apps</strong>, or any platform that runs containers. No Python runtime to vendor. No pip install at build time. No virtual environment. Just a binary.</p><p>If you want to see the same pattern applied to other clouds and languages, I have already covered:</p><ul><li><a href="https://xavidop.me/genkit/2026-03-20-genkit-aws-lambda-bedrock/">Genkit + AWS Lambda + Bedrock</a></li><li><a href="https://xavidop.me/genkit/2026-03-20-genkit-azure-function-ai-foundry/">Genkit + Azure Functions + AI Foundry</a></li><li><a href="https://xavidop.me/genkit/gcp/2026-02-10-genkit-java-101/">Genkit Java 101</a></li></ul><p>Genkit Go fits the same mold, with the smallest runtime footprint of all of them.</p><h3>“But What About…”</h3><p>A few honest objections worth addressing.</p><ul><li><strong>“All the cool research libraries are in Python.”</strong> True. Keep them in Python, behind a small Python service that does only the research-y bit. Put your <strong>product surface</strong> (the part your users actually call) in Go. That separation is healthy.</li><li><strong>“My team only knows Python.”</strong> Go is famously the easiest “real” backend language to learn. A Python developer can be productive in Go in days, and Genkit’s API surface is small enough that the learning curve is mostly Go itself, not the framework.</li><li><strong>“What about LangChain / LlamaIndex features?”</strong> Most of what those frameworks give you (flows, tools, RAG, prompts, evaluation, observability) Genkit Go gives you too, with a fraction of the surface area and without the abstraction tax. See my <a href="https://xavidop.me/genkit/2026-04-16-top-jsts-genai-frameworks-2026/">2026 frameworks comparison</a> for the long version.</li><li><strong>“Is Genkit Go production-ready?”</strong> It powers Gen AI features at Google and a growing list of companies. The Go SDK shares the same core philosophy and plugin model as the JS and Java SDKs. It is stable enough to bet on, and the iteration speed is high.</li></ul><h3>Wrapping Up</h3><p>Python earned its place as the language of AI <strong>research</strong>. It did not earn its place as the language of AI <strong>services</strong>. Those are different problems with different constraints, and the constraints of production services, concurrency, footprint, deployment, types, observability, all favor Go.</p><p>Genkit Go is the framework that finally makes that switch painless. You get a typed, observable, multi-provider Gen AI service in one file, one binary, and one deploy. If you are still maintaining a Python microservice whose only job is to call an LLM and return structured JSON, you are paying a tax you do not need to pay.</p><p>Try it on your next flow. Replace one Python service. See how much smaller the resulting system is, in code, in memory, and in operational surface area.</p><h3>References</h3><ul><li><a href="https://genkit.dev/docs/go/get-started/">Genkit Go, Get Started</a></li><li><a href="https://genkit.dev/docs/go/flows/">Genkit Go, Flows</a></li><li><a href="https://genkit.dev/docs/go/tool-calling/">Genkit Go, Tool Calling</a></li><li><a href="https://genkit.dev/docs/go/deployment/cloud-run/">Genkit Go, Deployment on Cloud Run</a></li><li><a href="https://github.com/firebase/genkit">Genkit GitHub</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68cda467be5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top JavaScript/TypeScript Gen AI Frameworks for 2026: A Hands-On Comparison]]></title>
            <link>https://xavidop.medium.com/top-javascript-typescript-gen-ai-frameworks-for-2026-a-hands-on-comparison-80a4ecf75ece?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/80a4ecf75ece</guid>
            <category><![CDATA[genkit]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Tue, 05 May 2026 03:10:44 GMT</pubDate>
            <atom:updated>2026-05-05T03:10:44.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CO1KpkfNLErFFwihNKKFLw.png" /></figure><h3>Introduction</h3><p>The Generative AI tooling ecosystem has exploded over the past two years. What started as a handful of Python libraries has grown into a rich, opinionated landscape of frameworks spanning multiple languages, deployment targets, and philosophy bets. As a developer who has shipped production applications using all five of the frameworks covered in this article, <strong>Genkit</strong>, <strong>Vercel AI SDK</strong>, <strong>Mastra</strong>, <strong>LangChain</strong>, and <strong>Google ADK</strong>, I want to offer a practical, hands-on view of where each one excels, where each one falls short, and what I would reach for depending on the project I’m building.</p><p>This is not a benchmark post. Tokens per second and latency numbers go stale within weeks. Instead, this is a developer experience and architecture comparison, the kind of thing that matters when you’re deciding what framework will carry your product through 2026 and beyond.</p><p>A quick note on scope: all five frameworks are in active development and moving fast. Code samples in this article use the APIs as of <strong>April 2026</strong>.</p><h3>Genkit</h3><h3>History and Direction</h3><p>Genkit was announced by Google at Google I/O 2024 as an open-source framework designed to bring production-ready AI tooling to full-stack developers, regardless of their cloud provider. At the time, the JavaScript/TypeScript ecosystem lacked a coherent story for building AI-powered features with the kind of developer ergonomics you’d expect from, say, a Next.js app. Firebase’s team set out to fix that, building Genkit not as a proprietary Firebase product but as a cloud-agnostic SDK with first-class support for plugins.</p><p>By mid-2024, Genkit had already attracted a community plugin ecosystem covering AWS Bedrock, Azure OpenAI, Ollama, Cohere, and a growing list of vector stores. The framework reached its 1.0 milestone in late 2024 and shipped major expansions in 2025, most notably adding Python (preview), Go, and Dart (preview) SDKs alongside the primary TypeScript runtime. This multi-language vision is central to Genkit’s story: it aspires to be the framework you reach for no matter what stack you’re running. As of 2026, the Dart SDK has matured notably, making Genkit one of the very few AI frameworks with meaningful <strong>Flutter</strong> support, giving mobile developers a first-class path into generative AI that no other framework on this list can match. It is also important to note that Genkit has a unofficial Java SDK, maintained by the community, which has been used in production but is not officially supported by the Genkit team.</p><p>The team’s declared direction is to deepen Genkit’s role as a full-stack AI layer: strong observability primitives baked into the runtime, composable workflow abstractions (flows), and an expanding model plugin ecosystem. The ambition is not just to be a bridge to a single model provider but to be the connective tissue that lets you swap providers, mix modalities, and trace every hop in your pipeline, all from one coherent API. Of course, Adding more campabilities to its DEV UI is also a major focus, with the goal of making it the best local development experience for AI applications, regardless of where they deploy.</p><h3>What Makes Genkit Stand Out</h3><p>Genkit occupies a unique position among the frameworks in this comparison: it is the only one that provides <strong>multiple levels of abstraction</strong> in a single, coherent API. You can call a model directly (vanilla generation), compose steps into a typed flow, or wire up a fully autonomous agent, and you can mix all three in the same application. Most other frameworks force you to choose a lane.</p><p><strong>Supported languages:</strong> TypeScript/JavaScript (primary, stable), Python (preview), Go, Dart/Flutter (preview)</p><pre>import { genkit } from &#39;genkit&#39;;<br>import { googleAI } from &#39;@genkit-ai/google-genai&#39;;</pre><pre>const ai = genkit({ plugins: [googleAI()] });</pre><pre>// Vanilla generation — no abstraction needed<br>const { text } = await ai.generate({<br>  model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>  prompt: &#39;What is the capital of France?&#39;,<br>});<br>console.log(text);</pre><h4>Flows — Composable, Typed Pipelines</h4><p>Flows are Genkit’s first-class pipeline primitive. They are strongly typed, observable end-to-end, and automatically traced in the Dev UI. You define them once and can invoke them from CLI, HTTP, or the Dev UI without any extra scaffolding.</p><pre>import { genkit, z } from &#39;genkit&#39;;<br>import { googleAI } from &#39;@genkit-ai/google-genai&#39;;</pre><pre>const ai = genkit({ plugins: [googleAI()] });</pre><pre>const summarizeFlow = ai.defineFlow(<br>  {<br>    name: &#39;summarizeArticle&#39;,<br>    inputSchema: z.object({ url: z.string().url() }),<br>    outputSchema: z.object({ summary: z.string(), keyPoints: z.array(z.string()) }),<br>  },<br>  async ({ url }) =&gt; {<br>    const { output } = await ai.generate({<br>      model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>      prompt: `Summarize the article at ${url} and list the key points.`,<br>      output: {<br>        schema: z.object({ summary: z.string(), keyPoints: z.array(z.string()) }),<br>      },<br>    });<br>    return output!;<br>  }<br>);</pre><h4>Agent Abstractions</h4><p>For agents, Genkit uses definePrompt with tools and a system prompt to define specialized agents, along with tool calling via defineTool and conversation memory, all integrated with the same tracing and observability infrastructure that flows use. The agent model is deliberate: it gives you control over how much autonomy you hand over to the model.</p><pre>import { genkit, z } from &#39;genkit&#39;;<br>import { googleAI } from &#39;@genkit-ai/google-genai&#39;;</pre><pre>const ai = genkit({ plugins: [googleAI()] });</pre><pre>const weatherTool = ai.defineTool(<br>  {<br>    name: &#39;getWeather&#39;,<br>    description: &#39;Returns current weather conditions for a given city.&#39;,<br>    inputSchema: z.object({ city: z.string() }),<br>    outputSchema: z.object({ temperature: z.number(), condition: z.string() }),<br>  },<br>  async ({ city }) =&gt; {<br>    // Real implementation would call a weather API<br>    return { temperature: 22, condition: &#39;Sunny&#39; };<br>  }<br>);</pre><pre>const travelAgent = ai.definePrompt(<br>  {<br>    name: &#39;travelAdvisor&#39;,<br>    description: &#39;Travel Advisor can help with trip planning and weather-based advice&#39;,<br>    model: googleAI.model(&#39;gemini-flash-latest&#39;),<br>    tools: [weatherTool],<br>    system: &#39;You are a helpful travel advisor. Use available tools to give accurate advice.&#39;,<br>  }<br>);</pre><pre>// Start a chat session with the agent<br>const chat = ai.chat(travelAgent);<br>const response = await chat.send(&#39;Should I pack a jacket for my trip to Lisbon?&#39;);<br>console.log(response.text);</pre><h4>The Dev UI — Where Genkit Truly Shines</h4><p>The <strong>Genkit Developer UI</strong> is, frankly, the killer feature. No other framework in this comparison comes close to what Genkit offers locally. You launch it with a single command:</p><pre>npx genkit start</pre><p>The Dev UI gives you:</p><ul><li><strong>Flow runner</strong> — execute any flow with a custom input, inspect the typed output, and view the full execution trace.</li><li><strong>Model playground</strong> — invoke any registered model directly, tweak prompt templates, compare outputs.</li><li><strong>Tool testing</strong> — stub and test individual tools in isolation before wiring them into an agent.</li><li><strong>Trace explorer</strong> — every generate, flow, and agent call is traced with latency breakdowns, token counts, and the exact prompts and completions sent to the model. This is OpenTelemetry-compatible telemetry, exportable to Cloud Trace, Langfuse, or any OTEL collector.</li><li><strong>Dotprompt editor</strong> — Genkit’s .prompt files (Dotprompt) are editable live in the UI, with real-time preview and variable injection.</li><li><strong>Session replay</strong> — replay any traced session end-to-end to reproduce bugs without re-running the full application.</li></ul><p>This local observability loop collapses what normally requires a deployed tracing backend (LangSmith, Langfuse, Weave) into a zero-config experience that runs entirely offline. For development speed, this is enormous.</p><p>Vercel’s Developer Tool, by comparison, is a lightweight panel primarily for inspecting HTTP streaming responses. It doesn’t offer flow visualization, trace exploration, or tool testing. It’s functional but basic, the kind of thing you’d expect as a starting point, not a full developer experience.</p><h4>Broad Model Support — Provider Neutral by Design</h4><p>Genkit ships official plugins for <strong>Google AI (Gemini)</strong>, <strong>Google Vertex AI</strong>, <strong>OpenAI</strong>, <strong>Anthropic Claude</strong>, <strong>Cohere</strong>, <strong>Mistral</strong>, <strong>Ollama</strong> (local models), <strong>AWS Bedrock</strong>, and more. The community has extended this to xAI, DeepSeek, Perplexity, and Azure OpenAI. Every model, regardless of provider, is accessed through the same ai.generate() interface, and every call is automatically traced.</p><pre>import { genkit } from &#39;genkit&#39;;<br>import { anthropic } from &#39;genkitx-anthropic&#39;;<br>import { openAI } from &#39;genkitx-openai&#39;;</pre><pre>const ai = genkit({ plugins: [anthropic(), openAI()] });</pre><pre>// Switch between providers without changing downstream code<br>const { text: claudeResponse } = await ai.generate({<br>  model: anthropic.model(&#39;claude-sonnet-4-5&#39;),<br>  prompt: &#39;Explain transformer attention in one paragraph.&#39;,<br>});</pre><pre>const { text: gptResponse } = await ai.generate({<br>  model: openAI.model(&#39;gpt-4o&#39;),<br>  prompt: &#39;Explain transformer attention in one paragraph.&#39;,<br>});</pre><h3>Vercel AI SDK</h3><h3>History and Direction</h3><p>The Vercel AI SDK was born out of a practical need: Vercel builds the infrastructure that powers a large portion of the modern web, and as developers started shipping AI features inside Next.js apps in 2023, the friction of integrating streaming LLM responses into React was painfully apparent. Vercel released the initial AI SDK as an open-source library to standardize streaming, provider integration, and UI hooks across their ecosystem.</p><p>The SDK grew quickly, adding support for Vue, Svelte, SolidJS, and plain Node.js, but its DNA remains deeply tied to the Vercel and Next.js stack. Version 3 in 2024 introduced streamUI, which lets you stream React components as model output, a paradigm-shift for building truly generative user interfaces. Version 4, shipping in late 2024, brought generateObject and streamObject with Zod schemas, structured output across all providers, and an expanded agent API. By 2026, AI SDK v6 has established itself as the go-to choice for teams that live in the Vercel/React ecosystem and want the lowest-friction path from a prompt to a production UI.</p><p>Vercel’s direction is clear: deeper integration between AI, edge compute, and the frontend. The AI Gateway, launched in 2025, acts as a provider proxy with load balancing and fallback, another layer of lock-in dressed as a convenience. The SDK is intentionally lower-level than Genkit or Mastra, favoring simplicity and composability over opinionated abstractions.</p><h3>What Makes the Vercel AI SDK Stand Out</h3><p>The Vercel AI SDK’s greatest strength is its <strong>seamless integration with React and the web UI layer</strong>. useChat, useCompletion, and useObject hooks wire directly into streaming AI responses with built-in state management, loading indicators, and error boundaries. If you’re building a Next.js app and want to add a chat interface or a streaming form, nothing gets you there faster.</p><p><strong>Supported languages:</strong> TypeScript/JavaScript (primary). Node.js, React, Next.js, Nuxt, SvelteKit, SolidStart, Expo (React Native).</p><pre>// app/api/chat/route.ts (Next.js App Router)<br>import { streamText } from &#39;ai&#39;;<br>import { openai } from &#39;@ai-sdk/openai&#39;;</pre><pre>export async function POST(req: Request) {<br>  const { messages } = await req.json();</pre><pre>  const result = await streamText({<br>    model: openai(&#39;gpt-4o&#39;),<br>    messages,<br>  });</pre><pre>  return result.toDataStreamResponse();<br>}</pre><pre>// app/page.tsx — chat UI with one hook<br>&#39;use client&#39;;<br>import { useChat } from &#39;ai/react&#39;;</pre><pre>export default function Chat() {<br>  const { messages, input, handleInputChange, handleSubmit } = useChat();</pre><pre>  return (<br>    &lt;div&gt;<br>      {messages.map(m =&gt; (<br>        &lt;div key={m.id}&gt;&lt;b&gt;{m.role}:&lt;/b&gt; {m.content}&lt;/div&gt;<br>      ))}<br>      &lt;form onSubmit={handleSubmit}&gt;<br>        &lt;input value={input} onChange={handleInputChange} placeholder=&quot;Say something...&quot; /&gt;<br>        &lt;button type=&quot;submit&quot;&gt;Send&lt;/button&gt;<br>      &lt;/form&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>Structured Generation and Agent Patterns</h4><p>The SDK provides clean primitives for structured output and tool use, though the abstractions are deliberately minimal. You get generateText, streamText, generateObject, streamObject, and a simple maxSteps loop for agentic behavior. There is no high-level “flow” abstraction or graph, you compose these primitives yourself.</p><pre>import { generateObject } from &#39;ai&#39;;<br>import { openai } from &#39;@ai-sdk/openai&#39;;<br>import { z } from &#39;zod&#39;;</pre><pre>const { object } = await generateObject({<br>  model: openai(&#39;gpt-4o&#39;),<br>  schema: z.object({<br>    recipe: z.object({<br>      name: z.string(),<br>      ingredients: z.array(z.object({ name: z.string(), amount: z.string() })),<br>      steps: z.array(z.string()),<br>    }),<br>  }),<br>  prompt: &#39;Generate a recipe for a vegan chocolate cake.&#39;,<br>});</pre><h4>Genkit vs. Vercel AI SDK — Abstraction Levels</h4><p>Compared to Genkit, the Vercel AI SDK operates at a <strong>lower level of abstraction</strong>. This is by design, Vercel wants to give you sharp, composable tools, not an opinionated framework. The trade-off is that you assemble more boilerplate yourself. Want to trace a multi-step agent? Wire up OpenTelemetry manually. Want a typed pipeline? Build it yourself. Genkit bakes these in.</p><p>Conversely, Vercel’s <strong>deep UI integration</strong>, streaming RSC, useChat, generative UI patterns, is something Genkit does not attempt to own. For Flutter-based applications, Genkit’s Dart SDK fills this role, but in the web domain, Vercel wins on integration depth.</p><h3>Mastra</h3><h3>History and Direction</h3><p>Mastra is the youngest framework in this comparison, founded in 2024 by the team behind Gatsby (Cade Diehm and Sam Bhagwat). Coming from a background of developer experience tooling and static-site generation, Mastra’s founders approached AI framework design with a strong bias toward <strong>TypeScript ergonomics</strong>, workflow-first thinking, and integrated tooling. The name “Mastra” (Swahili for “master”) reflects the team’s ambition to be the definitive TypeScript-native AI orchestration layer.</p><p>Mastra reached public beta in late 2024 and gained significant traction in early 2025 among TypeScript developers frustrated with LangChain’s Python-ported patterns. The framework’s distinct feature, a built-in <strong>Studio UI</strong>, arrived in early 2025 and quickly became its marquee differentiator. Mastra Studio is a web-based visual interface for defining, testing, and running agents and workflows, accessible locally or in the cloud. By mid-2025, Mastra had secured seed funding and announced hosted cloud infrastructure for deploying Mastra agents directly from the Studio.</p><p>Mastra’s direction is firmly in the TypeScript/JavaScript ecosystem. The team has shown no signs of pursuing multi-language support; instead, they are doubling down on deep integrations with popular TypeScript meta-frameworks like Next.js, Astro, SvelteKit, and Hono. Think of Mastra as the opinionated, batteries-included agent framework for TypeScript developers who want to spin up production agents as fast as possible, without writing any platform glue.</p><h3>What Makes Mastra Stand Out</h3><p>Mastra is purpose-built for one thing: <strong>spinning up agents fast</strong>. It is an agent-only framework, you will not find vanilla model calls or a “flow” primitive. Everything in Mastra is modelled around agents, tools, memory, and workflows. If you know exactly what you need (an agent with memory and tool access), Mastra gets you there in fewer lines of code than any other framework here.</p><p><strong>Supported languages:</strong> TypeScript/JavaScript exclusively. Integrations with Next.js, Astro, SvelteKit, Hono, Express.</p><pre>import { Mastra, Agent } from &#39;@mastra/core&#39;;<br>import { openai } from &#39;@mastra/openai&#39;;</pre><pre>const researchAgent = new Agent({<br>  name: &#39;researcher&#39;,<br>  model: openai(&#39;gpt-4o&#39;),<br>  instructions: `You are a research assistant. <br>    Find relevant information, synthesize key points, <br>    and present clear, well-structured summaries.`,<br>  tools: {<br>    // Tools added here<br>  },<br>});</pre><pre>const mastra = new Mastra({ agents: { researchAgent } });</pre><pre>const response = await mastra.getAgent(&#39;researcher&#39;).generate([<br>  { role: &#39;user&#39;, content: &#39;Summarize the latest developments in quantum computing.&#39; },<br>]);</pre><pre>console.log(response.text);</pre><h4>Workflows</h4><p>Mastra’s workflow primitive lets you chain agent steps into typed, directed graphs, useful when you need a mix of deterministic logic and LLM reasoning.</p><pre>import { Workflow, Step } from &#39;@mastra/core&#39;;<br>import { z } from &#39;zod&#39;;</pre><pre>const contentPipeline = new Workflow({<br>  name: &#39;contentPipeline&#39;,<br>  triggerSchema: z.object({ topic: z.string() }),<br>});</pre><pre>contentPipeline<br>  .step({<br>    id: &#39;research&#39;,<br>    execute: async ({ context }) =&gt; {<br>      const { topic } = context.triggerData;<br>      // Agent call to research the topic<br>      return { research: `Key facts about ${topic}` };<br>    },<br>  })<br>  .then({<br>    id: &#39;draft&#39;,<br>    execute: async ({ context }) =&gt; {<br>      const { research } = context.getStepResult(&#39;research&#39;);<br>      // Agent call to draft the article<br>      return { draft: `Article draft using: ${research}` };<br>    },<br>  })<br>  .commit();</pre><h3>LangChain</h3><h3>History and Direction</h3><p>LangChain is, by a significant margin, the most widely used AI framework in the world, but its story is complicated. Harrison Chase created LangChain in October 2022 as a Python library for chaining LLM calls, and it spread virally through the developer community in early 2023 as everyone scrambled to experiment with GPT-3 and GPT-4. Its key insight, that useful AI applications require structured chains of calls, retrieval augmentation, and tool integration, was correct and arrived at the right moment. GitHub stars and npm downloads shot to the top of every chart.</p><p>The JavaScript port, langchain on npm, arrived shortly after and has tracked the Python library closely in both API design and feature parity. This is the source of one of LangChain’s most persistent criticisms: the JavaScript SDK feels like <strong>Python idioms force-translated into TypeScript</strong>. Patterns like BaseChain, runnable pipelines with .pipe(), and the LCEL (LangChain Expression Language) make perfect sense coming from Python’s compositional patterns but feel unnatural to TypeScript developers accustomed to async/await and module-based composition.</p><p>LangChain the company raised $35M in 2023 and has since built a growing platform around <strong>LangSmith</strong> (observability and evaluation) and <strong>LangGraph</strong> (graph-based orchestration). This is where the tension lies: LangChain’s open-source SDK and LangSmith are designed to complement each other. Getting the best observability experience requires using LangSmith. While you can configure other backends, the seamless experience is on their platform. The framework is excellent and featureful, but its commercial direction is unmistakably pointed toward LangSmith adoption.</p><p>In 2025, LangChain reorganized its JavaScript library around a cleaner agent API (create_agent) and introduced Deep Agents, pre-built agent implementations with built-in context compression and subagent spawning. LangGraph remains the recommended framework for complex multi-step workflows, and LangSmith continues to be the best-in-class platform for production LLM observability.</p><h3>LangChain’s Position: Agent-First, Platform-Tied</h3><p>LangChain is squarely an <strong>agent framework</strong>. Its sweet spot is spinning up capable agents quickly, particularly for teams coming from the Python AI ecosystem who want to move to or stay in JavaScript without losing the LangChain mental model. It is the most feature-complete framework here in terms of raw agent capabilities, RAG patterns, and integrations, but that breadth comes with complexity.</p><p><strong>Supported languages:</strong> Python (primary, feature-complete), JavaScript/TypeScript (JS port, near-parity). Note: the JS SDK carries Python-style patterns.</p><pre>import { createAgent } from &#39;langchain/agents&#39;;<br>import { ChatOpenAI } from &#39;@langchain/openai&#39;;</pre><pre>function getWeather(city: string): string {<br>  // Real implementation would call a weather API<br>  return `It&#39;s always sunny in ${city}!`;<br>}</pre><pre>const model = new ChatOpenAI({ model: &#39;gpt-4o&#39;, temperature: 0 });</pre><pre>const agent = createAgent({<br>  model,<br>  tools: [<br>    {<br>      name: &#39;get_weather&#39;,<br>      description: &#39;Get weather for a given city.&#39;,<br>      func: getWeather,<br>    },<br>  ],<br>  systemPrompt: &#39;You are a helpful assistant.&#39;,<br>});</pre><pre>const result = await agent.invoke({<br>  messages: [{ role: &#39;user&#39;, content: &#39;What is the weather in Madrid?&#39; }],<br>});<br>console.log(result.messages.at(-1)?.content);</pre><h4>LangSmith Observability</h4><p>LangSmith is LangChain’s answer to the observability problem. It provides trace visualization, dataset management, prompt versioning, and LLM evaluation, all polished and production-grade. The integration with LangChain is seamless: set LANGSMITH_TRACING=true and every run is captured automatically.</p><p>The catch is that LangSmith is a SaaS platform. Genkit’s Dev UI provides comparable local observability with zero cloud dependency. If you need hosted, team-scale observability, LangSmith is arguably the best option in the market. If you need local, zero-config development tracing, Genkit wins.</p><h3>Google ADK (Agent Development Kit)</h3><h3>History and Direction</h3><p>Google ADK was announced at Google Cloud Next 2024 as Google’s opinionated take on a production-grade agent framework, specifically targeting enterprise deployments on Google Cloud. Unlike Genkit, which is cloud-agnostic and full-stack, ADK was designed from day one around <strong>Vertex AI</strong> and Google Cloud’s agent infrastructure, including Agent Engine, Cloud Run, and GKE. It is the framework Google recommends when you’re building agents that will live in a Google Cloud environment at scale.</p><p>ADK’s initial release was Python-only, which told the story clearly: this was a framework for the enterprise Python AI developer, data scientists, ML engineers, and cloud architects who think in agents and workflows and are already committed to Google Cloud. The TypeScript, Go, and Java SDKs followed in 2025, with ADK Go 1.0 and ADK Java 1.0 shipping in early 2026. This multi-language expansion signals that Google is positioning ADK as more than a Python script runner, it wants to be the enterprise agent runtime for any Google Cloud workload.</p><p>ADK 2.0, released in 2026, brought significant refinements: graph-based workflow APIs, a visual Web UI builder, enhanced evaluation tooling (including user simulation and environment simulation for testing agents end-to-end), and deeper A2A (Agent-to-Agent) protocol support. The A2A protocol is an open standard that allows ADK agents to communicate with agents built on other frameworks, a meaningful interoperability effort in a fragmented ecosystem.</p><p>Google’s direction with ADK is unmistakable: this is enterprise AI infrastructure for Google Cloud customers. If your organization runs on GCP and needs reliable, scalable, observable agent deployments with enterprise support, ADK is Google’s answer. If you need to be cloud-agnostic, look elsewhere.</p><h3>ADK’s Position: Agent-First, Enterprise-Grade</h3><p>Like LangChain and Mastra, ADK is an <strong>agent-only framework</strong>, its reason for existing is to make building, evaluating, and deploying agents fast and reliable. Unlike Mastra (which targets indie developers and startups), ADK is purpose-built for enterprise scenarios: multi-agent systems, graph-based orchestration, agent evaluation at scale, and deployment to Google’s managed infrastructure.</p><p><strong>Supported languages:</strong> Python (primary, feature-complete), TypeScript/JavaScript, Go, Java. Note: the API design and documentation are heavily Python-first; TypeScript and other SDKs track but sometimes lag the Python feature set.</p><pre># Python — ADK&#39;s primary language<br>from google.adk import Agent<br>from google.adk.tools import google_search</pre><pre>research_agent = Agent(<br>    name=&quot;researcher&quot;,<br>    model=&quot;gemini-flash-latest&quot;,<br>    instruction=&quot;You help users research topics thoroughly and accurately.&quot;,<br>    tools=[google_search],<br>)</pre><pre># Run locally<br>result = research_agent.run(&quot;What are the latest developments in fusion energy?&quot;)<br>print(result.text)</pre><pre>// TypeScript ADK<br>import { Agent } from &#39;@google/adk&#39;;<br>import { googleSearch } from &#39;@google/adk/tools&#39;;</pre><pre>const researchAgent = new Agent({<br>  name: &#39;researcher&#39;,<br>  model: &#39;gemini-flash-latest&#39;,<br>  instruction: &#39;You help users research topics thoroughly and accurately.&#39;,<br>  tools: [googleSearch],<br>});</pre><pre>const result = await researchAgent.run(<br>  &#39;What are the latest developments in fusion energy?&#39;<br>);<br>console.log(result.text);</pre><h4>Multi-Agent Systems</h4><p>ADK’s multi-agent support is one of its strongest features. You can compose agents hierarchically, assign them different models, and let them collaborate via the A2A protocol.</p><pre>from google.adk import Agent<br>from google.adk.agents import SequentialAgent, ParallelAgent</pre><pre>researcher = Agent(name=&quot;researcher&quot;, model=&quot;gemini-flash-latest&quot;, instruction=&quot;Research the topic.&quot;)<br>writer = Agent(name=&quot;writer&quot;, model=&quot;gemini-pro-latest&quot;, instruction=&quot;Write a clear article from the research.&quot;)<br>editor = Agent(name=&quot;editor&quot;, model=&quot;gemini-flash-latest&quot;, instruction=&quot;Polish and format the article.&quot;)</pre><pre>content_pipeline = SequentialAgent(<br>    name=&quot;contentPipeline&quot;,<br>    agents=[researcher, writer, editor],<br>)</pre><pre>result = content_pipeline.run(&quot;Write an article about the impact of quantum computing on cryptography.&quot;)</pre><h4>Vertex AI Lock-In</h4><p>ADK’s evaluation, deployment, and production observability features lean heavily on <strong>Vertex AI Agent Engine</strong>, <strong>Cloud Trace</strong>, and Google’s managed infrastructure. You can run ADK locally and even deploy to Cloud Run or GKE independently, but to get the full ADK experience, including agent evaluation, performance dashboards, and managed scaling, you’re on Google Cloud. This is similar to how LangSmith is the intended observability backend for LangChain: technically optional, practically expected.</p><p>Frameworks like Genkit, Vercel AI SDK, and Mastra were designed from the ground up to be cloud-neutral. ADK and LangChain, by contrast, have strong ecosystem gravity toward their respective platforms.</p><h3>Head-to-Head Comparison</h3><h3>Developer Experience</h3><p>FrameworkDX HighlightsShortcomings<strong>Genkit</strong>Dev UI is unparalleled for local debugging. Idiomatic TypeScript. Multi-level abstractions.Less prescriptive, more choices to make upfront<strong>Vercel AI SDK</strong>Frictionless React/Next.js integration. Minimal API.Assembles boilerplate for complex scenarios<strong>Mastra</strong>Fastest path to a working agent. Great Studio UI.Agent-only, JS-only<strong>LangChain</strong>Vast documentation and community. Battle-tested patterns.Python idioms in TypeScript, complex API<strong>ADK</strong>Powerful multi-agent tooling. Strong eval story.GCP-centric, Python-first</p><h3>Abstraction Levels</h3><p>Genkit is the only framework that gives you all three levels in one SDK: <strong>vanilla generation</strong>, <strong>typed flows (pipelines)</strong>, and <strong>agents</strong>. Vercel AI SDK lives at the lower end, it gives you clean generation and tool-calling primitives but no flow abstraction. Mastra, LangChain, and ADK are agent frameworks: they optimize for spinning up agents quickly but don’t offer a coherent story for when you just want to generate text or structure a pipeline without agent autonomy.</p><h3>Observability</h3><p>FrameworkLocal Dev ObservabilityProduction Observability<strong>Genkit</strong>Built-in Dev UI, trace explorer, Dotprompt editorOTEL-compatible, Cloud Trace, Langfuse<strong>Vercel AI SDK</strong>Basic Developer PanelOTEL, Vercel Observability (platform-tied)<strong>Mastra</strong>Studio UI for workflowsStill maturing<strong>LangChain</strong>Minimal without LangSmithLangSmith (best-in-class, SaaS)<strong>ADK</strong>ADK Web UICloud Trace + Vertex (GCP-tied)</p><h3>Language Support</h3><p>FrameworkPrimaryAdditional<strong>Genkit</strong>TypeScriptPython (preview), Go, Dart/Flutter (preview), Java (Unofficial)<strong>Vercel AI SDK</strong>TypeScriptNode.js runtimes, Edge<strong>Mastra</strong>TypeScriptJS runtimes only<strong>LangChain</strong>PythonTypeScript (near-parity, Python idioms)<strong>ADK</strong>PythonTypeScript, Go, Java</p><h3>Framework Neutrality</h3><p><strong>Genkit</strong>, <strong>Vercel AI SDK</strong>, and <strong>Mastra</strong> were built from the ground up to be provider-neutral. They support OpenAI, Anthropic, Google, and others through a unified API, and they deploy to any infrastructure.</p><p><strong>LangChain</strong> and <strong>ADK</strong> are platform-influenced. LangChain’s full power unlocks with LangSmith; ADK’s full power unlocks on Google Cloud. This is not a dealbreaker, both platforms are excellent, but it is an architectural commitment you should make consciously.</p><h3>Idiom and Code Style</h3><p>Genkit, Mastra, and Vercel AI SDK feel <strong>natively TypeScript</strong>: async/await everywhere, Zod schemas for validation, module-based composition, and no runtime class inheritance chains to navigate.</p><p>LangChain and ADK’s TypeScript SDKs carry the weight of their Python origins. You’ll find class-heavy APIs, .pipe() chains, and patterns that feel natural if you’ve written LangChain Python but unfamiliar if you’re coming from the TypeScript world. This is not a quality judgment, it’s a cultural fit question.</p><h3>Which Framework Should You Choose?</h3><p>After building with all five, here’s my honest take:</p><p><strong>Choose Genkit if:</strong></p><ul><li>You want to iterate on your AI fast and get feedback with less back and forth — Genkit was built from the ground up for powerful local tooling and observability.</li><li>You need to mix vanilla generation, typed pipelines (flows), and agents in the same app.</li><li>Provider neutrality is important now or likely to be important later.</li><li>You’re building a Flutter/Dart mobile app and need AI capabilities.</li><li>You want OpenTelemetry-compatible tracing without configuring a separate backend.</li></ul><p><strong>Choose Vercel AI SDK if:</strong></p><ul><li>You’re building a React/Next.js app and want the lowest-friction path to streaming AI UI.</li><li>Simplicity and minimal API surface matter more than built-in abstractions.</li><li>You’re already on the Vercel platform and want native integration.</li><li>Your use case maps well to the UI hooks (useChat, useCompletion, generative UI).</li></ul><p><strong>Choose Mastra if:</strong></p><ul><li>You’re a TypeScript developer who wants to spin up a production agent as fast as possible.</li><li>You want a clean, idiomatic TypeScript agent API without Python-ported patterns.</li><li>The visual Studio UI for workflow design appeals to your team.</li><li>You’re building in the Next.js/SvelteKit/Hono ecosystem.</li></ul><p><strong>Choose LangChain if:</strong></p><ul><li>Your team is coming from the Python AI ecosystem and wants cross-language continuity.</li><li>You need the broadest possible integration ecosystem (the most integrations of any framework).</li><li>You’re investing in LangSmith for production observability and want a cohesive platform.</li><li>LangGraph’s graph-based orchestration matches your workflow complexity.</li></ul><p><strong>Choose ADK if:</strong></p><ul><li>You’re building enterprise-grade multi-agent systems on Google Cloud.</li><li>Vertex AI’s infrastructure (Agent Engine, Cloud Trace, Vertex Search) is already in your stack.</li><li>You need battle-tested multi-language support including Go and Java.</li><li>Agent evaluation at scale (user simulation, custom metrics) is a core requirement.</li></ul><h3>Conclusion</h3><p>The Generative AI framework landscape in 2026 is not a winner-take-all market. Each of the five frameworks covered here has a legitimate use case, a growing community, and an active development team.</p><p>If I had to crown one framework as the most versatile choice for teams that haven’t already committed to a cloud platform, it would be <strong>Genkit</strong>. Its combination of multi-level abstractions, provider neutrality, and, above all, the Developer UI creates a development experience that genuinely accelerates iteration. The fact that it is expanding to Dart/Flutter, Python, and Go while keeping its TypeScript SDK as the best-in-class experience is a sign of a team thinking about the long game.</p><p>That said, none of these frameworks is going away. LangChain’s ecosystem depth, ADK’s enterprise footprint, Vercel’s UI ergonomics, and Mastra’s TypeScript-native speed all serve real needs. The most important thing is to make the choice deliberately, understanding what you’re trading when you pick a platform-tied framework, and what you’re gaining when you pick a more opinionated one.</p><p>Happy building.</p><p><em>Last updated: April 2026. Framework versions referenced: Genkit 1.x, Vercel AI SDK 6.x, Mastra 0.x (latest), LangChain JS 0.3.x, Google ADK 2.0.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80a4ecf75ece" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top Gen AI Frameworks for Java in 2026: A Hands-On Comparison]]></title>
            <link>https://xavidop.medium.com/top-gen-ai-frameworks-for-java-in-2026-a-hands-on-comparison-22baa8c13141?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/22baa8c13141</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Tue, 05 May 2026 03:08:43 GMT</pubDate>
            <atom:updated>2026-05-05T03:08:43.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72XQpH71JiSy3yUlRywu1g.png" /></figure><h3>Introduction</h3><p>Java has always been a serious language for production systems, and in 2026, the Generative AI ecosystem has finally caught up. For years, Java developers watched from the sidelines as Python and TypeScript accumulated framework after framework for building LLM-powered applications. Today, the picture is very different. Java has multiple mature, actively maintained AI frameworks, each with its own philosophy and trade-offs.</p><p>This article covers the four frameworks I have personally used to ship Java AI applications: <strong>Genkit Java</strong>, <strong>Spring AI</strong>, <strong>LangChain4j</strong>, and <strong>Google ADK Java</strong>. Each one represents a meaningfully different bet on what a Java AI framework should be, and understanding those differences will save you from picking the wrong tool.</p><h3>Genkit Java</h3><h3>History and Direction</h3><p>Genkit started life as a TypeScript-first framework launched by Google at I/O 2024. The Java SDK arrived as a community-maintained effort, built and maintained by developers within the Google ecosystem who wanted to bring the same developer experience to Java that Genkit had established in TypeScript. As of 2026, <strong>Genkit Java is unofficial</strong>, it is not an official Google product, but it is actively maintained, follows the core Genkit design closely, and ships its own plugin ecosystem.</p><p>The framework’s first stable release landed in early 2026 after months of preview use. Its ambition mirrors the TypeScript SDK’s: bring Genkit’s multi-level abstractions (vanilla generation, typed flows, agents), its broad provider-neutral plugin model, and, crucially, the <strong>Genkit Developer UI</strong> to Java developers. The Java SDK ships with Spring Boot and Jetty server plugins, making it a natural fit for teams that already run Java services in production. The Javadoc and architecture are clean and idiomatic Java, this does not feel like a port; it feels designed for the language.</p><p>The direction is clear: maintain parity with the TypeScript Genkit SDK’s abstractions while embracing Java idioms (builder patterns, typed schemas via Java classes, annotation-free configuration). Support for evaluation, MCP (Model Context Protocol), RAG with pgvector and Pinecone, and multi-agent patterns is already in place.</p><h3>What Makes Genkit Java Stand Out</h3><p>Like its TypeScript counterpart, Genkit Java provides <strong>three levels of abstraction in a single SDK</strong>: direct model calls, typed flows (observable pipelines), and agents. This is unique in the Java AI space, no other Java framework gives you all three in one coherent API.</p><p><strong>Supported languages:</strong> Java 21+ (primary). Deploys to Spring Boot, Jetty, or Firebase Cloud Functions.</p><h4>Vanilla Generation</h4><pre>import com.google.genkit.Genkit;<br>import com.google.genkit.ai.GenerateOptions;<br>import com.google.genkit.plugins.googlegenai.GoogleGenAIPlugin;</pre><pre>Genkit genkit = Genkit.builder()<br>    .plugin(GoogleGenAIPlugin.create())<br>    .build();</pre><pre>String text = genkit.generate(GenerateOptions.builder()<br>    .model(&quot;googleai/gemini-flash-latest&quot;)<br>    .prompt(&quot;Explain the CAP theorem in two sentences.&quot;)<br>    .build()).getText();</pre><pre>System.out.println(text);</pre><h4>Typed Flows — Observable Pipelines</h4><p>Flows are the heart of Genkit Java. They wrap your AI logic in a named, typed, traceable unit that is automatically exposed as an HTTP endpoint and visible in the Dev UI.</p><pre>import com.google.genkit.Genkit;<br>import com.google.genkit.flow.FlowOptions;<br>import com.google.genkit.plugins.googlegenai.GoogleGenAIPlugin;<br>import com.google.genkit.plugins.jetty.JettyPlugin;<br>import com.google.genkit.plugins.jetty.JettyPluginOptions;</pre><pre>record TranslateRequest(String text, String targetLanguage) {}<br>record TranslateResponse(String translation, String detectedLanguage) {}</pre><pre>JettyPlugin jetty = new JettyPlugin(JettyPluginOptions.builder().port(8080).build());</pre><pre>Genkit genkit = Genkit.builder()<br>    .plugin(GoogleGenAIPlugin.create())<br>    .plugin(jetty)<br>    .build();</pre><pre>genkit.defineFlow(<br>    FlowOptions.&lt;TranslateRequest, TranslateResponse&gt;builder()<br>        .name(&quot;translateText&quot;)<br>        .inputClass(TranslateRequest.class)<br>        .outputClass(TranslateResponse.class)<br>        .build(),<br>    (ctx, request) -&gt; {<br>        var response = genkit.generate(GenerateOptions.builder()<br>            .model(&quot;googleai/gemini-flash-latest&quot;)<br>            .prompt(&quot;Translate &#39;%s&#39; to %s. Return JSON with &#39;translation&#39; and &#39;detectedLanguage&#39;.&quot;<br>                .formatted(request.text(), request.targetLanguage()))<br>            .outputClass(TranslateResponse.class)<br>            .build());<br>        return response.getOutput(TranslateResponse.class);<br>    }<br>);</pre><pre>jetty.start();</pre><h4>Tools and Agents</h4><pre>import com.google.genkit.ai.tool.ToolDefinition;</pre><pre>var weatherTool = genkit.defineTool(<br>    ToolDefinition.&lt;String, String&gt;builder()<br>        .name(&quot;getWeather&quot;)<br>        .description(&quot;Returns current weather for a city.&quot;)<br>        .inputClass(String.class)<br>        .outputClass(String.class)<br>        .build(),<br>    (ctx, city) -&gt; &quot;Sunny, 24°C in &quot; + city<br>);</pre><pre>// Use the tool inside a flow or agent<br>var result = genkit.generate(GenerateOptions.builder()<br>    .model(&quot;googleai/gemini-flash-latest&quot;)<br>    .prompt(&quot;What&#39;s the weather like in Tokyo?&quot;)<br>    .tools(List.of(weatherTool))<br>    .build());</pre><h4>The Dev UI — Same Power as TypeScript</h4><p>One of Genkit Java’s most compelling features is that the <strong>same Genkit Developer UI</strong> used by the TypeScript SDK works directly with Java applications. You install the Genkit CLI (Node.js-based) and start your Java app through it:</p><pre>npm install -g genkit<br>genkit start -- mvn exec:java</pre><p>The Dev UI opens at http://localhost:4000 and gives you:</p><ul><li><strong>Flow runner</strong> — execute any flow interactively with custom inputs and inspect typed outputs.</li><li><strong>Trace explorer</strong> — full OpenTelemetry traces for every generate and flow call, showing latency, token counts, and exact prompts.</li><li><strong>Model playground</strong> — test any registered model directly.</li><li><strong>Tool testing</strong> — stub and test tools in isolation.</li><li><strong>Dotprompt editor</strong> — edit .prompt files live with variable injection.</li></ul><p>This is the single biggest advantage Genkit Java has over every other Java AI framework: a zero-config, local developer UI that replaces the need for LangSmith or Grafana during development.</p><h4>Provider Support</h4><p>Genkit Java ships plugins for: <strong>Google GenAI (Gemini)</strong>, <strong>OpenAI</strong>, <strong>Anthropic (Claude)</strong>, <strong>AWS Bedrock</strong>, <strong>Azure AI Foundry</strong>, <strong>Ollama</strong>, <strong>xAI (Grok)</strong>, <strong>DeepSeek</strong>, <strong>Cohere</strong>, <strong>Mistral</strong>, and <strong>Groq</strong>. All accessed through the same genkit.generate() interface.</p><p>Vector store plugins cover: Firebase Firestore, Weaviate, PostgreSQL (pgvector), Pinecone, and a local in-memory store.</p><h3>Spring AI</h3><h3>History and Direction</h3><p>Spring AI was announced by the Spring team (Broadcom) in mid-2023 and reached its 1.0 GA release in mid-2024. It is the most enterprise-grade option in this comparison, built by the same team that maintains Spring Framework, Spring Boot, and Spring Data, which together underpin a vast proportion of the world’s Java server-side applications.</p><p>The founding premise of Spring AI is that AI integration in Java applications should feel like every other Spring integration: auto-configured, testable, portable, and production-ready out of the box. The project draws inspiration from LangChain and LlamaIndex but explicitly avoids being a port, it is designed from the ground up to be idiomatic Spring. If you have written Spring applications, Spring AI will feel immediately familiar: @Autowired AI clients, Spring Boot starters, application.properties configuration, and Advisor patterns that mirror Spring’s existing interception model.</p><p>Spring AI’s direction through 2025 and into 2026 has been to deepen its observability story (Micrometer-native metrics and traces), expand its ChatClient fluent API, and ship more vector store integrations. The framework is now the de facto standard for teams that are already invested in the Spring ecosystem and want to add AI capabilities without introducing a foreign dependency philosophy.</p><h3>What Makes Spring AI Stand Out</h3><p>Spring AI’s killer feature is <strong>Spring Boot integration depth</strong>. There is no framework on this list, in any language, that integrates AI capabilities as seamlessly into an existing application framework as Spring AI does with Spring Boot. Auto-configuration, conditional beans, health indicators, Actuator endpoints for AI metrics, everything a Spring developer expects, applied to AI.</p><p><strong>Supported languages:</strong> Java (primary). Also supports Kotlin (via Spring’s Kotlin DSL). Runs anywhere Spring Boot runs: embedded Tomcat, Jetty, Undertow, GraalVM native images.</p><pre>// application.properties<br>// spring.ai.openai.api-key=${OPENAI_API_KEY}<br>// spring.ai.openai.chat.options.model=gpt-4o</pre><pre>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.web.bind.annotation.*;</pre><pre>@RestController<br>public class ChatController {</pre><pre>    private final ChatClient chatClient;</pre><pre>    public ChatController(ChatClient.Builder builder) {<br>        this.chatClient = builder.build();<br>    }</pre><pre>    @GetMapping(&quot;/chat&quot;)<br>    public String chat(@RequestParam String message) {<br>        return chatClient.prompt()<br>            .user(message)<br>            .call()<br>            .content();<br>    }<br>}</pre><h4>Structured Output <a href="https://xavidop.me/genkit/2026-04-16-top-java-genai-frameworks-2026/#structured-output">Permalink</a></h4><p>Spring AI’s BeanOutputConverter maps model responses directly to Java POJOs, using the class schema to generate format instructions automatically.</p><pre>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.ai.converter.BeanOutputConverter;</pre><pre>record MovieReview(String title, int rating, String summary, List&lt;String&gt; pros) {}</pre><pre>BeanOutputConverter&lt;MovieReview&gt; converter = new BeanOutputConverter&lt;&gt;(MovieReview.class);</pre><pre>MovieReview review = chatClient.prompt()<br>    .user(u -&gt; u.text(&quot;Review the movie Inception. {format}&quot;)<br>        .param(&quot;format&quot;, converter.getFormat()))<br>    .call()<br>    .entity(MovieReview.class);</pre><pre>System.out.println(review.title() + &quot; — &quot; + review.rating() + &quot;/10&quot;);</pre><h4>RAG with Advisors</h4><p>Spring AI’s Advisors API is one of its most elegant features. Advisors wrap ChatClient calls with cross-cutting concerns, RAG retrieval, chat memory, logging, guardrails, in a declarative, composable way.</p><pre>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;<br>import org.springframework.ai.vectorstore.VectorStore;</pre><pre>@Service<br>public class DocumentQAService {</pre><pre>    private final ChatClient chatClient;</pre><pre>    public DocumentQAService(ChatClient.Builder builder, VectorStore vectorStore) {<br>        this.chatClient = builder<br>            .defaultAdvisors(new QuestionAnswerAdvisor(vectorStore))<br>            .build();<br>    }</pre><pre>    public String answerQuestion(String question) {<br>        return chatClient.prompt()<br>            .user(question)<br>            .call()<br>            .content();<br>    }<br>}</pre><h4>Observability</h4><p>Spring AI ships with <strong>Micrometer</strong> integration out of the box. Every chat call generates spans (Spring Boot tracing) and metrics (prompt token count, completion token count, model latency) visible in any Micrometer-compatible backend: Prometheus, Grafana, Zipkin, or Datadog. There is no separate Dev UI, observability is handled by your existing Spring Boot infrastructure.</p><h4>Broad Vector Store and Model Support</h4><p>Spring AI supports 10+ model providers (OpenAI, Anthropic, Google Vertex AI, Amazon Bedrock, Azure OpenAI, Mistral, Ollama, Groq, and more) and 20+ vector stores (PGVector, Pinecone, Weaviate, Redis, Elasticsearch, MongoDB Atlas, Chroma, and more), the broadest integration coverage of any Java AI framework.</p><h3>LangChain4j</h3><h3>History and Direction</h3><p>LangChain4j was started in early 2023 by a small community of Java developers who noticed that the LLM framework explosion happening in Python had no Java equivalent. Despite the name, the project is not a mechanical port of LangChain Python, it is a fusion of ideas from LangChain, Haystack, LlamaIndex, and original innovation, packaged in a way that makes sense for Java.</p><p>It grew quickly through 2023 and 2024, driven by its comprehensive integration list (20+ LLM providers, 30+ vector stores) and its clean two-level abstraction model: low-level primitives for maximum control and high-level <strong>AI Services</strong> for rapid development. The AI Services pattern, where you define an interface with annotations and LangChain4j implements it for you at runtime, became the framework’s signature feature and arguably the most Java-idiomatic approach to LLM integration in the ecosystem.</p><p>By 2025, LangChain4j had formal integrations with <strong>Quarkus</strong>, <strong>Spring Boot</strong>, <strong>Micronaut</strong>, and <strong>Helidon</strong>, covering every major Java application framework. The team’s direction in 2026 is focused on deepening agentic capabilities (multi-step tools, planning loops, MCP support) and improving the observability story, which has historically been a weaker point compared to Spring AI’s Micrometer integration or Genkit’s Dev UI.</p><h3>What Makes LangChain4j Stand Out</h3><p>LangChain4j’s <strong>AI Services</strong> pattern is its defining feature. Instead of writing imperative LLM call code, you declare an interface, annotate it with @SystemMessage, @UserMessage, and memory annotations, and LangChain4j generates the implementation. The result is AI code that reads like a Java service contract, clean, testable, and completely familiar to Java developers.</p><p><strong>Supported languages:</strong> Java (primary). Kotlin extensions available (coroutine-based async support). Integrates with Spring Boot, Quarkus, Micronaut, Helidon.</p><pre>import dev.langchain4j.service.AiServices;<br>import dev.langchain4j.service.SystemMessage;<br>import dev.langchain4j.model.openai.OpenAiChatModel;</pre><pre>interface TranslationAssistant {<br>    @SystemMessage(&quot;You are a professional translator. Translate text accurately and naturally.&quot;)<br>    String translate(@UserMessage String text, @V(&quot;language&quot;) String targetLanguage);<br>}</pre><pre>var model = OpenAiChatModel.withApiKey(System.getenv(&quot;OPENAI_API_KEY&quot;));</pre><pre>TranslationAssistant assistant = AiServices.builder(TranslationAssistant.class)<br>    .chatLanguageModel(model)<br>    .build();</pre><pre>String result = assistant.translate(&quot;The quick brown fox jumps over the lazy dog&quot;, &quot;Spanish&quot;);<br>System.out.println(result);</pre><h4>Memory and Streaming</h4><pre>import dev.langchain4j.memory.chat.MessageWindowChatMemory;<br>import dev.langchain4j.service.MemoryId;</pre><pre>interface ConversationalAssistant {<br>    @SystemMessage(&quot;You are a helpful assistant.&quot;)<br>    String chat(@MemoryId String userId, @UserMessage String message);<br>}</pre><pre>ConversationalAssistant assistant = AiServices.builder(ConversationalAssistant.class)<br>    .chatLanguageModel(model)<br>    .chatMemoryProvider(memoryId -&gt; MessageWindowChatMemory.withMaxMessages(20))<br>    .build();</pre><pre>// Each userId gets its own isolated memory<br>assistant.chat(&quot;user-42&quot;, &quot;My name is Alice.&quot;);<br>String response = assistant.chat(&quot;user-42&quot;, &quot;What&#39;s my name?&quot;);<br>// Returns: &quot;Your name is Alice.&quot;</pre><h4>RAG Pipeline</h4><pre>import dev.langchain4j.data.document.loader.UrlDocumentLoader;<br>import dev.langchain4j.data.document.splitter.DocumentSplitters;<br>import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;<br>import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;</pre><pre>// Ingest documents<br>var documents = UrlDocumentLoader.load(&quot;https://example.com/docs&quot;);<br>var splitter = DocumentSplitters.recursive(500, 50);<br>var segments = splitter.splitAll(documents);</pre><pre>var embeddingModel = OpenAiEmbeddingModel.withApiKey(apiKey);<br>var embeddingStore = new InMemoryEmbeddingStore&lt;TextSegment&gt;();<br>EmbeddingStoreIngestor.ingest(segments, embeddingStore, embeddingModel);</pre><pre>// Build RAG-enabled assistant<br>interface DocsAssistant {<br>    String answer(@UserMessage String question);<br>}</pre><pre>var retriever = EmbeddingStoreContentRetriever.builder()<br>    .embeddingStore(embeddingStore)<br>    .embeddingModel(embeddingModel)<br>    .maxResults(3)<br>    .build();</pre><pre>DocsAssistant assistant = AiServices.builder(DocsAssistant.class)<br>    .chatLanguageModel(model)<br>    .contentRetriever(retriever)<br>    .build();</pre><h4>Two Abstraction Levels</h4><p>LangChain4j explicitly offers two levels:</p><ul><li><strong>Low level</strong> — ChatModel, UserMessage, AiMessage, EmbeddingStore: full control, more code.</li><li><strong>High level</strong> — AiServices: declarative interfaces, minimal boilerplate.</li></ul><p>This mirrors what Genkit Java achieves differently. Where Genkit gives you flows and agents as pipeline concepts, LangChain4j uses interface-based AI Services as its high-level abstraction, very idiomatic in Java terms.</p><h3>Google ADK Java</h3><h3>History and Direction</h3><p>Google ADK (Agent Development Kit) launched in 2024 as a Python-first agent framework targeting enterprise deployments on Google Cloud. Java was a late addition to the multi-language roadmap, with <strong>ADK Java 1.0</strong> shipping in early 2026 alongside ADK Go 1.0. The Java SDK arrival was significant: it signaled that Google views ADK as a serious enterprise runtime, not just a Python scripting tool.</p><p>ADK Java follows the same design philosophy as the Python SDK: everything is an agent, workflow, or tool. The framework is optimized for building reliable, evaluatable, production-grade multi-agent systems and deploying them to Google Cloud infrastructure, primarily <strong>Vertex AI Agent Engine</strong>, Cloud Run, and GKE. Like its Python counterpart, ADK Java carries the weight of Google Cloud gravity. The best developer experience, the smoothest deployment path, and the most mature observability story all assume you are running on GCP.</p><p>ADK Java 1.0 includes the full agent runtime (LLM agents, sequential/loop/parallel workflow agents), tool calling, MCP support, A2A (Agent-to-Agent) protocol, session/memory management, and streaming. The Java API closely mirrors the Python API in structure, which means the mental model transfers well, but also means the Java SDK carries a style that reflects Python-first design decisions.</p><h3>ADK Java’s Position: Agent-Only, Enterprise-Grade</h3><p>Like its Python counterpart, ADK Java is an <strong>agent framework</strong>, it has no vanilla generation primitive or flow abstraction outside the agent model. Its raison d’être is spinning up reliable, evaluatable agents and deploying them at enterprise scale. If you are building a multi-agent system on Google Cloud and Java is your language of choice, ADK Java 1.0 is Google’s recommended path.</p><p><strong>Supported languages:</strong> Java (with ADK Java 1.0). Also: Python (primary), TypeScript, Go.</p><pre>import com.google.adk.agents.LlmAgent;<br>import com.google.adk.tools.GoogleSearchTool;<br>import com.google.adk.runner.InMemoryRunner;<br>import com.google.genai.types.Content;</pre><pre>var researchAgent = LlmAgent.builder()<br>    .name(&quot;researcher&quot;)<br>    .model(&quot;gemini-flash-latest&quot;)<br>    .instruction(&quot;You help users research topics thoroughly and accurately.&quot;)<br>    .tools(List.of(new GoogleSearchTool()))<br>    .build();</pre><pre>var runner = new InMemoryRunner(researchAgent);</pre><pre>var session = runner.sessionService().createSession(<br>    researchAgent.name(), &quot;user-1&quot;<br>).blockingGet();</pre><pre>var userMessage = Content.fromParts(Part.fromText(<br>    &quot;What are the latest developments in fusion energy?&quot;<br>));</pre><pre>runner.runAsync(researchAgent.name(), session.id(), userMessage)<br>    .blockingForEach(event -&gt; {<br>        if (event.finalResponse()) {<br>            System.out.println(event.stringifyContent());<br>        }<br>    });</pre><h4>Multi-Agent Orchestration</h4><p>ADK Java’s multi-agent capabilities match the Python SDK’s, including sequential, parallel, and loop orchestration.</p><pre>import com.google.adk.agents.SequentialAgent;</pre><pre>var researcher = LlmAgent.builder()<br>    .name(&quot;researcher&quot;)<br>    .model(&quot;gemini-flash-latest&quot;)<br>    .instruction(&quot;Research the given topic and provide key facts.&quot;)<br>    .build();</pre><pre>var writer = LlmAgent.builder()<br>    .name(&quot;writer&quot;)<br>    .model(&quot;gemini-flash-latest&quot;)<br>    .instruction(&quot;Write a clear, well-structured article from the research provided.&quot;)<br>    .build();</pre><pre>var editor = LlmAgent.builder()<br>    .name(&quot;editor&quot;)<br>    .model(&quot;gemini-flash-latest&quot;)<br>    .instruction(&quot;Polish and format the article for publication.&quot;)<br>    .build();</pre><pre>var pipeline = SequentialAgent.builder()<br>    .name(&quot;contentPipeline&quot;)<br>    .subAgents(List.of(researcher, writer, editor))<br>    .build();</pre><h4>Vertex AI Lock-In</h4><p>ADK Java’s production deployment story is built around <strong>Vertex AI Agent Engine</strong> and Google Cloud. While you can run ADK Java locally (via the ADK CLI or directly) and deploy to Cloud Run or GKE independently, the managed evaluation tools, performance dashboards, and enterprise support all assume GCP. This is the clearest example in the Java AI space of a framework built to serve a platform rather than being platform-neutral.</p><h3>Head-to-Head Comparison</h3><h3>Abstraction Levels</h3><p>Genkit Java is the only Java AI framework that provides all three levels: <strong>vanilla generation</strong>, <strong>typed flows (pipelines)</strong>, and <strong>agents</strong>. Spring AI covers generation and a basic agent model via tools, but lacks a flow abstraction. LangChain4j provides two levels (low-level primitives and high-level AI Services) but is agent/service focused. ADK Java is agent-only.</p><h3>Observability</h3><p>FrameworkLocal DevProduction<strong>Genkit Java</strong>Dev UI with trace explorerOTEL-compatible export<strong>Spring AI</strong>Logs and Actuator endpointsMicrometer (Prometheus, Grafana, Datadog)<strong>LangChain4j</strong>Logging onlyManual OTEL setup<strong>ADK Java</strong>ADK Web UICloud Trace + Vertex (GCP)</p><h3>Framework Neutrality</h3><p>Genkit Java and LangChain4j are built to be provider-neutral: they support every major model and deploy to any infrastructure. Spring AI is similarly neutral on model providers, though it carries Spring’s opinionated application framework as a dependency, a worthwhile trade for most Java shops. ADK Java carries the heaviest platform dependency: its full value is unlocked on Google Cloud.</p><h3>Which Framework Should You Choose?</h3><p><strong>Choose Genkit Java if:</strong></p><ul><li>You want to iterate on your AI fast and get feedback with less back and forth — Genkit was built from the ground up for powerful local tooling and observability, and the Dev UI is genuinely transformative.</li><li>You need multiple abstraction levels (vanilla calls, typed flows, and agents) in one SDK.</li><li>Provider neutrality matters: you need to swap or mix Gemini, Claude, OpenAI, and Bedrock.</li><li>Your team also writes TypeScript and wants a consistent framework story across both stacks.</li></ul><p><strong>Choose Spring AI if:</strong></p><ul><li>You are already running Spring Boot and want AI to feel like any other Spring integration.</li><li>Micrometer-native metrics and traces plugging into your existing Prometheus/Grafana stack are a priority.</li><li>You need the broadest model and vector store coverage with production-grade auto-configuration.</li><li>GraalVM native images are a requirement for your deployment targets.</li></ul><p><strong>Choose LangChain4j if:</strong></p><ul><li>You want the most Java-idiomatic high-level AI abstraction: interface-based AI Services with annotations.</li><li>You need the largest integration ecosystem and don’t want to be tied to any application framework.</li><li>Your team works across Spring Boot, Quarkus, Micronaut, and Helidon, LangChain4j is the most framework-agnostic.</li><li>RAG pipelines with rich document ingestion and retrieval are a core use case.</li></ul><p><strong>Choose ADK Java if:</strong></p><ul><li>You are building enterprise-grade multi-agent systems and Google Cloud is your runtime.</li><li>You need official Google support and SLA-backed infrastructure for agent deployment.</li><li>Multi-agent orchestration (sequential, parallel, loop) and the A2A interoperability protocol matter.</li><li>Your team is already using the ADK Python SDK and wants to extend to Java services.</li></ul><h3>Conclusion</h3><p>Java’s AI framework landscape in 2026 is surprisingly rich. The four frameworks covered here serve genuinely different needs, and unlike in the JavaScript world where Genkit, Vercel, Mastra, LangChain, and ADK overlap significantly, the Java options each occupy a clearer niche.</p><p>For <strong>enterprise Spring Boot teams</strong>, Spring AI is the obvious choice, zero friction, production-ready observability via Micrometer, and the broadest integration matrix. For <strong>teams that value developer experience above all</strong>, Genkit Java’s Dev UI is a category apart and worth the unofficial status trade-off. For <strong>framework-agnostic Java developers</strong> who want the most idiomatic Java AI service abstraction, LangChain4j’s AI Services pattern is hard to beat. And for <strong>Google Cloud enterprise workloads</strong> that need reliable multi-agent orchestration at scale, ADK Java 1.0 is where Google is putting its weight.</p><p>The most important thing is that you no longer have an excuse to reach for Python just because it has better AI tooling. Java’s time in generative AI has arrived.</p><p><em>Last updated: April 2026. Framework versions referenced: Genkit Java 1.0.0-SNAPSHOT, Spring AI 1.x, LangChain4j 0.36.x, Google ADK Java 1.0.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22baa8c13141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Can You Link LLM Agent Metrics to Business Success]]></title>
            <link>https://xavidop.medium.com/how-can-you-link-llm-agent-metrics-to-business-success-c1ab2eeea29e?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1ab2eeea29e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gen-ai-for-business]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[llmops]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 16 Jan 2025 19:07:53 GMT</pubDate>
            <atom:updated>2025-01-16T19:28:25.038Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xwvtzXV81xKkh3CxSg7EyA.jpeg" /></figure><p>The rise of AI agents powered by Large Language Models (LLMs) has revolutionized how we interact with technology. However, effectively evaluating these agents requires a multifaceted approach that goes beyond traditional metrics. Here you will understand the key categories and specific metrics that are essential for understanding and improving LLM-driven AI agent performance.</p><p><strong>1. Interaction Metrics</strong></p><ul><li><strong>Number of Interactions:</strong> Tracks usage frequency (e.g., daily interactions, returning users). High numbers indicate user trust and the agent’s value.</li><li><strong>Session Duration:</strong> Measures the average time users spend interacting in a single session. Longer durations suggest deeper engagement, but also potential inefficiencies.</li><li><strong>Conversation Turns:</strong> Counts user-agent exchanges per session. A balance is crucial — too few might indicate limited depth, while too many could suggest inefficiency.</li></ul><p><strong>2. Intent Usage Metrics</strong></p><ul><li><strong>Top Intents Used:</strong> Identifies the most frequent user intents (e.g., FAQs, bookings). This guides resource allocation and prioritization of enhancements.</li><li><strong>Intent Completion Rate:</strong> Measures the percentage of intents successfully handled by the agent without human intervention.</li></ul><p>The metrics above are quite relevant, especially if you are enhancing a classic NLU with LLMs using NLU RAGs techniques where you use the intents + the description of them + user utterances + user conversation history + current context of the conversation.</p><p><strong>3. Goal Achievement Metrics</strong></p><ul><li><strong>Happy Path Achievement:</strong> Tracks how smoothly users reach desired outcomes with minimal friction.</li><li><strong>Task Success Rate (TSR):</strong> Measures the percentage of interactions that successfully achieve user goals without retries or human intervention.</li></ul><p><strong>4. Conversation Flow Metrics</strong></p><ul><li><strong>Funnel Analysis:</strong> Examines user journeys within a conversation, identifying drop-offs and common pathways.</li><li><strong>Turn Efficiency:</strong> Evaluates the number of exchanges required to complete a task. Fewer turns generally indicate higher efficiency.</li></ul><p><strong>5. LLM-Specific Metrics</strong></p><p><strong>LLM Performance:</strong></p><ul><li><strong>Response Accuracy:</strong> Assessed through human evaluation and automated benchmarks using pre-labeled datasets.</li><li><strong>Latency:</strong> Measures the average response time of the LLM. Low latency is crucial for user satisfaction.</li></ul><p><strong>LLM Safety:</strong></p><ul><li><strong>Safety Detection:</strong> Monitors the model’s ability to detect and mitigate harmful or inappropriate content.</li><li><strong>Inappropriate Response Rate:</strong> Measures the frequency of unsafe or irrelevant responses.</li></ul><p><strong>LLM Hallucination:</strong></p><ul><li><strong>Hallucination Rate:</strong> Tracks how often the LLM generates inaccurate or fabricated information.</li><li><strong>Critical Hallucination Impact (CHI):</strong> Identifies instances where hallucinations lead to severe misunderstandings or negative outcomes.</li><li><strong>d. Evaluation Frameworks:</strong></li><li><strong>Human Ratings:</strong> Experts evaluate responses for relevance, coherence, and correctness.</li><li><strong>Automated Evaluations:</strong> Metrics like BLEU, ROUGE, and BERTScore compare generated responses to ground truth answers.</li></ul><p><strong>Combining Metrics for Insights</strong></p><p>When you use these metrics, you will understand how your LLM agents are performing and how your users are interacting with those agents.</p><ul><li><strong>Interaction and intent metrics</strong> provide insights into user engagement and core use cases.</li><li><strong>Goal achievement and flow metrics</strong> refine user journeys and identify areas for improvement.</li><li><strong>LLM-specific evaluations</strong> ensure safety, reliability, and accuracy.</li></ul><p>These metrics allow you to iterate faster: find gaps/areas of improvement, build new features, redefine a current feature, etc.</p><p>You can use platforms to build AI agents that have built-in evaluation metrics like <a href="https://www.voiceflow.com/">Voiceflow</a> and add an advanced analytics tool like <a href="https://www.feedbackintelligence.ai/">Feedback Intelligence</a>.</p><p>In the upcoming article, we’ll dive into a hands-on example of building an LLM agent, deploying it to production, and iterating on improvements using the metrics we covered earlier.</p><p>This article has been co-authored by <a href="https://medium.com/u/3783f728d8d1">movchinar</a> and myself!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1ab2eeea29e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrando Alexa con MS LUIS]]></title>
            <link>https://xavidop.medium.com/integrando-alexa-con-ms-luis-6fb3213c440e?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fb3213c440e</guid>
            <category><![CDATA[voice-first]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[microsoft-luis]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[alexa]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-11-12T19:32:56.012Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uf7HbHEZFYTYi-GW.jpg" /></figure><p>Alexa tiene un motor de procesamiento de lenguaje natural (NLP) muy bueno. Sin embargo, hay otros NLPs en el mercado que se pueden usar y estos incluyen cada vez más capacidades.</p><h3>Prerrequisitos</h3><p>Aquí tienes las tecnologías utilizadas en este proyecto</p><ol><li>Node.js v12.x</li><li>Visual Studio Code</li><li>Cuenta de Azure</li></ol><h3>Prefacio</h3><p>El NLP de Alexa cubre el 99% de los casos de uso de los usuarios más comunes y podemos crear potentes Skills de Alexa utilizando su IA. Sin embargo, es un hecho que MS LUIS, como NLP, ha evolucionado mucho y podemos encontrar ua gran cantidad de funcionalidades que no podemos encontrar dentro de Alexa como sus <a href="https://docs.microsoft.com/en-us/azure/cognitive-services/luis/howto-add-prebuilt-models">Prebuilt Domains</a> o sus prebuilt entities, subentities y <a href="https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-how-to-add-entities">Regular expression entities</a>.</p><h3>Configurando nuestra Alexa Skill</h3><p>Lo primero que debemos hacer es configurar nuestro modelo de interacción. Para eso vamos a crear el OrderIntent. Este intent tendrá, para este ejemplo, solo un utterance y un slot. Este slot tendrá el tipo AMAZON.SearchQuery:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*APg1IxUQLXmN7eBj.png" /></figure><p>Por definición, un slot AMAZON.SearchQuery es un tipo de slot un poco diferente del resto. Básicamente es una búsqueda como la que podría introducir en un motor de búsqueda estándar. Para usar este slot, debemos agregar una coletilla en los utterances. En este caso utilizaremos I want como coletilla. En definitiva, vamos a enviar a MS LUIS todo lo que Alexa reconoce después de I want.... Por ejemplo, I want 3 pizzas, a LUIS enviaremos 3 pizzas.</p><h3>Creando los Azure Cognitive Services</h3><p>Para interactuar con una aplicación de Microsoft LUIS desde una Skill de Amazon Alexa, necesitamos crear algunos Azure Resources.</p><p>Para eso, necesitamos crear un Natural Language Understanding Service dentro de los Cognitive Services en el <a href="https://portal.azure.com/">Portal de Azure</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ultMPP6tZFtwTEUV.png" /></figure><p>LUIS Azure Resources</p><p>NOTA: asegurate de haber clickado en los servicios de prediction y authoring durante el proceso de creación.</p><p>Después de esto, asegurate de copiar el endpoint. Vamos a utilizar este endpoint para interactuar con MS LUIS. Podmeos encontrar el endpoint después de la creación en la sección Keys and Endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/0*L0AHdHeipVr2A4bQ.png" /></figure><p>LUIS Endpoint</p><p>¡También asegurate de haber copiado la region y la Key 1 (esta es el subscription id que usaremos en los siguientes pasos)!</p><h3>Creando una App en MS LUIS</h3><p>Una vez que hayas creado los Azure Resources, debes crear la aplicación de MS Luis en el <a href="https://www.luis.ai/">Portal de LUIS</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z0Bb_cvFXa2YR5ya.png" /></figure><p>LUIS App</p><p>NOTA: asegúrese de utilizar el prediction endpoint que has creado en el paso anterior.</p><p>Ahora que tenemos nuestra aplicación MS LUIS, añadamos el modelo de interacción:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2dbNQpH8rIH2j2Mr.png" /></figure><p>Modelo de interacción en LUIS</p><p>Cuando hayas creado tus Entities e Intents, debes entrenar el Modelo y publicar la aplicación LUIS en Staging.</p><h3>Haciendo una petición a MS LUIS desde la Alexa Skill</h3><p>Ahora que tenemos todo configurado, ¡es hora de picar código! Para interactuar con MS LUIS desde el código Node.JS de la AWS Lambda de la Alexa Skill, vamos a utilizar el paquete npm llamado @ zure/cognitivoservices-luis-runtime. Puedes encontrar la documentación completa de este paquete <a href="https://www.npmjs.com/package/@azure/cognitiveservices-luis-runtime">aquí</a>.</p><p>Primero, tenemos que crear nuestro OrderIntentHandler, que es el controlador que va a administrar todas las request del OrderIntent:</p><pre>const OrderIntentHandler = {<br>    canHandle(handlerInput) {<br>        return Alexa.getRequestType(handlerInput.requestEnvelope) === &#39;IntentRequest&#39;<br>            &amp;&amp; Alexa.getIntentName(handlerInput.requestEnvelope) === &#39;OrderIntent&#39;;<br>    },<br>    async handle(handlerInput) {<br>        predictionRequest.query = Alexa.getSlotValueV2(handlerInput.requestEnvelope, &#39;luisquery&#39;).value;</pre><pre>        var result = await client.prediction.getSlotPrediction(appId, <br>                                                                &#39;Staging&#39;, <br>                                                                predictionRequest, <br>                                                                { verbose: true, showAllIntents: true });<br>        var speak = intentDispatcher(result.prediction.topIntent, result.prediction.entities)<br>        return handlerInput.responseBuilder<br>            .speak(speak)<br>            .reprompt(speak)<br>            .getResponse();<br>    }<br>};</pre><p>Como se puede ver en el código anterior, estamos obteniendo el valor de nuestro slot AMAZON.SearchQuery llamado luisquery y luego, enviamos ese valor a MS LUIS usando el objeto client y la función getSlotPrediction.</p><p>Para crear el cliente necesitamos tres properties:</p><ol><li>MS LUIS app id: Puedes encontrar este valor en la Aplicación LUIS en el Portal de LUIS.</li><li>MS Subscription id. Este id es la que obtuvimos en el paso anterior.</li><li>MS LUIS Prediction endpoint. Este endpoint es el que hemos obtenido en el paso anterior.</li></ol><p>Cuando tenemos estas properties podemos crear nuestro cliente de MS LUIS de la siguiente manera:</p><pre>require(&#39;dotenv&#39;).config({path: &#39;.env&#39;})<br>const { CognitiveServicesCredentials } = require(&quot;@azure/ms-rest-azure-js&quot;);<br>const { LUISRuntimeClient } = require(&quot;@azure/cognitiveservices-luis-runtime&quot;);<br> <br>let subscriptionKey = process.env[&quot;subscription-key&quot;];<br>const creds = new CognitiveServicesCredentials(subscriptionKey);<br> <br>const client = new LUISRuntimeClient(creds, process.env[&quot;endpoint&quot;]);<br>const appId = process.env[&quot;app-id&quot;]; <em>// replace this with your appId.</em><br>const predictionRequest = {<br>    query: &quot;&quot;,<br>    options: {<br>      datetimeReference: new Date(),<br>      preferExternalEntities: true<br>    }<br>  };</pre><p>El resultado que vamos a recibir de MS LUIS será gestionado por el intentDispatcher:</p><pre>function intentDispatcher(intent, entities) {<br>    var result = &#39;&#39;;<br>    switch (intent) {<br>        case &#39;PizzaIntent&#39;:<br>            result = `Okay, I will give you ${entities[&#39;number&#39;]} Pizzas`<br>            break;<br>        case &#39;BurgerIntent&#39;:<br>            result = `Okay, I will give you ${entities[&#39;number&#39;]} Burgers`<br>            break;<br>    <br>        default:<br>            result = &#39;Sorry I  didn\&#39;t catch you&#39;<br>            break;<br>    }</pre><pre>    return result;</pre><pre>}</pre><h3>Resultado Final</h3><p>Y eso es todo, aquí tienes el código completo ejecutándose. Alexa usando LUIS como su motor NLP:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/0*30lxSALBC-ig8_30.png" /></figure><p>Ejecución funcionando</p><h3>Recursos</h3><ul><li><a href="https://www.npmjs.com/package/ask-sdk">Official Alexa Skills Kit Node.js SDK</a> — The Official Node.js SDK Documentation</li><li><a href="https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html">Official Alexa Skills Kit Documentation</a> — Official Alexa Skills Kit Documentation</li><li><a href="https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/host-web-service.html">Official Express Adapter Documentation</a> — Express Adapter Documentation</li><li><a href="https://github.com/Azure/azure-sdk-for-js">Official Microsoft Azure SDK Documentation</a> — DOfficial Microsoft Azure SDK Documentation</li></ul><h3>Conclusión</h3><p>Como se puede ver, podemos integrar de una manera fácil otros motores de NLP dentro de nuestras Skills de Alexa. Este ejemplo es solo un experimento, pero os recomiendo que se use solo el NLP incorporado de Alexa, ya que puedes tener comportamientos inesperados usando AMAZON.SearchQuery.</p><p>Espero que este proyecto de ejemplo os sea de utilidad.</p><p>Puedes encontrar el código <a href="https://github.com/xavidop/alexa-helloworld-ms-luis">aquí</a></p><p>¡Eso es todo amigos!</p><p>Happy coding!</p><p><em>Originally published at </em><a href="https://xavidop.me/alexa/2021-11-12-alexa-ms-luis/"><em>https://xavidop.me</em></a><em> on November 12, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fb3213c440e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa y Kubernetes. Desplegando una Alexa Skill en AWS Elastic Kubernetes Services (VII)]]></title>
            <link>https://xavidop.medium.com/alexa-y-kubernetes-desplegando-una-alexa-skill-en-aws-elastic-kubernetes-services-vii-3e7ad906248f?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e7ad906248f</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[alexa]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 11 Nov 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-11-12T19:18:34.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PtZLocH4b6ZgZl1G.jpg" /></figure><p>Ahora tenemos todo preparado y listo para pasar a un clúster de Kubernetes en un proveedor cloud. Es un hecho que crear un clúster en cualquier proveedor cloud de forma manual es una tarea difícil. Además, si queremos automatizar estos despliegues, necesitamos algo que nos ayude en esta tediosa tarea. En esta publicación veremos cómo crear un clúster de Kubernetes y todos sus objetos requeridos y cómo implementar nuestra Skill de Alexa con Terraform usando <a href="https://aws.amazon.com/eks/">Elastic Kubernetes Service</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-t7Jisf4VghqLokO.jpg" /></figure><p>Elastic Kubernetes Service</p><h3>Requisitos previos</h3><p>Aquí tienes las tecnologías utilizadas en este proyecto:</p><ol><li>Node.js v12.x</li><li>Visual Studio Code</li><li>Docker 19.x</li><li>MongoDB Atlas Account</li><li>Kubectl CLI</li><li>Kind</li><li>go &gt;=1.11</li><li>Terraform 12.x</li><li>AWS Account</li><li>AWS CLI</li><li>AWS IAM Authenticator CLI</li></ol><h3>Terraform</h3><p>Terraform es una herramienta para construir, cambiar y crear versiones de infraestructuras cloud de manera segura y eficiente. Terraform puede gestionar proveedores de servicios existentes y populares, así como soluciones internas personalizadas.</p><p>Los archivos de configuración le indican a Terraform los componentes necesarios para ejecutar una sola aplicación. Terraform genera un plan de ejecución que describe lo que hará para alcanzar el estado deseado y luego lo ejecuta para construir la infraestructura descrita. A medida que cambia la configuración, Terraform puede determinar qué cambió y crear planes de ejecución incrementales que se pueden ir aplicando.</p><p>La infraestructura que Terraform puede administrar incluye componentes de bajo nivel como instancias de computación, almacenamiento y redes, así como componentes de alto nivel como entradas de DNS, características de SaaS, etc.</p><h3>Ficheros Terraform</h3><p>Después de la breve descripción general de Terraform, vamos a explicar todos los archivos de terraform y sus objetos que vamos a utilizar para desplegar el clúster y nuestra Skill de Alexa. Podemos encontrar todos los archivos relacionados con este despliegue en la carpeta terraform/eks.</p><h3>Terraform Providers</h3><p>Un provider es el responsable de comprender las interacciones de la API y exponer los resources. La mayoría de los providers disponibles corresponden a una plataforma de infraestructura cloud o local y ofrecen tipos de resources que corresponden a cada una de las características de esa plataforma.</p><p>Para el Elastic Kubernetes Service, usaremos el provider aws. Este provider nos permite crear todos los objetos de AWS que necesitamos para crear nuestro Stack para la Skill de Alexa:</p><pre>provider &quot;aws&quot; {<br>  region = &quot;eu-central-1&quot;<br>}</pre><p>Como vamos a desplegar Helm Charts, se requerirá tener el provider helm:</p><pre>provider &quot;helm&quot; {<br>  kubernetes {<br>    host                   = data.aws_eks_cluster.cluster.endpoint<br>    cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)<br>    token                  = data.aws_eks_cluster_auth.cluster.token<br>  }<br>}</pre><p>Como vamos a interactuar con el clúster, será útil tener el provider kubernetes:</p><pre>provider &quot;kubernetes&quot; {<br>  host                   = data.aws_eks_cluster.cluster.endpoint<br>  cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)<br>  token                  = data.aws_eks_cluster_auth.cluster.token<br>  load_config_file       = false<br>}</pre><h3>Terraform Modules y Resources</h3><p>Uno de los resources más importantes de un clúster EKS son las redes. Por eso, tenemos que crear nuestra Red y Subredes usando Virtual Private Cloud. Para eso, necesitamos usar el módulo vpc :</p><pre>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;2.64.0&quot;</pre><pre>  name                 = &quot;k8s-vpc&quot;<br>  cidr                 = &quot;172.16.0.0/16&quot;<br>  azs                  = data.aws_availability_zones.available.names<br>  private_subnets      = [&quot;172.16.1.0/24&quot;, &quot;172.16.2.0/24&quot;, &quot;172.16.3.0/24&quot;]<br>  public_subnets       = [&quot;172.16.4.0/24&quot;, &quot;172.16.5.0/24&quot;, &quot;172.16.6.0/24&quot;]<br>  enable_nat_gateway   = true<br>  single_nat_gateway   = true<br>  enable_dns_hostnames = true</pre><pre>  public_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${local.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/elb&quot;                      = &quot;1&quot;<br>  }</pre><pre>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${local.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/internal-elb&quot;             = &quot;1&quot;<br>  }<br>}</pre><p>Una vez que se ha creado la VPC, podemos crear el clúster que utilizará esa VPC. Para eso, necesitamos usar el módulo eks:</p><pre>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;13.2.1&quot;</pre><pre>  cluster_name    = local.cluster_name<br>  cluster_version = &quot;1.18&quot;<br>  subnets         = module.vpc.private_subnets<br>  wait_for_cluster_cmd          = &quot;until curl -k -s $ENDPOINT/healthz &gt;/dev/null; do sleep 4; done&quot;<br>  wait_for_cluster_interpreter = [&quot;C:/Program Files/Git/bin/sh.exe&quot;, &quot;-c&quot;]</pre><pre>  vpc_id = module.vpc.vpc_id</pre><pre>  node_groups = {<br>    first = {<br>      desired_capacity = 2<br>      max_capacity     = 10<br>      min_capacity     = 2</pre><pre>      instance_type = &quot;m5.large&quot;<br>    }<br>  }</pre><pre>  write_kubeconfig   = true<br>  config_output_path = &quot;./&quot;</pre><pre>  workers_additional_policies = [aws_iam_policy.worker_policy.arn]<br>}</pre><p>Además, crearemos algunas políticas de IAM de AWS específicas para nuestros nodos del clúster de Kubernetes para poder acceder a ellos desde Internet. Para eso usaremos el resources aws_iam_policy:</p><pre>resource &quot;aws_iam_policy&quot; &quot;worker_policy&quot; {<br>  name        = &quot;worker-policy&quot;<br>  description = &quot;Worker policy for the ALB Ingress&quot;</pre><pre>  policy = file(&quot;iam-policy.json&quot;)<br>}</pre><p>Todos los resources y modules comentados anteriormente están relacionados con el clúster de Kubernetes. Ahora es el momento de desplegar nuestra Skill de Alexa comenzando con el ngingx-ingress-controller:</p><pre>resource &quot;helm_release&quot; &quot;ingress&quot; {<br>  name       = &quot;nginx-ingress-controller&quot;<br>  chart      = &quot;nginx-ingress-controller&quot;<br>  repository = &quot;https://charts.bitnami.com/bitnami&quot;</pre><pre>  set {<br>    name  = &quot;rbac.create&quot;<br>    value = &quot;true&quot;<br>  }<br>}</pre><p>Después de eso, podemos desplegar con orgullo nuestro el Helm Chart de nuestra Alexa Skill en nuestro clúster de Kubernetes en el Cloud:</p><pre>resource &quot;helm_release&quot; &quot;alexa-skill&quot; {<br>  name       = &quot;alexa-skill&quot;<br>  chart      = &quot;../../helm/alexa-skill-chart&quot;<br>  depends_on = [helm_release.ingress]<br>}</pre><h3>Terraform Variables</h3><p>Hemos proporcionado algunas variables que podemos modificar fácilmente para cambiar el nombre del clúster o la región donde se desplegará el clúster. Para eso puedes modificar las variables locales en el fichero main.tf:</p><pre>locals {<br>  cluster_name = &quot;alexa-cluster&quot;<br>  region       = &quot;eu-central-1&quot;<br>}</pre><h3>Desplegando el Stack</h3><p>Para que un provider esté disponible en Terraform, necesitamos ejecutar terraform init, estos comandos descargan cualquier complemento que necesitemos para nuestros providers. Después de eso, tenemos que ejecutar terraform plan. El comando terraform plan se utiliza para crear un plan de ejecución. No modificará las cosas en la infraestructura. Terraform realiza una actualización, a menos que esté explícitamente deshabilitado, y luego determina qué acciones son necesarias para lograr el estado deseado especificado en los archivos de configuración. Este comando es una forma conveniente de verificar si el plan de ejecución para un conjunto de cambios coincide con nuestras expectativas sin realizar ningún cambio en los recursos reales o en el estado. Finalmente, necesitamos ejecutar terraform apply. El comando terraform apply se utiliza para aplicar los cambios necesarios para alcanzar el estado deseado de la configuración. Terraform apply también escribirá datos en el archivo terraform.tfstate. Una vez que se completa la ejecución, los recursos están disponibles de inmediato.</p><p>Aquí tienes la lista de comandos completa:</p><pre>terraform init<br>terraform plan<br>terraform appyly</pre><p>Después de ejecutar el comando terraform apply, podemos echar un vistazo a Elastic Kubernetes Service para ver que nuestro clúster ahora aparece:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1fPKO-NRWmzsp5MU.png" /></figure><p>Cluster creandose</p><p>Necesitamos esperar como 10 minutos hasta que se cree el clúster. Una vez creado el clúster, ahora podemos ver el cluster completo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0OIo-Y_4vIZa4Rvr.png" /></figure><p>Cluster Creado</p><p>Después de la creación del clúster, Terraform desplegará todos los gráficos de Helm. Aquí podemos ver todos los pods de Kubernetes desplegados:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JPQfj0VDNmsFt3_6.png" /></figure><p>Pods</p><p>Y aquí los Servicios de Kubernetes y la IP externa del nginx-ingress-controller. Esa IP es la que vamos a utilizar para realizar peticiones típicas de Alexa:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*phs6pTk6j0cJ-Obp.png" /></figure><p>Services y Ingress</p><h3>Probando peticiones</h3><p>Seguro que ya conoceis la famosa herramienta llamada <a href="https://www.postman.com/">Postman</a>. Las API REST se han convertido en el nuevo estándar para proporcionar una interfaz pública y segura para nuestros servicios web. Aunque REST se ha vuelto omnipresente, no siempre es fácil de probar. Postman, hace que sea más fácil probar y administrar las API REST HTTP. Postman nos brinda múltiples funciones para importar, probar y compartir API, lo que nos ayudará a nosotros y a nuestro equipo a ser más productivos a largo plazo.</p><p>Después de ejecutar nuestra aplicación, tendremos un endpoint disponible en <a href="http://a6ae89bc3ff9745de8bd095000264ff6-1697202105.eu-central-1.elb.amazonaws.com.">http://a6ae89bc3ff9745de8bd095000264ff6-1697202105.eu-central-1.elb.amazonaws.com.</a> Con Postman podemos emular cualquier solicitud de Alexa.</p><p>Por ejemplo, podemos probar una LaunchRequest:</p><pre>{<br>    &quot;version&quot;: &quot;1.0&quot;,<br>    &quot;session&quot;: {<br>      &quot;new&quot;: true,<br>      &quot;sessionId&quot;: &quot;amzn1.echo-api.session.[unique-value-here]&quot;,<br>      &quot;application&quot;: {<br>        &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>      },<br>      &quot;user&quot;: {<br>        &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>      },<br>      &quot;attributes&quot;: {}<br>    },<br>    &quot;context&quot;: {<br>      &quot;AudioPlayer&quot;: {<br>        &quot;playerActivity&quot;: &quot;IDLE&quot;<br>      },<br>      &quot;System&quot;: {<br>        &quot;application&quot;: {<br>          &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>        },<br>        &quot;user&quot;: {<br>          &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>        },<br>        &quot;device&quot;: {<br>          &quot;supportedInterfaces&quot;: {<br>            &quot;AudioPlayer&quot;: {}<br>          }<br>        }<br>      }<br>    },<br>    &quot;request&quot;: {<br>      &quot;type&quot;: &quot;LaunchRequest&quot;,<br>      &quot;requestId&quot;: &quot;amzn1.echo-api.request.[unique-value-here]&quot;,<br>      &quot;timestamp&quot;: &quot;2020-03-22T17:24:44Z&quot;,<br>      &quot;locale&quot;: &quot;en-US&quot;<br>    }<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JI-CXq3fa0o7ePJ7.png" /></figure><p>Petición a EKS</p><h3>Destruir el Stack</h3><p>Si queremos eliminar toda el stack creado por Terraform, simplemente tenemos que ejecutar:</p><pre>terraform destroy</pre><h3>Recursos</h3><ul><li><a href="https://www.npmjs.com/package/ask-sdk">Official Alexa Skills Kit Node.js SDK</a> — The Official Node.js SDK Documentation</li><li><a href="https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html">Official Alexa Skills Kit Documentation</a> — Official Alexa Skills Kit Documentation</li><li><a href="https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/host-web-service.html">Official Express Adapter Documentation</a> — Express Adapter Documentation</li><li><a href="https://kind.sigs.k8s.io/">Official Kind Documentation</a> — Kind Documentation</li><li><a href="https://kubernetes.io/docs">Official Kubernetes Documentation</a> — Kubernetes Documentation</li><li><a href="https://learnk8s.io/terraform-eks">Terraform EKS</a> — Terraform EKS</li><li><a href="https://github.com/k-mitevski/terraform-k8s/tree/master/04_terraform_helm_provider">Terraform EKS Github</a> — Terraform EKS GitHub</li></ul><h3>Conclusión</h3><p>Ahora tenemos nuestra Skill de Alexa ejecutándose en un clúster de Kubernetes de nuestro proveedor en la nube, todo automatizado con Terraform y listo para usar en nuestras Skill de Alexa.</p><p>Espero que este proyecto de ejemplo os sea de utilidad.</p><p>Puede encontrar el código <a href="https://github.com/xavidop/alexa-nodejs-k8s-helloworld">aquí</a></p><p>¡Eso es todo amigos!</p><p>Happy coding!</p><p><em>Originally published at </em><a href="https://xavidop.me/alexa/2021-11-11-alexa-kubernetes-7/"><em>https://xavidop.me</em></a><em> on November 11, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e7ad906248f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa y Kubernetes. Helm chart de nuestra Alexa skill (V)]]></title>
            <link>https://xavidop.medium.com/alexa-y-kubernetes-helm-chart-de-nuestra-alexa-skill-v-a21a2114efeb?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a21a2114efeb</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[alexa]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[voice-assistant]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 11 Nov 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-11-12T19:04:13.961Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UraSBD_x6E000jtx.jpg" /></figure><p>En este paso, tenemos nuestra Skill de Alexa dockerizada correctamente y todos los objetos de Kubernetes creados y ejecutándose en un clúster de Kubernetes. Ahora es el momento de empaquetar todos los componentes software (Alexa Skill + MongoDB), en este paso transformaremos todos nuestros objetos de kubernetes en templates usando Helm y agregaremos una instancia de MongoDB lista para ser desplegada en un clúster de Kubernetes como dependencia de nuestro Helm Chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kMsD5bu14hxEVgJ-.png" /></figure><p>Uso de MongoDB proporcionado en el Chart de Helm</p><h3>Requisitos previos</h3><p>Aquí tienes las tecnologías utilizadas en este proyecto:</p><ol><li>Node.js v12.x</li><li>Visual Studio Code</li><li>Docker 19.x</li><li>MongoDB Atlas Account</li><li>Kubectl CLI</li><li>Kind</li><li>go &gt;=1.11</li><li>Helm v3.x</li></ol><h3>Helm chart</h3><p>Para diseñar el Helm Chart de nuestra Skill de Alexa, es importante explicar qué es Helm. Esta herramienta facilitará el desarrollo y el ciclo de vida de la Alexa Skill. También es una herramienta que se utiliza para administrar paquetes de Kubernetes. Estos paquetes se denominan Charts. Un Chart es una colección de archivos que describen un conjunto de recursos de Kubernetes. Con Helm podemos realizar las siguientes tareas:</p><ul><li>Empaquetar nuestras aplicaciones como Chart.</li><li>Interactuar con repositorios de Charts (públicos o privados).</li><li>Instalación y desinstalación de Charts en clústeres de Kubernetes.</li><li>Gestión de Charts previamente instalados con Helm.</li><li>Además, es una herramienta para administrar recursos de Kubernetes empaquetados y preconfigurados. En otras palabras, Helm nos permite administrar templates que facilitan el despliegue de cualquier objeto de Kubernetes. Entonces, no será necesario tener conocimientos avanzados de esos objetos de Kubernetes para desplegarlos.</li></ul><p>Nuestro Helm Chart se encuentra en helm/alexa-skill-chart</p><pre>├── Chart.yaml<br>├── README.md<br>├── requirements.yaml<br>├── templates<br>│   ├── deployment.yaml<br>│   ├── service.yaml<br>│   ├── ingress.yaml<br>└── values.yaml</pre><p>El Chart de esta Skill de Alexa tendría los siguientes archivos:</p><ol><li>Chart.yaml: archivo con los metadatos del paquete. Nombre, versión, descripción. En este archivo indicaremos las dependencias de la Alexa Skill (MongoDB). Aquí podemos agregar otros Charts.</li><li>Templates: los templates se almacenan en este directorio.</li><li>values.yml: valores predeterminados utilizados en los templates.</li></ol><p>Antes de comenzar, como nuestro Chart incluye un MongoDB como dependencia, tendremos que agregarlo en nuestro archivo Chart.yaml.</p><p>Primero necesitamos agregar el repositorio de Helm donde se almacena el Chart de MongoDB con los siguientes comandos:</p><pre>helm repo add bitnami https://charts.bitnami.com/bitnami<br>helm repo update</pre><p>Luego podemos agregar el Chart de MongoDB: <a href="https://github.com/bitnami/charts/tree/master/bitnami/mongodb">https://github.com/bitnami/charts/tree/master/bitnami/mongodb</a> en nuestro archivo Chart.yaml:</p><pre>apiVersion: v2<br>name: alexa-skill<br>description: A Helm chart for Kubernetes</pre><pre><em># A chart can be either an &#39;application&#39; or a &#39;library&#39; chart.</em><br><em>#</em><br><em># Application charts are a collection of templates that can be packaged into versioned archives</em><br><em># to be deployed.</em><br><em>#</em><br><em># Library charts provide useful utilities or functions for the chart developer. They&#39;re included as</em><br><em># a dependency of application charts to inject those utilities and functions into the rendering</em><br><em># pipeline. Library charts do not define any templates and therefore cannot be deployed.</em><br>type: application</pre><pre><em># This is the chart version. This version number should be incremented each time you make changes</em><br><em># to the chart and its templates, including the app version.</em><br>version: 1.0.0</pre><pre><em># This is the version number of the application being deployed. This version number should be</em><br><em># incremented each time you make changes to the application.</em><br>appVersion: 1.0.0</pre><pre>dependencies:<br>- name: mongodb<br>  version: 10.3.3<br>  repository: alias:bitnami<br>  alias: mongodb<br>  condition: mongodb.enabled</pre><h3>Creando los templates</h3><p>La siguiente imagen muestra lo que sucede cuando usamos Helm y cómo transforma nuestros templates en objetos de Kubernetes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UEQioDH0-1tbaDy6.png" /></figure><p>Helm templates</p><p>Ahora agregaremos la capa Helm para permitir que nuestra Skill de alexa sea escalable, extensible, environment-aware, version-aware, incremental, personalizada, dinámica y reutilizable. Agregar esta capa significa crear templates para todos nuestros objetos de Kubernetes.</p><h3>Deployment template</h3><p>A continuación podemos encontrar el Deployment de nuestra Skill de Alexa pero ahora con la capa Helm que nos permite configurar toda la información a través del archivo values.yaml.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: {{ include &quot;alexa-skill.fullname&quot; . }}<br>  labels:<br>    {{- include &quot;alexa-skill.labels&quot; . | nindent 4 }}<br>spec:<br>  replicas: {{ .Values.replicaCount }}<br>  selector:<br>    matchLabels:<br>      {{- include &quot;alexa-skill.selectorLabels&quot; . | nindent 6 }}<br>  template:<br>    metadata:<br>      labels:<br>        {{- include &quot;alexa-skill.selectorLabels&quot; . | nindent 8 }}<br>    spec:<br>    {{- with .Values.imagePullSecrets }}<br>      imagePullSecrets:<br>        {{- toYaml . | nindent 8 }}<br>    {{- end }}<br>      containers:<br>        - name: {{ .Chart.Name }}<br>          image:  .Values.image.repo }}/{{ .Values.image.name }}:{{ .Values.image.tag }}&quot;<br>          imagePullPolicy: {{ .Values.pullPolicy }}<br>          ports:<br>            - name: http<br>              containerPort: {{ .Values.service.NodePort }}<br>              protocol: TCP<br>          resources:<br>            {{- toYaml .Values.resources | nindent 12 }}<br>          env:<br>            - name: DB_TYPE<br>              value: {{ .Values.mongodb.type }}<br>            - name: DB_HOST<br>              {{ if eq .Values.mongodb.type &quot;provided&quot; }}<br>              value: {{ include &quot;alexa-skill.fullname&quot; . }}-{{ .Values.mongodb.service.name }}<br>              {{ else }}<br>              value: {{ .Values.mongodb.service.name }}<br>              {{ end }}<br>            - name: DB_PORT<br>              value:  .Values.mongodb.service.port }}&quot;<br>            - name: DB_USER<br>              value: {{ .Values.mongodb.auth.username }}<br>            - name: DB_PASSWORD<br>              value: {{ .Values.mongodb.auth.password }}<br>            - name: DB_DATABASE<br>              value: {{ .Values.mongodb.auth.database }}    <br>      {{- with .Values.nodeSelector }}<br>      nodeSelector:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>    {{- with .Values.affinity }}<br>      affinity:<br>        {{- toYaml . | nindent 8 }}<br>    {{- end }}<br>    {{- with .Values.tolerations }}<br>      tolerations:<br>        {{- toYaml . | nindent 8 }}<br>    {{- end }}</pre><h3>Service template</h3><p>A continuación podemos encontrar el Servicio de nuestra Skill de Alexa pero ahora con la capa Helm que nos permite configurar toda la información a través del archivo values.yaml.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: {{ include &quot;alexa-skill.fullname&quot; . }}<br>  labels:<br>    {{- include &quot;alexa-skill.labels&quot; . | nindent 4 }}<br>spec:<br>  ports:<br>    - port: {{ .Values.service.port }}<br>      targetPort: {{ .Values.service.NodePort }}<br>      protocol: TCP<br>  selector:<br>    {{- include &quot;alexa-skill.selectorLabels&quot; . | nindent 4 }}</pre><h3>Ingress template</h3><p>A continuación podemos encontrar el Ingress de nuestra Skill de Alexa pero ahora con la capa Helm que nos permite configurar toda la información a través del archivo values.yaml.</p><pre>apiVersion: networking.k8s.io/v1beta1<br>kind: Ingress<br>metadata:<br>  name: {{ .Values.ingress.name }}<br>  labels:<br>    {{- include &quot;alexa-skill.labels&quot; . | nindent 4 }}<br>  annotations:<br>    <em># Target URI where the traffic must be redirected</em><br>    <em># More info: https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md</em><br>    nginx.ingress.kubernetes.io/rewrite-target: /<br>    kubernetes.io/ingress.class: nginx<br>spec:<br>  rules:<br>    <em># Uncomment the below to only allow traffic from this domain and route based on it</em><br>    <em># - host: my-host # your domain name with A record pointing to the nginx-ingress-controller IP</em><br>    - http:<br>        paths:<br>        - path: / <em># Everything on this path will be redirected to the rewrite-target</em><br>          backend:<br>            serviceName: {{ include &quot;alexa-skill.fullname&quot; . }} <em># the exposed svc name and port</em><br>            servicePort: {{ .Values.ingress.port }}</pre><h3>Ficheros Values</h3><p>Como podemos ver, todos nuestros objetos de Kubernetes se convierten en templates. Estos templates necesitan un archivo values.yaml para obtener el objeto final de Kubernetes.</p><p>Si queremos utilizar la Alexa Skill con MongoDB proporcionado en el Helm Chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EyZQk3hlW4lTMEPg.png" /></figure><p>MongoDB porporcionado en el Helm Chart</p><p>Podemos utilizar este archivo Valores:</p><pre><em># Default values for alexa-skill.</em><br><em># This is a YAML-formatted file.</em><br><em># Declare variables to be passed into your templates.</em></pre><pre>replicaCount: 1</pre><pre>image: <br>  repo: xavidop<br>  name: alexa-skill-nodejs-express<br>  tag: latest<br>pullPolicy: Always</pre><pre>imagePullSecrets: []<br>nameOverride: &quot;&quot;<br>fullnameOverride: &quot;&quot;</pre><pre>service:<br>  port: 3000<br>  NodePort: 3000</pre><pre>ingress:<br>  enabled: true<br>  name: alexa-skill-ingress<br>  port: 3000</pre><pre>resources:<br>  limits:<br>    cpu: 50m<br>    memory: 128Mi<br>  requests:<br>    cpu: 50m<br>    memory: 128Mi</pre><pre><em># Mongo provided conneciton</em><br>mongodb:<br>  enabled: true<br>  type: provided <em># could be atlas or provided</em><br>  auth:<br>    username: root<br>    password: root<br>    database: alexa<br>    rootPassword: root<br>  service:<br>    name: mongodb<br>    port: 27017</pre><pre>nodeSelector: {}</pre><pre>tolerations: []</pre><pre>affinity: {}</pre><p>Si queremos utilizar la Alexa Skill con MongoDB Atlas Cloud:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qrepuPYgLYNHec-f.png" /></figure><p>MongoDB con Atlas Cloud</p><p>Podemos utilizar este archivo Valores:</p><pre><em># Default values for alexa-skill.</em><br><em># This is a YAML-formatted file.</em><br><em># Declare variables to be passed into your templates.</em></pre><pre>replicaCount: 1</pre><pre>image: <br>  repo: xavidop<br>  name: alexa-skill-nodejs-express<br>  tag: latest<br>pullPolicy: Always</pre><pre>imagePullSecrets: []<br>nameOverride: &quot;&quot;<br>fullnameOverride: &quot;&quot;</pre><pre>service:<br>  port: 3000<br>  NodePort: 3000</pre><pre>ingress:<br>  enabled: true<br>  name: alexa-skill-ingress<br>  port: 3000</pre><pre>resources:<br>  limits:<br>    cpu: 50m<br>    memory: 128Mi<br>  requests:<br>    cpu: 50m<br>    memory: 128Mi</pre><pre><em># Atlas connection</em><br>mongodb:<br>  enabled: false<br>  type: atlas <em># could be atlas or provided</em><br>  auth:<br>    username: root<br>    password: root<br>    database: alexa<br>  service:<br>    name: cluster0.qlqga.mongodb.net</pre><pre>nodeSelector: {}</pre><pre>tolerations: []</pre><pre>affinity: {}</pre><h3>Instalación del Helm Chart</h3><p>Una vez explicado todo el Chart de Helm. Ahora tenemos que instalarlo en nuestro Kind Cluster. Para eso, tenemos que ejecutar el siguiente comando:</p><pre><em># Update the dependencies</em><br>helm dep update helm/alexa-skill-chart/<br><em># Install the chart</em><br>helm install alexa-skill helm/alexa-skill-chart/ --namespace alexa-skill</pre><p>If we want to remove oour Chart Installer, just run the following command:</p><pre><em>## Uninstall</em><br>helm uninstall alexa-skill --namespace alexa-skill</pre><h3>Probando peticiones localmente</h3><p>Seguro que ya conoceis la famosa herramienta llamada <a href="https://www.postman.com/">Postman</a>. Las API REST se han convertido en el nuevo estándar para proporcionar una interfaz pública y segura para nuestros servicios web. Aunque REST se ha vuelto omnipresente, no siempre es fácil de probar. Postman, hace que sea más fácil probar y administrar las API REST HTTP. Postman nos brinda múltiples funciones para importar, probar y compartir API, lo que nos ayudará a nosotros y a nuestro equipo a ser más productivos a largo plazo.</p><p>Después de ejecutar nuestra aplicación, tendremos un endpoint disponible en <a href="http://localhost:3008.">http://localhost:3008.</a> Con Postman podemos emular cualquier solicitud de Alexa.</p><p>Por ejemplo, podemos probar una LaunchRequest:</p><pre>{<br>    &quot;version&quot;: &quot;1.0&quot;,<br>    &quot;session&quot;: {<br>      &quot;new&quot;: true,<br>      &quot;sessionId&quot;: &quot;amzn1.echo-api.session.[unique-value-here]&quot;,<br>      &quot;application&quot;: {<br>        &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>      },<br>      &quot;user&quot;: {<br>        &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>      },<br>      &quot;attributes&quot;: {}<br>    },<br>    &quot;context&quot;: {<br>      &quot;AudioPlayer&quot;: {<br>        &quot;playerActivity&quot;: &quot;IDLE&quot;<br>      },<br>      &quot;System&quot;: {<br>        &quot;application&quot;: {<br>          &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>        },<br>        &quot;user&quot;: {<br>          &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>        },<br>        &quot;device&quot;: {<br>          &quot;supportedInterfaces&quot;: {<br>            &quot;AudioPlayer&quot;: {}<br>          }<br>        }<br>      }<br>    },<br>    &quot;request&quot;: {<br>      &quot;type&quot;: &quot;LaunchRequest&quot;,<br>      &quot;requestId&quot;: &quot;amzn1.echo-api.request.[unique-value-here]&quot;,<br>      &quot;timestamp&quot;: &quot;2020-03-22T17:24:44Z&quot;,<br>      &quot;locale&quot;: &quot;en-US&quot;<br>    }<br>  }</pre><h3>Recursos</h3><ul><li><a href="https://www.npmjs.com/package/ask-sdk">Official Alexa Skills Kit Node.js SDK</a> — The Official Node.js SDK Documentation</li><li><a href="https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html">Official Alexa Skills Kit Documentation</a> — Official Alexa Skills Kit Documentation</li><li><a href="https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/host-web-service.html">Official Express Adapter Documentation</a> — Express Adapter Documentation</li><li><a href="https://kind.sigs.k8s.io/">Official Kind Documentation</a> — Kind Documentation</li><li><a href="https://kubernetes.io/docs">Official Kubernetes Documentation</a> — Kubernetes Documentation</li><li><a href="https://helm.sh/docs/">Official Helm Documentation</a> — Helm Documentation</li></ul><h3>Conclusión</h3><p>Como se puede ver, tenemos nuestra Skill de Alexa ejecutándose en Kubernetes usando templates y empaquetados como Helm Chart. Gracias al archivo Values podemos cambiar todos los parámetros/propiedades clave de nuestra Alexa Skill de una manera fácil.</p><p>Espero que este proyecto de ejemplo os sea de utilidad.</p><p>Puede encontrar el código <a href="https://github.com/xavidop/alexa-nodejs-k8s-helloworld">aquí</a></p><p>¡Eso es todo amigos! Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a21a2114efeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa y Kubernetes. Desplegando una Alexa Skill en Google Kubernetes Engine (IX)]]></title>
            <link>https://xavidop.medium.com/alexa-y-kubernetes-desplegando-una-alexa-skill-en-google-kubernetes-engine-ix-8717dd8870b1?source=rss-933813d028b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8717dd8870b1</guid>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[voice-assistant]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[alexa]]></category>
            <dc:creator><![CDATA[Xavier Portilla Edo]]></dc:creator>
            <pubDate>Thu, 11 Nov 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-11-12T19:29:59.252Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YIHk1k1p4gLkIUQj.jpg" /></figure><p>Ahora tenemos todo preparado y listo para pasar a un clúster de Kubernetes en un proveedor cloud. Es un hecho que crear un clúster en cualquier proveedor cloud de forma manual es una tarea difícil. Además, si queremos automatizar estos despliegues, necesitamos algo que nos ayude en esta tediosa tarea. En esta publicación veremos cómo crear un clúster de Kubernetes y todos sus objetos requeridos y cómo implementar nuestra Skill de Alexa con Terraform usando <a href="https://cloud.google.com/kubernetes-engine?">Google Kubernetes Engine</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/0*q9LoStqCIOVhpBD9.png" /></figure><p>Google Kubernetes Engine</p><h3>Requisitos previos</h3><p>Aquí tienes las tecnologías utilizadas en este proyecto:</p><ol><li>Node.js v12.x</li><li>Visual Studio Code</li><li>Docker 19.x</li><li>MongoDB Atlas Account</li><li>Kubectl CLI</li><li>Kind</li><li>go &gt;=1.11</li><li>Terraform 12.x</li><li>Google Cloud Account</li><li>gcloud CLI</li></ol><h3>Terraform</h3><p>Terraform es una herramienta para construir, cambiar y crear versiones de infraestructuras cloud de manera segura y eficiente. Terraform puede gestionar proveedores de servicios existentes y populares, así como soluciones internas personalizadas.</p><p>Los archivos de configuración le indican a Terraform los componentes necesarios para ejecutar una sola aplicación. Terraform genera un plan de ejecución que describe lo que hará para alcanzar el estado deseado y luego lo ejecuta para construir la infraestructura descrita. A medida que cambia la configuración, Terraform puede determinar qué cambió y crear planes de ejecución incrementales que se pueden ir aplicando.</p><p>La infraestructura que Terraform puede administrar incluye componentes de bajo nivel como instancias de computación, almacenamiento y redes, así como componentes de alto nivel como entradas de DNS, características de SaaS, etc.</p><h3>Ficheros Terraform</h3><p>Después de la breve descripción general de Terraform, vamos a explicar todos los archivos de terraform y sus objetos que vamos a utilizar para desplegar el clúster y nuestra Skill de Alexa. Podemos encontrar todos los archivos relacionados con este despliegue en la carpetaterraform/gke.</p><h3>Terraform Providers</h3><p>Un provider es el responsable de comprender las interacciones de la API y exponer los resources. La mayoría de los providers disponibles corresponden a una plataforma de infraestructura cloud o local y ofrecen tipos de resources que corresponden a cada una de las características de esa plataforma.</p><p>Para el Google kubernetes Engine, usaremos el provider google. Este provider nos permite crear todos los objetos de Google Cloud que necesitamos para crear nuestro Stack para la Skill de Alexa:</p><pre>provider &quot;google&quot; {<br>  project = var.project_id<br>  region  = var.region<br>}</pre><p>Como vamos a desplegar Helm Charts, se requerirá tener el provider helm:</p><pre>provider &quot;helm&quot; {</pre><pre>  kubernetes {<br>    host                   = google_container_cluster.primary.endpoint<br>    token                  = data.google_client_config.current.access_token<br>    client_certificate     = base64decode(google_container_cluster.primary.master_auth.0.client_certificate)<br>    client_key             = base64decode(google_container_cluster.primary.master_auth.0.client_key)<br>    cluster_ca_certificate = base64decode(google_container_cluster.primary.master_auth.0.cluster_ca_certificate)<br>  }<br>}</pre><h3>Terraform Resources</h3><p>Uno de los resources más importantes de un clúster de GKE es la red. Por eso, tenemos que crear nuestra red y subredes usando Virtual Private Cloud Network:</p><pre>resource &quot;google_compute_network&quot; &quot;vpc&quot; {<br>  name                    = &quot;${var.project_id}-vpc&quot;<br>  auto_create_subnetworks = &quot;false&quot;<br>}</pre><pre><em># Subnet</em><br>resource &quot;google_compute_subnetwork&quot; &quot;subnet&quot; {<br>  name          = &quot;${var.project_id}-subnet&quot;<br>  region        = var.region<br>  network       = google_compute_network.vpc.name<br>  ip_cidr_range = &quot;10.10.0.0/24&quot;</pre><pre>}</pre><p>Una vez que se ha creado la VPC, podemos crear el clúster que utilizará esa VPC. Para eso, necesitamos usar el módulo google_container_cluster:</p><pre>resource &quot;google_container_cluster&quot; &quot;primary&quot; {<br>  name     = &quot;${var.project_id}-gke&quot;<br>  location = var.region</pre><pre>  remove_default_node_pool = true<br>  initial_node_count       = 1</pre><pre>  network    = google_compute_network.vpc.name<br>  subnetwork = google_compute_subnetwork.subnet.name</pre><pre>}</pre><p>Cada clúster debe tener un grupo de nodos donde se desplegarán los objetos de kubernetes. Para crear ese grupo de nodos en Google Cloud usaremos el resource google_container_node_pool:</p><pre>resource &quot;google_container_node_pool&quot; &quot;primary_nodes&quot; {<br>  name       = &quot;${google_container_cluster.primary.name}-node-pool&quot;<br>  location   = var.region<br>  cluster    = google_container_cluster.primary.name<br>  node_count = var.gke_num_nodes</pre><pre>  node_config {<br>    oauth_scopes = [<br>      &quot;https://www.googleapis.com/auth/logging.write&quot;,<br>      &quot;https://www.googleapis.com/auth/monitoring&quot;,<br>    ]</pre><pre>    labels = {<br>      env = var.project_id<br>    }</pre><pre>    <em># preemptible  = true</em><br>    machine_type = &quot;n1-standard-1&quot;<br>    tags         = [&quot;gke-node&quot;, &quot;${var.project_id}-gke&quot;]<br>    metadata = {<br>      disable-legacy-endpoints = &quot;true&quot;<br>    }<br>  }<br>}</pre><p>Todos los resources y modules comentados anteriormente están relacionados con el clúster de Kubernetes. Ahora es el momento de desplegar nuestra Skill de Alexa comenzando con el ngingx-ingress-controller:</p><pre>resource &quot;helm_release&quot; &quot;ingress&quot; {<br>  name       = &quot;nginx-ingress-controller&quot;<br>  chart      = &quot;nginx-ingress-controller&quot;<br>  repository = &quot;https://charts.bitnami.com/bitnami&quot;</pre><pre>  set {<br>    name  = &quot;rbac.create&quot;<br>    value = &quot;true&quot;<br>  }<br>}</pre><p>Después de eso, podemos desplegar con orgullo nuestro el Helm Chart de nuestra Alexa Skill en nuestro clúster de Kubernetes en el Cloud:</p><pre>resource &quot;helm_release&quot; &quot;alexa-skill&quot; {<br>  name       = &quot;alexa-skill&quot;<br>  chart      = &quot;../../helm/alexa-skill-chart&quot;<br>  depends_on = [helm_release.ingress]<br>}</pre><h3>Terraform Variables</h3><p>Hemos proporcionado algunas variables que podemos modificar fácilmente para cambiar el nombre del project_id o la región donde se desplegará el clúster. Para eso podemos modificar las variables en el fihcero terraform.tfvars:</p><pre>project_id = &quot;alexa-k8s&quot;<br>region     = &quot;us-central1&quot;</pre><p>Para crear un proyecto de Google Cloud usando la cli de gcloud y configurar este proyecto como el proyecto predeterminado, necesitamos ejecutar los siguientes comandos:</p><pre>gcloud init<br>gcloud projects create alexa-k8s<br>gcloud auth application-default login<br>gcloud config set project alexa-k8s<br>gcloud config get-value project</pre><h3>Desplegando el Stack</h3><p>Para que un provider esté disponible en Terraform, necesitamos ejecutar terraform init, estos comandos descargan cualquier complemento que necesitemos para nuestros providers. Después de eso, tenemos que ejecutar terraform plan. El comando terraform plan se utiliza para crear un plan de ejecución. No modificará las cosas en la infraestructura. Terraform realiza una actualización, a menos que esté explícitamente deshabilitado, y luego determina qué acciones son necesarias para lograr el estado deseado especificado en los archivos de configuración. Este comando es una forma conveniente de verificar si el plan de ejecución para un conjunto de cambios coincide con nuestras expectativas sin realizar ningún cambio en los recursos reales o en el estado. Finalmente, necesitamos ejecutar terraform apply. El comando terraform apply se utiliza para aplicar los cambios necesarios para alcanzar el estado deseado de la configuración. Terraform apply también escribirá datos en el archivo terraform.tfstate. Una vez que se completa la ejecución, los recursos están disponibles de inmediato.</p><p>Aquí tienes la lista de comandos completa:</p><pre>terraform init<br>terraform plan<br>terraform appyly</pre><p>Después de ejecutar el terraform apply, podemos echar un vistazo a Google kubernetes Engine para ver que nuestro clúster ahora aparece:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FARqyPwn7VR9Bjjm.png" /></figure><p>Cluster creandose</p><p>Necesitamos esperar como 10 minutos hasta que se cree el clúster. Una vez creado el clúster, ahora podemos ver el cluster completo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qLiOa0L7pAK7BBKB.png" /></figure><p>Cluster creado</p><p>Después de la creación del clúster, Terraform desplegará todos los gráficos de Helm. Aquí podemos ver todos los pods de Kubernetes desplegados:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FuLcqvIuBCJSE8gt.png" /></figure><p>Pods</p><p>Y aquí los Servicios de Kubernetes y la IP externa del nginx-ingress-controller. Esa IP es la que vamos a utilizar para realizar peticiones típicas de Alexa:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j6yAhCyehR4xc_Z4.png" /></figure><p>Services y Ingress</p><h3>Probando peticiones</h3><p>Seguro que ya conoceis la famosa herramienta llamada <a href="https://www.postman.com/">Postman</a>. Las API REST se han convertido en el nuevo estándar para proporcionar una interfaz pública y segura para nuestros servicios web. Aunque REST se ha vuelto omnipresente, no siempre es fácil de probar. Postman, hace que sea más fácil probar y administrar las API REST HTTP. Postman nos brinda múltiples funciones para importar, probar y compartir API, lo que nos ayudará a nosotros y a nuestro equipo a ser más productivos a largo plazo.</p><p>Después de ejecutar nuestra aplicación, tendremos un endpoint disponible en <a href="http://35.193.101.213.">http://35.193.101.213.</a> Con Postman podemos emular cualquier solicitud de Alexa.</p><p>Por ejemplo, podemos probar una LaunchRequest:</p><pre>{<br>    &quot;version&quot;: &quot;1.0&quot;,<br>    &quot;session&quot;: {<br>      &quot;new&quot;: true,<br>      &quot;sessionId&quot;: &quot;amzn1.echo-api.session.[unique-value-here]&quot;,<br>      &quot;application&quot;: {<br>        &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>      },<br>      &quot;user&quot;: {<br>        &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>      },<br>      &quot;attributes&quot;: {}<br>    },<br>    &quot;context&quot;: {<br>      &quot;AudioPlayer&quot;: {<br>        &quot;playerActivity&quot;: &quot;IDLE&quot;<br>      },<br>      &quot;System&quot;: {<br>        &quot;application&quot;: {<br>          &quot;applicationId&quot;: &quot;amzn1.ask.skill.[unique-value-here]&quot;<br>        },<br>        &quot;user&quot;: {<br>          &quot;userId&quot;: &quot;amzn1.ask.account.[unique-value-here]&quot;<br>        },<br>        &quot;device&quot;: {<br>          &quot;supportedInterfaces&quot;: {<br>            &quot;AudioPlayer&quot;: {}<br>          }<br>        }<br>      }<br>    },<br>    &quot;request&quot;: {<br>      &quot;type&quot;: &quot;LaunchRequest&quot;,<br>      &quot;requestId&quot;: &quot;amzn1.echo-api.request.[unique-value-here]&quot;,<br>      &quot;timestamp&quot;: &quot;2020-03-22T17:24:44Z&quot;,<br>      &quot;locale&quot;: &quot;en-US&quot;<br>    }<br>  }</pre><p>And here the Kubernetes Services and the external IP of the nginx-ingress-controller. That IP is the one we are going to use to make Alexa requests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uSRZZd-jPxMOsw4i.png" /></figure><p>Petición a GKE</p><h3>Destruir el Stack</h3><p>Si queremos eliminar toda el stack creado por Terraform, simplemente tenemos que ejecutar:</p><pre>terraform destroy</pre><h3>Recursos</h3><ul><li><a href="https://www.npmjs.com/package/ask-sdk">Official Alexa Skills Kit Node.js SDK</a> — The Official Node.js SDK Documentation</li><li><a href="https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html">Official Alexa Skills Kit Documentation</a> — Official Alexa Skills Kit Documentation</li><li><a href="https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/host-web-service.html">Official Express Adapter Documentation</a> — Express Adapter Documentation</li><li><a href="https://kind.sigs.k8s.io/">Official Kind Documentation</a> — Kind Documentation</li><li><a href="https://kubernetes.io/docs">Official Kubernetes Documentation</a> — Kubernetes Documentation</li><li><a href="https://learn.hashicorp.com/tutorials/terraform/gke">Terraform GKE</a> — Terraform GKE</li><li><a href="https://github.com/hashicorp/learn-terraform-provision-gke-cluster">Terraform GKE Official</a> — Terraform Official</li><li><a href="https://github.com/GoogleCloudPlatform/terraform-google-examples/tree/master/example-gke-k8s-helm">Terraform GKE Github</a> — Terraform GKE GitHub</li></ul><h3>Conclusión</h3><p>Ahora tenemos nuestra Skill de Alexa ejecutándose en un clúster de Kubernetes de nuestro proveedor en la nube, todo automatizado con Terraform y listo para usar en nuestras Skill de Alexa.</p><p>Espero que este proyecto de ejemplo os sea de utilidad.</p><p>Puede encontrar el código <a href="https://github.com/xavidop/alexa-nodejs-k8s-helloworld">aquí</a></p><p>¡Eso es todo amigos!</p><p>Happy coding!</p><p><em>Originally published at </em><a href="https://xavidop.me/alexa/2021-11-11-alexa-kubernetes-9/"><em>https://xavidop.me</em></a><em> on November 11, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8717dd8870b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>