LangGraph Integration
Integrate CoreValue AI Gateway with LangGraph to build multi-agent workflows with access to LLM providers.
Introduction
LangGraph is a framework for building stateful, multi-agent applications with LLMs. The integration with CoreValue AI Gateway is nearly identical to the LangChain integration, with the addition of agent-specific features.
This integration requires only two changes to your existing LangGraph code - updating the base URL and API key. See the LangChain AI Gateway docs for full feature details.
Quick Start
Follow the same setup as LangChain AI Gateway integration, then create your agent:
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { MemorySaver } from "@langchain/langgraph";
const model = new ChatOpenAI({
model: 'gpt-4.1-mini',
apiKey: process.env.COVA_API_KEY,
configuration: {
baseURL: "https://gateway.corevalue.dev/v1",
},
});
const agent = createReactAgent({
llm: model,
tools: yourTools,
checkpointer: new MemorySaver(),
});from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langgraph.checkpoint.memory import MemorySaver
model = ChatOpenAI(
model='gpt-4.1-mini',
api_key=os.getenv('COVA_API_KEY'),
base_url="https://gateway.corevalue.dev/v1",
)
agent = create_react_agent(
model,
tools=your_tools,
checkpointer=MemorySaver(),
)While you're here, why not give us a star on GitHub? It helps us a lot!
Migration Example
Before (Direct Provider)
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const model = new ChatOpenAI({
model: 'gpt-4o-mini',
apiKey: process.env.OPENAI_API_KEY,
});
const agent = createReactAgent({
llm: model,
tools: myTools,
});from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
model = ChatOpenAI(
model='gpt-4o-mini',
api_key=os.getenv('OPENAI_API_KEY'),
)
agent = create_react_agent(model, tools=my_tools)After (CoreValue AI Gateway)
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const model = new ChatOpenAI({
model: 'gpt-4.1-mini', // many models supported
apiKey: process.env.COVA_API_KEY, // Your CoreValue API key
configuration: {
baseURL: "https://gateway.corevalue.dev/v1" // Add this!
},
});
const agent = createReactAgent({
llm: model,
tools: myTools,
});from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
model = ChatOpenAI(
model='gpt-4.1-mini', # many models supported
api_key=os.getenv('COVA_API_KEY'), # Your CoreValue API key
base_url="https://gateway.corevalue.dev/v1" # Add this!
)
agent = create_react_agent(model, tools=my_tools)Adding Custom Headers to Agent Invocations
You can add custom properties when calling your agent with invoke():
import { HumanMessage } from "@langchain/core/messages";
import { v4 as uuidv4 } from 'uuid';
const result = await agent.invoke(
{ messages: [new HumanMessage("What is the weather in San Francisco?")] },
{
options: {
headers: {
// Session tracking via custom properties:
"Cova-Property-Session-Id": uuidv4(),
"Cova-Property-Session-Path": "/weather/query",
"Cova-Property-Query-Type": "weather",
},
},
}
);from langchain_core.messages import HumanMessage
import uuid
result = agent.invoke(
{"messages": [HumanMessage(content="What is the weather in San Francisco?")]},
{
"configurable": {
"headers": {
// Session tracking via custom properties:
"Cova-Property-Session-Id": str(uuid.uuid4()),
"Cova-Property-Session-Path": "/weather/query",
"Cova-Property-Query-Type": "weather",
}
}
}
)Request a CoreValue Integration
Looking for a framework or tool not listed here? Request it here!
Related Documentation
AI Gateway Overview
Learn about CoreValue's AI Gateway features and capabilities
Provider Routing
Configure intelligent routing and automatic failover
Model Registry
Browse all available models and providers
LangChain Integration
Full AI Gateway feature documentation
Sessions
Track multi-turn conversations and agent workflows
Custom Properties
Add metadata to track and filter your requests