-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
56 lines (43 loc) · 1.67 KB
/
Copy pathbasic.py
File metadata and controls
56 lines (43 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Minimal LangGraph served through a standalone FastAPI application."""
from typing import TypedDict
from langgraph.checkpoint.base import BaseCheckpointSaver
from langgraph.graph import END, START, StateGraph
from fastapi_langgraph_server import AssistantConfig, StandaloneAppConfig, create_app
class GreetingState(TypedDict, total=False):
"""Input and output state for the example graph."""
name: str
greeting: str
def greet(state: GreetingState) -> GreetingState:
"""Return a deterministic greeting so the server needs no external service."""
name = state.get("name", "world")
return {"greeting": f"Hello, {name}!"}
def build_graph(checkpointer: BaseCheckpointSaver[str] | None) -> object:
"""Compile statelessly or with the explicitly configured checkpointer."""
builder = StateGraph(GreetingState)
builder.add_node("greet", greet)
builder.add_edge(START, "greet")
builder.add_edge("greet", END)
return builder.compile(checkpointer=checkpointer)
assistant = AssistantConfig(
assistant_id="greeter",
graph_id="greeter",
name="Example greeter",
description="A minimal deterministic LangGraph for local smoke testing.",
checkpointed_graph_factory=build_graph,
input_schema={
"type": "object",
"properties": {"name": {"type": "string"}},
},
output_schema={
"type": "object",
"properties": {"greeting": {"type": "string"}},
},
)
app = create_app(
StandaloneAppConfig(
title="fastapi-langgraph-server example",
description="A local test server backed by a basic LangGraph.",
assistants={assistant.assistant_id: assistant},
cors_origins=(),
)
)