Quickstart
Build an agent with LangChain and expose its graph as an SSE endpoint.
This example uses LangChain createAgent; Agentdock does not construct or run
the model/tool loop. Install a provider integration and set its credentials.
import { Agentdock } from "@agentdock-ai/agentdock";
import { ChatOpenRouter } from "@langchain/openrouter";
import { MemorySaver } from "@langchain/langgraph";
import { createAgent, tool } from "langchain";
import { z } from "zod";
const weather = tool(async ({ city }) => ({ city, forecast: "Sunny" }), {
name: "get_weather",
description: "Get the current weather for a city.",
schema: z.object({ city: z.string() }),
});
const graph = createAgent({
model: new ChatOpenRouter({ model: "openai/gpt-4o-mini" }),
tools: [weather],
checkpointer: new MemorySaver(),
}).graph;
const runtime = new Agentdock(graph);After your application authenticates and authorizes a request, pass an application-derived thread ID and graph input to the serving runtime:
await runtime.pipe(response, {
threadId: threadIdFromAuthorizedSession,
input: { messages: [{ role: "user", content: "Weather in Lahore?" }] },
context: { userId: authenticatedUser.id },
});pipe() writes Server-Sent Events to a Node response, honors backpressure, and
aborts cooperative graph and tool work if the client disconnects. Use
toResponse() for a Web Response, or stream()
when you want to consume events without a transport.
MemorySaver is for development and single-process demonstrations. Use an
appropriate LangGraph saver for durable production checkpoints, and manage its
lifecycle in your application.

