<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Salada de Dados</title>
    <description>The latest articles on DEV Community by Salada de Dados (@saladadedados).</description>
    <link>https://dev.to/saladadedados</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4183496%2F7061d7be-315b-4b48-936f-ba4d836d0e61.png</url>
      <title>DEV Community: Salada de Dados</title>
      <link>https://dev.to/saladadedados</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saladadedados"/>
    <language>en</language>
    <item>
      <title>How to Build a LangGraph Agent with FastAPI and SSE Streaming</title>
      <dc:creator>Salada de Dados</dc:creator>
      <pubDate>Wed, 14 Oct 2026 03:57:14 +0000</pubDate>
      <link>https://dev.to/saladadedados/how-to-build-a-langgraph-agent-with-fastapi-and-sse-streaming-4a7e</link>
      <guid>https://dev.to/saladadedados/how-to-build-a-langgraph-agent-with-fastapi-and-sse-streaming-4a7e</guid>
      <description>&lt;p&gt;Building an AI agent is relatively straightforward. Making it accessible through an API, integrating real tools, and streaming execution updates to a client is where the architecture becomes more interesting.&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll look at a small, working example that combines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LangGraph&lt;/strong&gt; for agent orchestration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI&lt;/strong&gt; for HTTP endpoints&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server-Sent Events (SSE)&lt;/strong&gt; for streaming responses&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open-Meteo&lt;/strong&gt; as a real external tool&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn't to build a production-ready platform in one tutorial. It's to establish a working foundation and understand the responsibilities of each component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source code:&lt;/strong&gt; &lt;a href="https://github.com/salada-dados/langgraph-fastapi-example" rel="noopener noreferrer"&gt;LangGraph + FastAPI Example on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Why LangGraph and FastAPI?
&lt;/h2&gt;

&lt;p&gt;LangGraph handles the agent's execution flow.&lt;/p&gt;

&lt;p&gt;FastAPI exposes that execution to external clients.&lt;/p&gt;

&lt;p&gt;These are different responsibilities, and separating them makes the application easier to understand and extend.&lt;/p&gt;

&lt;p&gt;A useful mental model is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbbzpgcxy6rvxpe05vkha.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbbzpgcxy6rvxpe05vkha.png" alt="LangGraph agent architecture showing a FastAPI endpoint connected to a LangGraph workflow with LLM reasoning, tool execution, and an external Open-Meteo API." width="608" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The client shouldn't need to understand how the agent chooses tools or manages its internal execution flow.&lt;/p&gt;

&lt;p&gt;It should interact with a clear HTTP interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Give the agent a real tool
&lt;/h2&gt;

&lt;p&gt;An agent becomes more interesting when it can do something beyond generating text.&lt;/p&gt;

&lt;p&gt;In this example, the agent uses a weather tool backed by Open-Meteo.&lt;/p&gt;

&lt;p&gt;That introduces a realistic execution path:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user asks a weather-related question.&lt;/li&gt;
&lt;li&gt;The model determines whether it needs the tool.&lt;/li&gt;
&lt;li&gt;The tool requests external weather information.&lt;/li&gt;
&lt;li&gt;The result returns to the agent.&lt;/li&gt;
&lt;li&gt;The agent uses the result to answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a useful foundation for more advanced agents that interact with APIs, databases, and business systems.&lt;/p&gt;

&lt;p&gt;It also introduces concerns that don't exist in a simple LLM completion: network failures, tool errors, latency, and retries.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Expose the agent through FastAPI
&lt;/h2&gt;

&lt;p&gt;The next step is making the agent accessible through an HTTP API.&lt;/p&gt;

&lt;p&gt;The example demonstrates two response patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regular JSON responses&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The client sends a request and waits for the agent's result.&lt;/p&gt;

&lt;p&gt;This approach is appropriate for simple integrations where intermediate execution updates aren't necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Streaming responses&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The client receives updates while the request is being processed.&lt;/p&gt;

&lt;p&gt;This is useful when agent execution involves multiple operations and the user would otherwise wait without feedback.&lt;/p&gt;

&lt;p&gt;Both patterns can be built around the same agent architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Why use Server-Sent Events?
&lt;/h2&gt;

&lt;p&gt;Server-Sent Events provide a way to deliver a stream of updates over an HTTP response.&lt;/p&gt;

&lt;p&gt;Instead of waiting for one final response, the client can process events as they arrive.&lt;/p&gt;

&lt;p&gt;A simplified SSE message looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;event: message
data: {"content":"Processing your request..."}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above illustrates SSE formatting, not the exact event contract of the repository.&lt;/p&gt;

&lt;p&gt;For AI applications, streaming can improve the experience by making long-running operations more visible.&lt;/p&gt;

&lt;p&gt;However, streaming also introduces engineering considerations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happens when the client disconnects?&lt;/li&gt;
&lt;li&gt;How are errors communicated after the stream begins?&lt;/li&gt;
&lt;li&gt;How does the client recognize completion?&lt;/li&gt;
&lt;li&gt;What happens if a tool fails halfway through execution?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions matter when moving from a working demonstration to a reliable service.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Keep the agent separate from the API
&lt;/h2&gt;

&lt;p&gt;One important design principle is to avoid mixing agent orchestration with HTTP transport logic.&lt;/p&gt;

&lt;p&gt;The agent should own its execution flow and tool interactions.&lt;/p&gt;

&lt;p&gt;The FastAPI layer should handle requests, responses, and streaming transport.&lt;/p&gt;

&lt;p&gt;That separation makes it easier to test the agent independently, evolve the API, and introduce additional clients later.&lt;/p&gt;

&lt;p&gt;It also creates a clearer boundary for future capabilities such as authentication, persistence, and observability.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What this example does not solve yet
&lt;/h2&gt;

&lt;p&gt;A working agent API is not automatically production-ready.&lt;/p&gt;

&lt;p&gt;Before using this architecture for critical workflows, several additional concerns need attention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Persistence and checkpointing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Long-running or multi-step agents may need to recover execution state after interruptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retries and idempotency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Retrying a failed operation can be dangerous when tools modify external systems.&lt;/p&gt;

&lt;p&gt;For example, retrying a payment operation must not charge the same customer twice.&lt;/p&gt;

&lt;p&gt;Checkpointing alone doesn't guarantee idempotency. External side effects need their own protection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Observability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Production systems need visibility into agent execution, LLM calls, tool inputs and outputs, errors, and latency.&lt;/p&gt;

&lt;p&gt;LangSmith is one option for tracing LangGraph applications at the execution, node, and tool-call levels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security and operational controls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Authentication, rate limiting, secrets management, structured logging, and deployment configuration need to be addressed according to the environment.&lt;/p&gt;

&lt;p&gt;These aren't reasons to avoid building a small example. They're reasons to distinguish a working foundation from a complete production system.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Run the example yourself
&lt;/h2&gt;

&lt;p&gt;The public repository contains the implementation and setup instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/salada-dados/langgraph-fastapi-example" rel="noopener noreferrer"&gt;https://github.com/salada-dados/langgraph-fastapi-example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start with the README, run the example locally, and inspect how the agent, tool integration, FastAPI endpoints, and SSE streaming fit together.&lt;/p&gt;

&lt;p&gt;The most useful next exercise is to replace the weather tool with an API relevant to your own application.&lt;/p&gt;

&lt;p&gt;That helps expose the operational questions you'll eventually need to solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. From a working example to production
&lt;/h2&gt;

&lt;p&gt;I'm also building a &lt;strong&gt;Production LangGraph + FastAPI Starter&lt;/strong&gt;, focused on reducing the repetitive engineering work involved in taking an agent beyond a local demonstration.&lt;/p&gt;

&lt;p&gt;The goal is to provide a production-oriented starting point rather than claim that every deployment concern can be solved by a template.&lt;/p&gt;

&lt;p&gt;If you're working on an agent and running into challenges with persistence, retries, observability, or deployment, I'd be interested in hearing what's been hardest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interested in the production-oriented Starter?&lt;/strong&gt; &lt;a href="https://saladadedados.com/en/products/ai-agent-production-kit?utm_source=github&amp;amp;utm_medium=referral&amp;amp;utm_campaign=ai-agent-production-kit" rel="noopener noreferrer"&gt;Join the Early Access list&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the original tutorial:&lt;/strong&gt; &lt;a href="https://saladadedados.com/en/blog/langgraph-fastapi-sse" rel="noopener noreferrer"&gt;https://saladadedados.com/en/blog/langgraph-fastapi-sse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explore the source code:&lt;/strong&gt; &lt;a href="https://github.com/salada-dados/langgraph-fastapi-example" rel="noopener noreferrer"&gt;https://github.com/salada-dados/langgraph-fastapi-example&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What has been the hardest part of moving your LangGraph agent from a local prototype to a real application?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
