Table of Contents
- 1.1 Introduction to the integration of APIs in LangGraph
- 1.2 Connect external data sources
- 1.3 Combine API responses with an LLM
- 1.4 Demo: Workflow API in LangGraph
- 2.1 Introduction to LangGraph deployment
- 2.2 The LangGraph server
- 2.3 Scaling workflows for multiple users
- 2.4 Demo: Deployment of LangGraph workflows
1. Connecting APIs and LLMs in LangGraph
1.1 Introduction to API integration in LangGraph
Let’s look at how to deploy LangGraph applications, including some ways to integrate third-party APIs with large language model responses. To get started, let’s first do a brief introduction to understand how to integrate APIs into LangGraph.
Why combine APIs and LLMs?
When we combine APIs with Large Language Models (LLM), we unlock workflows that are both intelligent and dynamic. Instead of relying solely on the model’s internal knowledge, APIs allow the LLM to access external data in real time, such as:
- Weather updates
- CRM (Customer Relationship Management) records
- Financial information
This means that responses can adapt to current conditions and the specific context of each user. This allows us to move from simple static text generation to interactive, data-driven solutions.
Key benefits of using third-party APIs
Here are the main advantages of integrating third-party APIs into LangGraph:
-
Access to up-to-date data: APIs allow LLMs to access up-to-date data instead of relying solely on static training information, making their responses more accurate and timely.
-
Real-time external data integration: By connecting third-party APIs, LangGraph can extract live data from external systems, enabling your workflows to make smarter, contextually relevant decisions.
-
Adaptive Workflows: By combining LLM reasoning with real-time API data, workflows become more adaptive, automating complex decisions with deeper contextual understanding.
-
Versatility of use: Whether you use weather APIs for contextual insights, CRM data for customer personalization, or financial APIs for market updates, integrating APIs expands what your AI can accomplish.
-
Continuous learning from external signals: The result is a system capable of continuously learning from external signals, providing more relevant data-driven results in real time.
Four common use cases
Here are the four common use cases where APIs and LLMs can work together:
-
Weather: You can extract live weather data from an API to provide location-specific insights or recommendations through the LLM.
-
CRM: You can integrate CRM data so that chatbots can give personalized responses based on the customer profile.
-
Finance: You can connect financial APIs to obtain real-time stock market data, allowing LLM to provide accurate and up-to-date market analysis.
-
General data: More generally, any API exposing structured data can be combined with an LLM to enrich responses with dynamic context.
1.2 Connect external data sources
Now let’s look at ways to connect LangGraph with external data sources.
API connection methods
In LangGraph, you can connect to external APIs using several approaches:
- REST Endpoints (Representational State Transfer)
- GraphQL Endpoints
The platform provides built-in connectors that facilitate the extraction of data from common services. You can also create custom nodes (nodes) for APIs specific to your workflow. These connections allow your LLM workflows to interact with real-time data, making your application smarter and more dynamic.
Best practices for retrieving and managing API data
Here are the essential steps and recommendations for working with API data in LangGraph:
-
Send requests correctly: Start by sending requests to the API endpoint using the appropriate HTTP method. This is how you collect the data needed for your workflow.
-
Parse JSON responses: Most APIs return data in JSON format. Learn how to read and extract the required fields to use them effectively in LangGraph.
-
Format data for LLM nodes: Once you get the answer, transmit it in the format that the LLM nodes can understand. This ensures smooth integration with your workflow.
-
Handle errors: APIs may fail or return unexpected results. Implement error handling to capture these issues and prevent workflow interruptions.
-
Secure API keys: Always store API keys (API keys) and authentication tokens (authentication tokens) securely. Never hard code them into your workflow to protect sensitive information.
-
Log requests and responses: Keep a log (log) of API requests and responses. This makes it easier to debug and monitor workflow performance.
1.3 Combine API responses with an LLM
Now let’s see how to combine API responses with large language models.
Map API data to LLM prompts
The process of combining API data with an LLM follows these steps:
-
Transform raw data into prompts: Start by taking raw data from an API and use it to generate meaningful prompts (prompts) that the LLM can understand and act on.
-
Extract only relevant fields: Not all API data is useful. Focus on extracting only those fields that are relevant to your workflow or the question you want the LLM to answer.
-
Manipulate data in LangGraph nodes: LangGraph nodes allow you to manipulate API data — formatting, filtering, or combining values — before sending it as input to the LLM.
-
Handle incomplete or unexpected data: APIs may return incomplete or unexpected data. Set up safeguards in LangGraph to handle these cases without interrupting the workflow.
-
Merge data from multiple APIs: To improve the quality of LLM responses, you can merge data from multiple APIs, giving the model richer context and more precise outputs.
LangGraph nodes as building blocks
Nodes (nodes) are at the heart of LangGraph. Here’s how to understand them:
-
One node = one action: Think of a node as a building block. Each node performs a specific action, such as fetching data or invoking an LLM.
-
Node versatility: Nodes are not limited to a single function. They can retrieve API data, transform it, or pass it to an LLM for smarter outputs.
-
Structure of a node: Each node has inputs that it receives, outputs that it produces, and parameters that you can configure to control its behavior.
-
Data flow: By connecting nodes, you create a flow where data moves seamlessly from one stage to the next.
-
Direct API → LLM integration: You can take API responses and pass them directly to an LLM prompt, enabling dynamic responses in real time.
1.4 Demo: API workflow in LangGraph
This section presents a hands-on demo of implementing an API workflow in LangGraph. The demo notebook is located in the 01/demos.ipynb folder.
Step 1: Installing dependencies
In this first step, we install all the Python packages necessary to build our LangGraph workflow.
langgraph: provides the workflow enginelangchain-openai: allows interaction with OpenAI modelsrequests: allows you to make external API calls (like weather services)
!pip install -U langgraph langchain-openai requests
Step 2: Imports
All necessary modules are imported into the notebook. This includes:
- Typing helpers to define workflow states
- LangGraph classes to build the workflow
- The LLM OpenAI wrapper
- Standard libraries like
requestsandos
Together, these imports provide everything needed to manage state, make API calls, and invoke LLMs.
from typing import TypedDict, Optional
from langgraph.graph import StateGraph, END
from langchain_openai import ChatOpenAI
import requests
import os
Step 3: Configure the OpenAI API key
To use the LLM in our workflow, we must define the OpenAI API key. In a real production environment, keys should be managed in environment variables or secret managers rather than written directly to the notebook. This step initializes the authentication so that LangChain can call the model.
os.environ["OPENAI_API_KEY"] = "votre_clé_ici" # remplacer par votre clé ou utiliser une variable d'environnement
Security Note: Never hardcode an API key into source code. Always use environment variables or a secrets manager like AWS Secrets Manager or Azure Key Vault.
Step 4: Define the state schema (state schema)
LangGraph workflows rely on a shared state object that is passed from one node to another. Here we define a TypedDict called WeatherState, which contains all the fields that will pass through the workflow:
city: the input cityweather_info: weather information retrieved from the APIsummary: the summary generated by the LLM
Each node will update part of this state.
class WeatherState(TypedDict, total=False):
city: str
weather_info: Optional[str]
summary: Optional[str]
Step 5: Define Workflow Nodes
We implement the two workflow nodes that perform the work in our pipeline:
fetch_weather: Fetch real-time weather data from a public API, display incoming status for transparency, call the API, insert temperature into the status, and display the updated status.summarize_weather: receives the enriched state, sends a prompt to an OpenAI model and adds the summary generated by the LLM in the workflow state.
Both nodes provide detailed printouts to observe pipeline behavior step by step.
def fetch_weather(state: WeatherState) -> WeatherState:
print("📌 Step 1: Inside `fetch_weather()`")
print("State received:", state)
city = state.get("city", "New York")
print(f"🔹 Fetching weather for {city}...")
url = "https://api.open-meteo.com/v1/forecast?latitude=40.7&longitude=-74¤t_weather=true"
response = requests.get(url, timeout=10)
data = response.json()
temp = data["current_weather"]["temperature"]
state["weather_info"] = f"The current temperature in {city} is {temp}°C."
print("📤 Updated State:", state, "\n")
return state
def summarize_weather(state: WeatherState) -> WeatherState:
print("\n📌 Step 2: Inside `summarize_weather()`")
print("State received:", state)
llm = ChatOpenAI(model="gpt-4o-mini")
prompt = f"Summarize this weather update: {state['weather_info']}"
print("🧠 Sending prompt to LLM:", prompt)
response = llm.invoke(prompt)
state["summary"] = response.content
print("📤 Updated State:", state, "\n")
return state
Step 6: Build the LangGraph workflow
We assemble the workflow by creating a StateGraph, registering each node and defining the flow between them. The fetch_weather node feeds summarize_weather, which then connects to the built-in end state (END). We also define fetch_weather as an entry point, so that the workflow always starts by fetching the API data.
workflow = StateGraph(WeatherState)
workflow.add_node("fetch_weather", fetch_weather)
workflow.add_node("summarize_weather", summarize_weather)
workflow.add_edge("fetch_weather", "summarize_weather")
workflow.add_edge("summarize_weather", END)
workflow.set_entry_point("fetch_weather")
Inspection before compilation
Before compiling the workflow, you can inspect the graph to verify that the nodes, edges (edges) and entry points are correctly configured:
print("📌 Pre-Compile Graph Inspection\n")
print("Nodes:")
print(workflow.nodes, "\n")
print("Edges:")
print(workflow.edges, "\n")
# Extraire le point d'entrée depuis les arêtes
entry_point = [to_node for from_node, to_node in workflow.edges if from_node == "__start__"][0]
print("Entry Point:")
print(entry_point, "\n")
Expected output:
📌 Pre-Compile Graph Inspection
Nodes:
{'fetch_weather': StateNodeSpec(...), 'summarize_weather': StateNodeSpec(...)}
Edges:
{('summarize_weather', '__end__'), ('fetch_weather', 'summarize_weather'), ('__start__', 'fetch_weather')}
Entry Point:
fetch_weather
Step 7: Compile and visualize the workflow
Compiling the workflow converts it to an executable form. LangGraph also provides built-in visualization support via a Mermaid diagram that shows the structure of the workflow.
# Compiler le graphe en une application exécutable
app = workflow.compile()
# Visualiser le graphe
from IPython.display import Image
Image(app.get_graph().draw_mermaid_png(
max_retries=5,
retry_delay=2.0
))
The generated diagram clearly shows the sequence of operations: __start__ → fetch_weather → summarize_weather → __end__. This helps readers visually understand the pipeline flow.
Step 8: Run the workflow
With the compiled workflow, we can now execute it by providing an initial state including the city name. As the workflow executes, each node displays its state transitions, allowing us to observe the weather data being retrieved and summarized by the LLM in real time.
initial_state = {"city": "New York"}
result = app.invoke(initial_state)
print("\n🔹 Weather Info:", result["weather_info"], "\n")
print("🔹 LLM Summary:", result["summary"], "\n")
Example output:
📌 Step 1: Inside `fetch_weather()`
State received: {'city': 'New York'}
🔹 Fetching weather for New York...
📤 Updated State: {'city': 'New York', 'weather_info': 'The current temperature in New York is 1.9°C.'}
📌 Step 2: Inside `summarize_weather()`
State received: {'city': 'New York', 'weather_info': 'The current temperature in New York is 1.9°C.'}
🧠 Sending prompt to LLM: Summarize this weather update: The current temperature in New York is 1.9°C.
📤 Updated State: {'city': 'New York', 'weather_info': 'The current temperature in New York is 1.9°C.', 'summary': 'The current temperature in New York is 1.9°C.'}
🔹 Weather Info: The current temperature in New York is 1.9°C.
🔹 LLM Summary: The current temperature in New York is 1.9°C.
Finally, we display the output stored in the workflow state after the execution has finished. This gives us a clear view of the final result of the LangGraph pipeline.
2. Deploy and scale LangGraph
2.1 Introduction to LangGraph deployment
Let’s look at the different ways to deploy and scale applications with LangGraph. We will first explore the introduction and some basic concepts of LangGraph deployment.
Basic components of LangGraph
Here are the fundamental components that constitute a LangGraph architecture:
-
The LangGraph Server (LangGraph Server): This is the central hub where all workflows run. It exposes APIs for external applications, manages the execution of workflows, manages concurrency, and ensures efficient allocation of resources.
-
*Nodes: These are individual steps in a workflow, such as data processing, model inference, or API calls. You connect nodes to form a complete workflow, defining the order and logic of execution.
-
The graph (Graph): It defines how the nodes are connected and executed. It supports branching, loops and parallel tasks, allowing you to design complex workflows flexibly.
-
Clients or SDKs: They allow developers to interact with the server. They can submit jobs, retrieve results, and integrate workflows in Python, JavaScript, or other supported environments.
-
Monitoring and logging: Provides insights into workflow execution, performance and errors, making it easier to debug and optimize workflows.
-
*Deployment layer: Uses Docker or Kubernetes to scale LangGraph for multiple users. It manages load balancing, resource management, and ensures that workflows run reliably and at scale.
Key Challenges of LangGraph Deployment
Before deploying LangGraph, it is important to understand some key challenges that can impact a successful deployment:
-
Dependency Management: When deploying LangGraph, maintaining consistent dependencies between development, staging and production environments is essential. Mismatched library versions or missing packages can cause unexpected behavior. Using containers or environment managers helps ensure reproducibility and smooth deployments.
-
Scalability and Reliability: As more users access LangGraph workflows, system reliability becomes critical. Workflows must handle varying loads without failing. The integration of retries, caching and autoscaling ensures that performance remains consistent even under heavy use.
-
API and network configuration: Proper configuration of APIs and network ensures smooth communication between the LangGraph server, clients and external services. Misconfigured endpoints, firewalls, or authentication tokens often lead to connection errors. Testing connectivity early prevents deployment delays.
-
Version management: LangGraph workflows evolve over time. Versioning helps manage updates without breaking existing features. Tagging workflow versions and maintaining backward compatibility ensures stability when introducing new features or enhancements.
-
Observability: In distributed deployments, tracing issues can be difficult. Centralized logging and monitoring tools help track workflow performance and quickly identify failures. Having clear observability pipelines in place speeds up debugging.
Key Scaling Considerations
Here are key considerations to help LangGraph manage growing workloads and multiple concurrent users:
-
Traffic Distribution: To handle multiple competing requests efficiently, distribute traffic across multiple LangGraph server instances. This prevents single server overload and ensures smooth and responsive performance for all users.
-
Session consistency: When scaling across multiple servers, maintaining session consistency is critical. Use shared session stores or stateless workflows so users can seamlessly continue their interactions regardless of which server instance is handling their requests.
-
Resource allocation: Proper allocation of CPU, memory, and GPU resources helps prevent bottlenecks in workflows. Set resource limits for each container or service to optimize performance and minimize costs.
-
Redundancy and automatic recovery: Implement redundancy and automatic recovery mechanisms to handle node failures gracefully. Monitoring and restart policies ensure that workflows remain available even during system disruptions.
-
Horizontal Scalability: Increase system capacity by adding more server instances rather than scaling up existing instances. This approach provides better flexibility, easier management and greater cost efficiency as demand increases.
2.2 The LangGraph server
LangGraph Server for API-based workflows
Let’s explore how LangGraph Server enables API-driven workflows and simplifies deployment with a unified scalable architecture.
The LangGraph server allows developers to transform workflows into accessible APIs. This makes it easy to integrate LangGraph-based logic into existing systems or front-end applications without manual execution or complex configuration.
The server acts as a central control point that manages the execution of workflows, tracks state, and efficiently coordinates multiple components. It ensures consistency and scalability across user requests and workflow executions.
Connect and verify LangGraph server
Here are the steps to connect to the LangGraph server and ensure its API endpoints are working properly:
-
Launch the server: Start by launching the LangGraph server on your local machine or in a remote environment. Make sure the server environment meets all dependencies and configurations so that it can function properly.
-
Check activity on port: Once launched, verify that the server is active on the assigned port. This ensures that the server is accessible and ready to process incoming API requests.
-
Test endpoints: Use tools like
cURLor Postman to send requests to your server endpoints. This helps confirm that endpoints are reachable and responding correctly. -
Validate Responses: Examine the API responses for correct HTTP status codes and validate the returned data payload. Accurate responses indicate that your server logic is working as expected.
-
Troubleshoot connectivity issues: If you experience connection failures or incorrect responses, check the server logs, firewall settings, or endpoint configurations. Systematic debugging helps quickly resolve common connectivity issues.
2.3 Scaling workflows for multiple users
Resource management and concurrency
Scaling workflows is essential when serving multiple users or processing large volumes of queries in LangGraph. By effectively managing concurrency and allocating resources appropriately, you can ensure that every workflow runs reliably without delays.
Policies like load balancing, horizontal scaling, and prioritization of critical tasks help maintain performance and responsiveness.
LangGraph Workflow Scaling Strategies
Here are the main strategies for scaling LangGraph workflows:
-
Multi-instance deployment with load balancer: To manage more users, you can deploy several instances of the LangGraph server behind a load balancer (load balancer). This distributes API requests evenly, ensuring that no single server becomes a bottleneck.
-
Parallel tasks: Large workflows can be broken down into smaller independent tasks. Running these tasks in parallel reduces overall execution time and improves system responsiveness.
-
Queues and asynchronous execution: We must control the number of workflows that execute simultaneously on each server. Using queues or asynchronous execution prevents overloading and keeps critical tasks running.
-
Autoscaling with Docker or Kubernetes: Using tools like Docker or Kubernetes, you can automatically add or remove server instances depending on the workload. This ensures that resources match demand without manual intervention.
-
Result caching: Frequently calculated workflow results can be cached. This avoids repeating costly calculations, speeds up response times and reduces server load.
-
Proactive Monitoring: By tracking execution times, errors, and resource utilization, one can identify bottlenecks and proactively optimize scaling and concurrency management strategies.
2.4 Demo: Deploying LangGraph workflows
This section provides a hands-on demo of deploying LangGraph workflows. The demo notebook is located in the 02/demos.ipynb folder. This demo uses FastAPI and Uvicorn to create an API server around the LangGraph workflow.
Step 1: Installation and configuration
We install all the Python packages required for this demo:
langgraph: to build the workflowfastapi: to create the API serveruvicorn: to run the ASGI servernest_asyncio: to enable asynchronous execution in Jupyter notebooksrequests: for API callspsutil: to monitor system resourceslangchain_openai: to use GPT models
!pip install langgraph fastapi uvicorn nest_asyncio requests psutil langchain_openai
Step 2: Define a simple LangGraph workflow — Imports
We import all the necessary libraries. We also configure the OpenAI API key to be able to call the LLM later.
# Imports
from langgraph.graph import StateGraph
from pydantic import BaseModel
from typing import TypedDict, Optional
from langchain_openai import ChatOpenAI
import nest_asyncio, uvicorn, threading, time, psutil, traceback
import requests
import os
os.environ["OPENAI_API_KEY"] = "KEY" # remplacer par votre clé ou utiliser une variable d'environnement
Step 3: Define the state schema
We define the data structure that our workflow will manage. WeatherState has optional fields for city, weather information and summary. This ensures consistent data passing between workflow nodes.
class WeatherState(TypedDict, total=False):
city: str
weather_info: Optional[str]
summary: Optional[str]
Step 4: Define Workflow Nodes
We define two key functions for our workflow:
fetch_weather: fetch real-time weather data from a public APIsummarize_weather: sends this data to a GPT model to generate a human-readable summary
The print statements in the code allow us to see the state of the data at each step.
def fetch_weather(state: WeatherState) -> WeatherState:
print("📌 Step 1: Inside `fetch_weather()`")
print("State received:", state)
city = state.get("city", "New York")
print(f"🔹 Fetching weather for {city}...")
url = "https://api.open-meteo.com/v1/forecast?latitude=40.7&longitude=-74¤t_weather=true"
response = requests.get(url, timeout=10)
data = response.json()
temp = data["current_weather"]["temperature"]
state["weather_info"] = f"The current temperature in {city} is {temp}°C."
print("📤 Updated State:", state, "\n")
return state
def summarize_weather(state: WeatherState) -> WeatherState:
print("\n📌 Step 2: Inside `summarize_weather()`")
print("State received:", state)
llm = ChatOpenAI(model="gpt-4o-mini")
prompt = f"Summarize this weather update: {state['weather_info']}"
print("🧠 Sending prompt to LLM:", prompt)
response = llm.invoke(prompt)
state["summary"] = response.content
print("📤 Updated State:", state, "\n")
return state
Step 5: Build the LangGraph workflow
We build the workflow by adding the nodes and defining the connections (edges) between them.
# Construire le workflow
workflow = StateGraph(WeatherState)
workflow.add_node("fetch_weather", fetch_weather)
workflow.add_node("summarize_weather", summarize_weather)
workflow.add_edge("fetch_weather", "summarize_weather")
workflow.set_entry_point("fetch_weather")
Step 6: Compilation — Pre-compilation inspection
Before compiling the workflow, we inspect the graph to verify that the nodes, edges and entry points are correctly initialized from the print instructions.
print("📌 Pre-Compile Graph Inspection\n")
print("Nodes:")
print(workflow.nodes, "\n")
print("Edges:")
print(workflow.edges, "\n")
# Extraire le point d'entrée depuis les arêtes
entry_point = [to_node for from_node, to_node in workflow.edges if from_node == "__start__"][0]
print("Entry Point:")
print(entry_point, "\n")
Expected output:
📌 Pre-Compile Graph Inspection
Nodes:
{'fetch_weather': StateNodeSpec(...), 'summarize_weather': StateNodeSpec(...)}
Edges:
{('fetch_weather', 'summarize_weather'), ('__start__', 'fetch_weather')}
Entry Point:
fetch_weather
Step 6 (continued): Compile the workflow
# Compiler le graphe en une application exécutable
compiled_graph = workflow.compile()
Step 7: Wrap the application with FastAPI
We encapsulate the workflow in a FastAPI server. The /run endpoint will run the workflow when called. We also define a /shutdown endpoint to gracefully shut down the server if necessary.
# Wrapper FastAPI
from fastapi import FastAPI
app = FastAPI()
@app.post("/run")
async def run_workflow():
try:
# Passer l'état initial directement
initial_state = {"city": "New York"} # MUST pass as input
result = compiled_graph.invoke(initial_state)
return result
except Exception as e:
import traceback
print("Workflow Error:", e)
traceback.print_exc()
return {"error": str(e)}
# Endpoint d'arrêt optionnel
@app.post("/shutdown")
async def shutdown():
import os, signal
os.kill(os.getpid(), signal.SIGINT)
return {"message": "Server shutting down"}
Step 8: Start LangGraph Server (locally for demo)
We are running the FastAPI server in a background thread so that we can continue to use the notebook while it is running. Once started, the server listens on port 8000.
# Exécuter le serveur dans un thread d'arrière-plan
def run_server():
uvicorn.run(app, host="127.0.0.1", port=8000)
thread = threading.Thread(target=run_server, daemon=True)
thread.start()
print("LangGraph Server running in the background on port 8000!")
Expected output:
LangGraph Server running in the background on port 8000!
INFO: Started server process [3364]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Step 9: Test API endpoints
We test the /run endpoint by sending a POST request with our input payload, and we display the response.
# Tester l'API
import requests, time
url = "http://127.0.0.1:8000/run"
payload = {"name": "Yasir"}
# Attendre que le serveur démarre
timeout = 10 # secondes
start = time.time()
while True:
try:
response = requests.post(url, json=payload)
break
except requests.exceptions.ConnectionError:
if time.time() - start > timeout:
raise Exception("Server did not start in time")
time.sleep(0.5) # attendre avant de réessayer
print("Status Code:", response.status_code)
try:
print("Response:", response.json())
except Exception:
print("Raw response text:", response.text)
Expected output:
Status Code: 200
Response: {
'city': 'New York',
'weather_info': 'The current temperature in New York is 4.5°C.',
'summary': 'The current temperature in New York is 4.5°C.'
}
We also see in the workflow logs the state transitions at each step:
📌 Step 1: Inside `fetch_weather()`
State received: {'city': 'New York'}
🔹 Fetching weather for New York...
📤 Updated State: {'city': 'New York', 'weather_info': 'The current temperature in New York is 4.5°C.'}
📌 Step 2: Inside `summarize_weather()`
State received: {'city': 'New York', 'weather_info': 'The current temperature in New York is 4.5°C.'}
🧠 Sending prompt to LLM: Summarize this weather update: The current temperature in New York is 4.5°C.
📤 Updated State: {'city': 'New York', 'weather_info': 'The current temperature in New York is 4.5°C.', 'summary': 'The current temperature in New York is 4.5°C.'}
INFO: 127.0.0.1:57950 - "POST /run HTTP/1.1" 200 OK
Step 10: Monitor CPU and Memory
Finally, we monitor CPU and memory usage to understand the impact on resources of workflow execution. We display the metrics before and after execution.
print("CPU Usage:", psutil.cpu_percent(), "%")
print("Memory Usage:", psutil.virtual_memory().percent, "%")
Example output:
CPU Usage: 0.9 %
Memory Usage: 9.1 %
This monitoring allows us to understand the resource footprint of our LangGraph application during real execution.
3. Summary
This training covers the fundamental aspects of deploying LangGraph applications, from the integration of third-party APIs to scalable deployment with FastAPI and Uvicorn.
Key Takeaways
Module 1 — API integration:
- APIs allow LLMs to access real-time data (weather, CRM, finance)
- LangGraph supports REST and GraphQL connections
- Nodes are building blocks that each perform a specific action
- State (
TypedDict) is shared between all workflow nodes - API keys should never be hardcoded — use environment variables
- Always implement error handling for API calls
Module 2 — Deployment and scaling:
- LangGraph server exposes APIs to integrate logic into external systems
- FastAPI + Uvicorn allow you to quickly create an API server around a LangGraph workflow
- Horizontal scaling with Docker/Kubernetes helps manage load growth
- Scalability strategies include: load balancing, parallel tasks, asynchronous queues, caching
- Monitoring with
psutilallows you to measure the impact on system resources - Observability (centralized logging, monitoring) is essential in distributed deployments
Overall architecture
Utilisateur / Client
↓
Load Balancer
↓
┌─────────────────────────────────┐
│ Serveur LangGraph │
│ (FastAPI + Uvicorn sur port 8000)│
│ │
│ POST /run → workflow.invoke() │
│ │
│ StateGraph: │
│ fetch_weather → summarize_weather │
└─────────────────────────────────┘
↓ ↓
API Externe OpenAI API
(Open-Meteo) (GPT-4o-mini)
This architecture demonstrates how LangGraph can be deployed as a microservice (microservice) accessible via HTTP, capable of orchestrating calls to external APIs and LLMs, all in a robust and scalable workflow.
Search Terms
deploying · langgraph · applications · ai · agents · orchestration · artificial · intelligence · generative · workflow · api · define · server · apis · data · nodes · scaling · workflows · combine · compilation · compile · connect · deployment · imports