Managed Deep Agents is in public beta on LangSmith Cloud.
agent.tsx.
For the full project layout, see Project structure.
To define the agent, use defineDeepAgent:
defineDeepAgent does not compile an agent. It returns a definition, and the managed runtime compiles it with createDeepAgent at deploy time. The options below are the createDeepAgent surface without the ones the runtime owns. See Relationship to Deep Agents.
Parameters
Select configuration per run
To select the agent’s configuration for each run, export a function asagent instead of a definition. One deployment can then adapt to different users, tasks, or repositories. The function is a graph factory, the same pattern LangGraph uses to rebuild a graph at runtime: it receives the runtime and returns a definition.
This example selects instructions and skills for the repository a run works on. It assumes the project has skills/python-service/ and skills/typescript-web/, each with a SKILL.md.
agent.ts
ManagedServerRuntime, which extends the native LangGraph ServerRuntime. Read run context from executionRuntime.context. It is undefined on channel runs, and executionRuntime is null when Agent Server loads the agent for inspection.
Callers choose the configuration through the run’s context:
Select managed resources
A factory can also select the resources that a static agent reads from project files. Omitting a field keeps the project’s configuration. Providing a value replaces it for that run:
Static definitions cannot set these fields. A skill path must end in
skills/<name> and point to a skill in the project. A factory can also return generated skill definitions, whose names must not duplicate project skill names.
This example enables the docs MCP server on request and gives one repository a longer sandbox timeout. It imports the declarations from tools/mcp and sandbox/:
agent.ts
allow policy. See Control access to a layer.
Keep the factory repeatable
Managed Deep Agents calls the factory at the start of each run, and again when a run resumes or retries. Agent Server also calls it to read schemas and state. Follow these rules:- No side effects: Return the same definition for the same context. Do not create records, call external APIs, or change shared state in the factory.
- Stable interrupts: Keep middleware that can interrupt a run in every configuration. When a run resumes, the middleware that raised the interrupt must still be present.
- Inline name: Set
nameas an inline string.mda buildreads it without calling the factory and uses it as the graph ID and default deployment name. - Model dependencies: Install the integration package for every model the factory can return. The build does not detect them.
Use LLM Gateway
You can use LLM Gateway to apply rate limits, fallbacks, and other policies to model calls. Prefix the gateway model ID withlangsmith::
Gateway model IDs use a slash between provider and model (
langsmith:provider/model-name). Model strings that call a provider directly use a colon (provider:model-name).moonshotai/kimi-k3 is a LangChain-hosted model, so it requires no provider secret and draws on Gateway Credits. A model ID that starts with a provider your workspace has configured, such as anthropic/claude-opus-5, uses that provider secret and bills to your own provider account.
For more information, see LLM Gateway.
To scaffold a project that uses Gateway from the start, pass --gateway when initializing:
Connect these docs to your agent of choice via MCP for real-time answers.

