Invoke agent with thread_id for conversation persistence
You can invoke an agent with a message by passing it along with a thread_id. The thread_id allows the agent to persist and resume conversation history across invocations. Behind the scenes, invocation passes an update to the agent's State.
Checkpointer required for thread_id persistence
Persisting conversation history with thread_id requires the agent to be configured with a checkpointer. When deployed on LangSmith, a checkpointer is provisioned automatically. Locally, pass one explicitly, for example create_agent(..., checkpointer=InMemorySaver()).
Context parameter for per-run configuration
You can pass per-run configuration (such as a user ID, API keys, or feature flags) to tools and middleware using the context parameter alongside config. Define the shape of that data with context_schema and access it through runtime.context.
thread_id vs context scoping difference
thread_id scopes the conversation (message history and checkpoints), while context carries per-run data your tools and middleware read at invocation time. Both are commonly passed together.
Ensure app is LangGraph-compatible before deploying
Before pushing your code to the repository for deployment on LangSmith Cloud, you must make sure your app is LangGraph-compatible by following the local server setup guide.
LangSmith Cloud provides managed infrastructure for stateful agents
LangSmith Cloud provides fully managed infrastructure for stateful, long-running agents with persistent state and background execution. This is the recommended option when deploying LangChain agents to production.
Prerequisites for deploying to LangSmith Cloud
Before deploying to LangSmith Cloud, you need a GitHub account and a LangSmith account (free to sign up).
LangSmith deployment options
LangSmith offers multiple deployment options beyond Cloud, including hybrid deployment, standalone servers, and self-hosted with control plane. For more information, see the LangSmith Deployment overview.
Application code must be in GitHub repository for LangSmith Cloud deployment
Your application code must reside in a GitHub repository to be deployed on LangSmith Cloud. Both public and private repositories are supported.
createAgent in JavaScript/TypeScript
In JavaScript, createAgent is imported from langchain and initialized with model, tools, and checkpointer parameters. For example: createAgent({model: 'openai:gpt-5.5', tools: [getWeather, searchWeb], checkpointer: new MemorySaver()}) where MemorySaver is imported from @langchain/langgraph.
createAgent with MemorySaver checkpointing
In Python, createAgent can be initialized with model, tools, and checkpointer parameters. For example: createAgent(model='openai:gpt-5.5', tools=[get_weather, search_web], checkpointer=MemorySaver()) creates an agent with in-memory checkpointing using MemorySaver from langgraph.checkpoint.memory.
Creating an agent with state machine middleware
Use create_agent() with: model (initialized chat model), tools (all tools from all steps), state_schema (custom state class), middleware (list including apply_step_config), and checkpointer (InMemorySaver or persistent option). The agent then dynamically reconfigures based on current_step on each invocation.
Python workflow compilation syntax
The Python workflow is compiled using StateGraph(RouterState) with methods: add_node() to add nodes, add_edge() to add edges, add_conditional_edges() to connect classify to agent nodes through route_to_agents function with list of possible node names, and compile() to create the executable workflow. The structure is: START -> classify -> [github, notion, slack] -> synthesize -> END.
JavaScript workflow compilation syntax
The JavaScript workflow uses new StateGraph(RouterState) with methods: addNode() to add nodes, addEdge() to add edges, addConditionalEdges() to connect classify to agent nodes through routeToAgents function with array of possible node names, and compile() to create the executable workflow. The structure is identical to Python: START -> classify -> [github, notion, slack] -> synthesize -> END.
Invoking stateless router
Invoke the router with workflow.invoke({"query": "How do I authenticate API requests?"}) in Python or await workflow.invoke({query: "How do I authenticate API requests?"}) in JavaScript. The result contains: query (original user query), classifications (list of routing decisions), results (collected AgentOutput items from all agents), and final_answer (synthesized response).
create_agent: minimal configurable agent harness
LangChain provides create_agent as a minimal, highly configurable harness for building agents. The harness encompasses the prompt, the tools, and any middleware that shapes behavior. Users start with primitives and compose exactly what their use case needs.
Agent invocation input format
Agent invocation uses the invoke method with input structured as a dictionary containing a 'messages' key. The messages value is a list of message objects with 'role' and 'content' keys.
Creating a SQL agent with create_agent
The @create_agent function builds a ReAct agent with minimal code. The agent interprets requests, generates SQL commands which the tools execute, and if errors occur, the error message is returned to the model. The model can then examine the original request and error message to generate a corrected command. This pattern of providing feedback to the model is powerful for iterative query generation.
Agent Chat UI configuration parameters
Agent Chat UI requires three configuration parameters to connect to an agent. Graph ID is the graph name found under `graphs` in the `langgraph.json` file. Deployment URL is the agent server's endpoint, such as `http://localhost:2024` for local development or a deployed agent's URL. LangSmith API key is optional and only needed if not using a local Agent server.
Agent Chat UI automatic thread discovery
Once configured, Agent Chat UI automatically fetches and displays any interrupted threads from the agent.
Agent Chat UI connects to local and deployed agents
Agent Chat UI can connect to both local agents and deployed agents via their respective endpoints.