Files
docs/build/snippets/python/code-samples/graph-api-using-tasks-original-js.mdx
T
2026-07-29 10:28:19 +00:00

38 lines
884 B
Plaintext

```ts
import * as z from "zod";
import {
END,
MemorySaver,
START,
StateGraph,
StateSchema,
} from "@langchain/langgraph";
import type { GraphNode } from "@langchain/langgraph";
const State = new StateSchema({
url: z.string(),
result: z.string().optional(),
});
const callApi: GraphNode<typeof State> = async (state) => {
const response = await fetch(state.url); // [!code highlight]
const text = await response.text();
const result = text.slice(0, 100);
return { result };
};
const builder = new StateGraph(State)
.addNode("callApi", callApi)
.addEdge(START, "callApi")
.addEdge("callApi", END);
const checkpointer = new MemorySaver();
const graph = builder.compile({ checkpointer });
const threadId = crypto.randomUUID();
const config = { configurable: { thread_id: threadId } };
await graph.invoke({ url: "https://www.example.com" }, config);
```