new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain · Deep Agents · all subjects

creating agents

15 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Middleware parameter usage

Pass middleware in the `middleware` list (Python) or `middleware` array (JavaScript) to add behavior around model calls, tool calls, and the agent lifecycle. Middleware runs in list or array order.

Agent entry file location and export name

The agent entry lives at the project root in agent.py (Python) or agent.ts/agent.tsx (JavaScript). The agent definition must be exported as a named `agent`.

JavaScript: defineDeepAgent function

Use `defineDeepAgent` from "managed-deepagents" to create a Managed Deep Agent in JavaScript. Basic example: `export const agent = defineDeepAgent({ name: "research-assistant", model: "openai:gpt-5.5" });`.

Python: define_deep_agent function

Use `define_deep_agent` from `managed_deepagents` to create a Managed Deep Agent in Python. Basic example: `agent = define_deep_agent(name="research-assistant", model="openai:gpt-5.5")`.

define_deep_agent parameters (Python)

Python define_deep_agent accepts these parameters: name (sets agent and default deployment name), model (selects the chat model), tools (adds tools the agent can call), middleware (adds behavior around model calls, tool calls, and agent lifecycle), subagents (defines specialized agents for delegated tasks), permissions (controls path-level access for filesystem tools), interrupt_on (pauses before selected tool calls for human approval), response_format (defines a structured output schema).

defineDeepAgent parameters (JavaScript)

JavaScript defineDeepAgent accepts these parameters: name (sets agent and default deployment name), model (selects the chat model), tools (adds tools the agent can call), middleware (adds behavior around model calls, tool calls, and agent lifecycle), subagents (defines specialized agents for delegated tasks), permissions (controls path-level access for filesystem tools), interruptOn (pauses before selected tool calls for human approval), responseFormat (defines a structured output schema).

Name parameter requirements

The `name` parameter is required and must be a static string that starts with a letter and contains only letters, numbers, underscores, or hyphens, such as "research-assistant". MDA uses the name as the LangGraph assistant ID and the default LangSmith deployment name. The deployment name can be overridden with `mda deploy --name` without changing the agent definition.

Model parameter string format

Set `model` to the chat model the agent uses. The simplest option is a `provider:model` string such as "openai:gpt-5.5" or "anthropic:claude-sonnet-4-6". Add the provider's API key to `.env` so the model works locally and in the deployment.

LangChain chat model instance for model parameter

Pass a LangChain chat model instance instead of a string when you need to configure model parameters in code. This allows setting model-specific options.

LangSmith Gateway configuration

To use LangSmith Gateway for rate limits and fallbacks, use the ChatOpenAI model directly with base_url of "https://gateway.smith.langchain.com/v1" and set LANGSMITH_GATEWAY_API_KEY environment variable to your LangSmith API key. When using Gateway, the model slug should be `provider/model-name` format instead of `provider:model-name`.

LangSmith Gateway ChatOpenAI Python example

```python import os from managed_deepagents import define_deep_agent from langchain_openai import ChatOpenAI api_key = os.environ.get( "LANGSMITH_GATEWAY_API_KEY", "missing-langsmith-gateway-api-key", ) base_url = "https://gateway.smith.langchain.com/v1" agent = define_deep_agent( name="my-agent", model=ChatOpenAI( model="moonshotai/Kimi-K3", api_key=api_key, base_url=base_url, ), ) ```

LangSmith Gateway ChatOpenAI JavaScript example

```ts import { defineDeepAgent } from "managed-deepagents"; import { ChatOpenAI } from "@langchain/openai"; const apiKey = process.env.LANGSMITH_GATEWAY_API_KEY ?? "missing-langsmith-gateway-api-key"; const baseURL = "https://gateway.smith.langchain.com/v1"; export const agent = defineDeepAgent({ name: "my-agent", model: new ChatOpenAI({ model: "moonshotai/Kimi-K3", apiKey, configuration: { baseURL }, }), }); ```

Gateway initialization flag

To scaffold a project to use LangSmith Gateway from the start, pass the `--gateway` flag when initializing your agent: `mda init my-agent --gateway`.

Tools parameter usage

Pass tools in the `tools` list (Python) or `tools` array (JavaScript) to let the agent call application logic or external services. Define tools in local modules, import them into the agent entry, and add them to the definition. For tools from remote MCP servers, use MCP connectors instead of importing them into the agent entry.

Initialize Deep Agents project with memory

To initialize a Deep Agents project with memory, create a memory.py (Python) or memory.ts (TypeScript) file at the project root. In Python: from managed_deepagents import define_memory; memory = define_memory(scope='agent'). In TypeScript: import { defineMemory } from 'managed-deepagents'; export const memory = defineMemory({ scope: 'agent' }). This exports a named memory declaration with the 'agent' scope which enables durable memory backed by Context Hub.

Give your agent this brain