Connect Swytchcode to LangGraph: Setup Guide and Example
Connect Swytchcode to LangGraph so your stateful agent workflows can safely call real APIs, with authentication, retries, and policy checks built in.

LangGraph is built for multi-step, stateful agent workflows, the kind that move through several stages and need to keep track of what happened at each one. Swytchcode gives those workflows a safe way to actually call external APIs at any step, without writing custom authentication and retry logic into the graph itself.
Why Connect Swytchcode to LangGraph?
- Keeps execution out of your graph logic. Nodes in your graph can call a tool without also containing the authentication, retry, and validation code for that integration.
- Managed execution. Every tool call runs through Swytchcode's execution pipeline: authentication, retries, idempotency, and policy checks, before it touches a real API.
- Reuses the same project across frameworks. Tools enabled once through the CLI work identically whether they're called from LangGraph, the OpenAI Agents SDK, the Anthropic SDK, or another supported framework.
Step 1: Install the CLI and SDKs
npm install -g swytchcode
npm install @swytchcode/runtimeAlongside langgraph (Python) or @langchain/langgraph (JavaScript/TypeScript), whichever matches your project.
Step 2: Initialize Your Project and Enable a Tool
swy init
swy get <project.library>
swy add method <canonical_id>
swy auth connect <provider>This sets up your project, fetches the integration your workflow needs, enables the specific method, and connects the account it acts on behalf of.
Step 3: Fetch Your Tools in Code
import { Swytchcode, TOOL_USE_INSTRUCTIONS } from "@swytchcode/runtime";
const swx = new Swytchcode(/* LangGraph provider */);
const tools = await swx.tools.get({ toolkits: ["<your-integration>"] });swx.tools.get() returns the schemas for whatever you've enabled with swy add, ready to attach to a node in your graph as a tool-calling step.
The exact provider import and how the fetched tools plug into a LangGraph node or tool-calling edge are worth confirming directly against the LangGraph quickstart, since graph construction is more particular to LangGraph than the other frameworks. The pattern above is the shared shape; that page has the precise, current syntax for wiring it into a graph.
Step 4: Handle Tool Calls in Your Graph
When a node in your graph produces a tool call, route it through Swytchcode:
const result = await swx.handleToolCalls(response);This executes the call through Swytchcode's managed pipeline and returns the result, which your graph then uses to continue to its next state.
Frequently Asked Questions
- Does Swytchcode work with LangGraph's stateful, multi-step workflows? Yes. Tool calls at any step in the graph route through the same Swytchcode execution pipeline, so state can move through several stages while each API call along the way still gets authentication, retries, and policy enforcement.
- Do I need separate Swytchcode setup for each node that calls a tool? No. You set up the project and enable tools once with the CLI; any node in your graph can then fetch and use those same tools.
- Is this the same underlying pattern as the other framework integrations? Yes. Install the matching provider package, fetch tools with
swx.tools.get(), and pass them into the framework's native tool-calling interface, in this case, a LangGraph node.
Where to Go Next
- LangGraph Quickstart: the official, framework-specific setup reference
- Connect Swytchcode to the Anthropic SDK: the same pattern applied to Claude
- Different Ways to Use Swytchcode: how the SDK path compares to the CLI and MCP
Ready to build?
Install the CLI and connect your first API in minutes. Free tier included, no credit card required.
More from the blog
"swy exec" Explained: Inputs, Outputs, and Exit Codes
How swy exec works: the single execution path for running Swytchcode tools, either by canonical ID or by plain-English intent.
How to Set Up Policy Guardrails for AI Agents with Swytchcode
How to use Swytchcode's guard policies to control exactly what an AI agent is allowed to execute, enforced before any request leaves your machine.
tooling.json, manifest.json, and policies.json Explained: Swytchcode's Config Files
What tooling.json, manifest.json, and policies.json actually do in a Swytchcode project, and which CLI commands read and write each one.
