Use this file to discover all available pages before exploring further.
You can invoke LangSmith Fleet agents from your applications using the LangGraph SDK or the REST API. Fleet agents run on Agent Server, so you can use the same API methods as any other LangSmith deployment.The REST API lets you call your agent from any language or platform that supports HTTP requests.
To authenticate with your agent’s Fleet deployment, provide a LangSmith Personal Access Token (PAT) to the api_key argument when instantiating the LangGraph SDK client, or via the X-API-Key header. If using X-API-Key, you must also set the X-Auth-Scheme header to langsmith-api-key.If the PAT you pass is not tied to the owner of the agent, your request will be rejected with a 404 Not Found error.If the agent you’re trying to invoke is a and you’re not the owner, you can perform all the same operations as you would in the UI (read-only).
In the LangSmith UI, navigate to your agent’s inbox.
Next to the agent name, click the Edit Agent icon.
Click the Settings icon in the top right corner.
Click View code snippets to see pre-populated values for your agent.
Copy the code below and replace agent_id and api_url with the values from your agent’s code snippets.Create a .env file in your project root with your Personal Access Token:
Use a Personal Access Token (PAT) tied to your LangSmith account. Set the X-Auth-Scheme header to langsmith-api-key for authentication. If you implemented custom authentication, pass the user’s token in headers so the agent can use user-scoped tools. See Add custom authentication.
The examples below show how to send a message to your agent and receive a response. You can use either a stateless run (no thread, no conversation history) or a stateful run (with a thread to maintain conversation history across multiple turns).
A stateless run sends a single request and returns the full response. No conversation history is persisted. This is the simplest way to call your agent:
To stream the response as it is generated rather than waiting for the full result, use the streaming endpoint:
Python
TypeScript
cURL
async for chunk in client.runs.stream( None, agent_id, input={ "messages": [ {"role": "user", "content": "What can you help me with?"} ] }, stream_mode="updates",): if chunk.data and "run_id" not in chunk.data: print(chunk.data)
const streamResponse = client.runs.stream( null, agentId, { input: { messages: [ { role: "user", content: "What can you help me with?" } ] }, streamMode: "updates" });for await (const chunk of streamResponse) { if (chunk.data && !("run_id" in chunk.data)) { console.log(chunk.data); }}
curl --request POST \ --url "<AGENT-BUILDER-URL>.us.langgraph.app/runs/stream" \ --header 'Content-Type: application/json' \ --header 'X-Api-Key: your-personal-access-token' \ --header 'X-Auth-Scheme: langsmith-api-key' \ --data '{ "assistant_id": "your-agent-id", "input": { "messages": [ { "role": "user", "content": "What can you help me with?" } ] }, "stream_mode": [ "updates" ] }'
To maintain conversation history across multiple interactions, first create a thread and then run your agent on it. Each subsequent run on the same thread has access to the full message history:
Python
TypeScript
cURL
import osfrom dotenv import load_dotenvfrom langgraph_sdk.client import get_clientload_dotenv()agent_id = "your-agent-id"api_key = os.getenv("LANGGRAPH_API_KEY")api_url = "<AGENT-BUILDER-URL>.us.langgraph.app"client = get_client( url=api_url, api_key=api_key, headers={ "X-Auth-Scheme": "langsmith-api-key", },)thread = await client.threads.create()async for chunk in client.runs.stream( thread["thread_id"], agent_id, input={ "messages": [ {"role": "user", "content": "Hi, my name is Alice."} ] }, stream_mode="updates",): if chunk.data and "run_id" not in chunk.data: print(chunk.data)async for chunk in client.runs.stream( thread["thread_id"], agent_id, input={ "messages": [ {"role": "user", "content": "What is my name?"} ] }, stream_mode="updates",): if chunk.data and "run_id" not in chunk.data: print(chunk.data)
import "dotenv/config";import { Client } from "@langchain/langgraph-sdk";const agentId = "your-agent-id";const apiKey = process.env.LANGGRAPH_API_KEY;const apiUrl = "<AGENT-BUILDER-URL>.us.langgraph.app";const client = new Client({ apiUrl, apiKey, defaultHeaders: { "X-Auth-Scheme": "langsmith-api-key", },});const thread = await client.threads.create();let streamResponse = client.runs.stream( thread["thread_id"], agentId, { input: { messages: [ { role: "user", content: "Hi, my name is Alice." } ] }, streamMode: "updates" });for await (const chunk of streamResponse) { if (chunk.data && !("run_id" in chunk.data)) { console.log(chunk.data); }}streamResponse = client.runs.stream( thread["thread_id"], agentId, { input: { messages: [ { role: "user", content: "What is my name?" } ] }, streamMode: "updates" });for await (const chunk of streamResponse) { if (chunk.data && !("run_id" in chunk.data)) { console.log(chunk.data); }}