Skip to main content
There are two main ways to use Fleet agents programmatically:
  • Call from code: Invoke your agent remotely via the LangGraph SDK or REST API, without downloading anything.
  • Export to code: Download your agent’s configuration and run it locally as a self-contained Python project using the fleet-deepagents-export package.

Call from code

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.

Prerequisites

Authentication

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).

1. Get the agent ID and URL

To get your agent’s agent_id and api_url:
  1. In the LangSmith UI, open your agent.
  2. In the sidebar, expand the Advanced settings drawer.
  3. Under Developer, 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:
.env

2. Fetch agent configuration

Verify your connection by fetching your agent’s configuration:
Use a Personal Access Token (PAT) tied to your LangSmith account. Set the X-Auth-Scheme header to langsmith-api-key for authentication.

3. Invoke agent

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).

Stateless run

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:

Stateless streaming run

To stream the response as it is generated rather than waiting for the full result, use the streaming endpoint:

Stateful run with a thread

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:

REST API reference

The table below summarizes the key endpoints. Replace <API_URL> with your agent’s deployment URL. All endpoints require the following headers: For the full API specification, see the Agent Server API reference.

Export to code

The Export to code feature lets you download your Fleet agent as a self-contained Python project and run it locally. This is useful when you want to:
  • Run your agent in your own infrastructure without calling the Fleet API
  • Extend or customize the agent beyond what the Fleet UI supports (add custom tools, middleware, or skills)
  • Inspect or version-control the full agent implementation
  • Use LangGraph Studio for local development and graph inspection
The fleet-deepagents-export package (GitHub) handles reading the exported configuration and wiring up your agent with MCP tools, subagents, and skills.

Prerequisites

  • Python 3.11+
  • uv (recommended) for dependency management
  • A LangSmith Fleet agent to export

1. Copy the starter project

The starter project at examples/template-agent/ is the recommended starting point. Clone the repo and copy the starter:

2. Export your agent from Fleet

In the LangSmith UI, open your agent and export it as a .zip file. fleet-export-code Then drop the contents into the fleet/ directory of your starter project:
The fleet/ directory contains everything your agent needs:
  • AGENTS.md — system prompt
  • config.json — model configuration and workspace metadata
  • tools.json — MCP server connections
  • subagents/ (optional) — subagent definitions
  • skills/ (optional) — skill instructions

3. Configure your environment

Copy the example env file and fill in the required values:
The three LANGSMITH_*_ID values are in fleet/config.json under metadata. Open that file and copy tenant_id, organization_id, and ls_user_id into your .env:
.env

4. Install dependencies and run

Then choose how to interact with your agent:

5. Customize the agent

The starter separates Fleet-owned files from files you own and can freely edit: Here is the full agent.py from the starter:

Re-exporting

When you export a new version of your agent from Fleet, simply wipe and re-unzip — your customizations are untouched:

Supported model providers

The starter ships with langchain-anthropic, langchain-openai, and langchain-google-genai. For any other provider (e.g. bedrock, fireworks), add the matching langchain-<provider> package to pyproject.toml.

MCP authentication

At startup, each tool’s mcp_server_url is resolved against LangSmith’s MCP server registry:
  • Built-in LangSmith tools (Gmail, Calendar, GitHub) — authenticated via your LANGSMITH_API_KEY.
  • Static-credential servers (auth_type: "headers") — credentials come from the registry record. Requires mcp-servers:invoke permission.
  • OAuth servers (auth_type: "oauth") — bearer token fetched from LangSmith’s OAuth broker. A browser window opens on first run for any per-user server that hasn’t been authorized yet.