Skip to main content
Build, run, and stream Managed Deep Agents from Python, TypeScript, and React. The SDKs wrap the /v1/deepagents API for creating agents, managing threads, streaming runs, registering MCP servers, and building React UIs. For concepts, see the Managed Deep Agents overview. For an end-to-end walkthrough, follow the quickstart.
The SDK packages are in public beta. Method signatures and payload fields can change during the beta.Managed Deep Agents is in private beta, available on LangSmith Cloud in the US region only. Join the waitlist to request access.

Install

uv add managed-deepagents

# or with pip
pip install managed-deepagents
Requirements:
  • Python 3.10 or newer for managed-deepagents.
  • Node.js 22 or newer for @langchain/managed-deepagents.
  • Managed Deep Agents private beta access.
  • A LangSmith API key for a workspace with private beta access.

Configure a client

Set your API key:
export LANGSMITH_API_KEY="<LANGSMITH_API_KEY>"
Both SDKs default to https://api.smith.langchain.com/v1/deepagents. To use a compatible endpoint, set LANGSMITH_ENDPOINT or pass the API URL directly:
from managed_deepagents import Client

client = Client(
    api_key="<LANGSMITH_API_KEY>",
    api_url="https://api.smith.langchain.com/v1/deepagents",
)
Client() and new Client() read LANGSMITH_API_KEY and LANGSMITH_ENDPOINT from the environment, so the remaining examples on this page construct a client with no arguments.

Create an agent

Requests to create an agent can use the same top-level model and backend fields as the Managed Deep Agents CLI. Pass model as an object with an id of {provider}:{model_id}. See supported providers and models.
from managed_deepagents import Client

with Client() as client:
    agent = client.agents.create(
        name="research-assistant",
        description="Research assistant that can search the web and summarize sources.",
        model="openai:gpt-5.5",
        backend={"type": "state"},
        instructions=(
            "You are a careful research assistant. Search for sources, "
            "keep notes, and return concise answers with citations."
        ),
    )

agent_id = agent["id"]
print(f"Agent ID: {agent_id}")
Python methods return dict-like responses, so use agent["id"]. TypeScript methods return typed objects, so use agent.id.

Run and stream

Create a thread before running the agent. Threads preserve conversation and execution state, so you can resume or inspect a run later. Use the id returned when you created the agent.
from managed_deepagents import Client

agent_id = "<agent_id>"

with Client() as client:
    thread = client.threads.create(
        agent_id=agent_id,
        options={
            "test_run": False,
            "skip_memory_write_protection": False,
        },
    )

    for event in client.threads.stream(
        thread["id"],
        agent_id=agent_id,
        messages=[
            {
                "role": "user",
                "content": "Research recent approaches to agent memory and summarize the main trade-offs.",
            }
        ],
        stream_mode=["values", "updates", "messages-tuple"],
        stream_subgraphs=True,
    ):
        print(event.event, event.data)
The options object is optional, and both fields default to false. Set test_run to true to mark the thread as a test run that is filtered out of usage and analytics. By default, skip_memory_write_protection lets the runtime raise a human-in-the-loop interrupt before the agent writes to long-term memory, so you can approve or reject the write. Set it to true to let memory writes proceed immediately, which is useful for headless runs where no human is available to approve the write. In Python, stream directly with client.threads.stream(...). In TypeScript, get a LangGraph client with client.getLangGraphClient(...) and stream with runs.stream(...), which accepts the message list under input. Each event exposes an event type and a data payload. The types you receive depend on stream_mode. For the stream modes and event types, see Stream a run from a thread.

Use React useStream

The TypeScript SDK includes a LangGraph client adapter for @langchain/react. Use getLangGraphClient() so useStream manages thread lifecycle, run submission, and state updates, while the Managed Deep Agents SDK supplies the correct routes, auth headers, and payload format.
Do not ship your LangSmith API key to the browser. new Client() reads LANGSMITH_API_KEY from the environment, so avoid exposing it to your client bundle. In production React apps, route requests through your backend with a custom fetch.
import { Client } from "@langchain/managed-deepagents";
import { useStream } from "@langchain/react";

const agentId = "<agent_id>";

const managedDeepAgents = new Client();

const client = managedDeepAgents.getLangGraphClient({ agentId });

export function ManagedDeepAgentStream() {
  const stream = useStream({
    client,
    assistantId: agentId
  });

  return (
    <section>
      <button
        type="button"
        disabled={stream.isLoading}
        onClick={() => {
          void stream.submit({
            messages: [
              { role: "user", content: "Write a short status update." },
            ],
          });
        }}
      >
        Run agent
      </button>

      {stream.messages.map((message, index) => (
        <p key={message.id ?? index}>{String(message.content)}</p>
      ))}

      <p>State keys: {Object.keys(stream.values).join(", ")}</p>
    </section>
  );
}

Resources

The SDK clients expose these resource groups:
ResourcePythonTypeScript
Agentsclient.agentsclient.agents
Threads and runsclient.threadsclient.threads
MCP serversclient.mcp_serversclient.mcpServers
Auth sessionsclient.auth_sessionsclient.authSessions
Python methods use snake_case, such as create_and_run and resolve_interrupt. TypeScript methods use camelCase, such as createAndRun and resolveInterrupt. The SDKs can register MCP servers, complete auth sessions, and discover a registered server’s tool schemas with client.mcp_servers.list_tools(...) in Python or client.mcpServers.listTools(...) in TypeScript. Pass the selected tool entries to client.agents.create(...) or client.agents.update(...).

Handle errors

Requests raise typed errors that include the HTTP status and, when the API returns them, an error code and detail.
from managed_deepagents import Client, ManagedDeepAgentsAPIError

with Client() as client:
    try:
        client.agents.get("missing-agent")
    except ManagedDeepAgentsAPIError as error:
        # `code` and `detail` can be empty, for example on a 403 permission error.
        # The raw message is on `error.body`.
        print(error.status_code, error.code, error.detail, error.body)
When a request is denied for a missing permission, the response is a 403 whose code and detail are empty and whose reason is returned as plain text. Read it from error.body in both SDKs, for example missing permission mcp-servers:create. For endpoint-level request and response schemas, see the Managed Deep Agents API reference.