Skip to content

Commit 6627a2a

Browse files
committed
Simplify the boilerplate
Signed-off-by: William Fu-Hinthorn <[email protected]>
1 parent 049ec89 commit 6627a2a

File tree

7 files changed

+52
-74
lines changed

7 files changed

+52
-74
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,4 @@ cython_debug/
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163163
uv.lock
164+
.langgraph_api/

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ lint.ignore = [
5454
"tests/*" = ["D", "UP"]
5555
[tool.ruff.lint.pydocstyle]
5656
convention = "google"
57+
58+
[dependency-groups]
59+
dev = [
60+
"anyio>=4.7.0",
61+
"langgraph-cli[inmem]>=0.2.8",
62+
]

src/agent/configuration.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/agent/graph.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
1-
"""Define a simple chatbot agent.
1+
"""LangGraph single-node graph template.
22
3-
This agent returns a predefined response without using an actual LLM.
3+
Returns a predefined response. Replace logic and configuration as needed.
44
"""
55

6-
from typing import Any, Dict
6+
from __future__ import annotations
7+
8+
from dataclasses import dataclass
9+
from typing import Any, Dict, TypedDict
710

811
from langchain_core.runnables import RunnableConfig
912
from langgraph.graph import StateGraph
1013

11-
from agent.configuration import Configuration
12-
from agent.state import State
14+
15+
class Configuration(TypedDict):
16+
"""Configurable parameters for the agent.
17+
18+
Set these when creating assistants OR when invoking the graph.
19+
See: https://langchain-ai.github.io/langgraph/cloud/how-tos/configuration_cloud/
20+
"""
21+
my_configurable_param: str
22+
23+
24+
@dataclass
25+
class State:
26+
"""Input state for the agent.
27+
28+
Defines the initial structure of incoming data.
29+
See: https://langchain-ai.github.io/langgraph/concepts/low_level/#state
30+
"""
31+
changeme: str = "example"
1332

1433

1534
async def my_node(state: State, config: RunnableConfig) -> Dict[str, Any]:
16-
"""Each node does work."""
17-
configuration = Configuration.from_runnable_config(config)
18-
# configuration = Configuration.from_runnable_config(config)
19-
# You can use runtime configuration to alter the behavior of your
20-
# graph.
35+
"""Example node: processes input and returns output.
36+
37+
Can use runtime configuration to alter behavior.
38+
"""
39+
configuration = config["configurable"]
2140
return {
2241
"changeme": "output from my_node. "
23-
f"Configured with {configuration.my_configurable_param}"
42+
f'Configured with {configuration.get("my_configurable_param")}'
2443
}
2544

2645

27-
# Define a new graph
28-
workflow = StateGraph(State, config_schema=Configuration)
29-
30-
# Add the node to the graph
31-
workflow.add_node("my_node", my_node)
32-
33-
# Set the entrypoint as `call_model`
34-
workflow.add_edge("__start__", "my_node")
35-
36-
# Compile the workflow into an executable graph
37-
graph = workflow.compile()
38-
graph.name = "New Graph" # This defines the custom name in LangSmith
46+
# Define the graph
47+
graph = (
48+
StateGraph(State, config_schema=Configuration)
49+
.add_node(my_node)
50+
.add_edge("__start__", "my_node")
51+
.compile(name="New Graph")
52+
)

src/agent/state.py

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import pytest
2-
from langsmith import unit
32

43
from agent import graph
54

65

7-
@pytest.mark.asyncio
8-
@unit
6+
@pytest.mark.langsmith
97
async def test_agent_simple_passthrough() -> None:
108
res = await graph.ainvoke({"changeme": "some_val"})
119
assert res is not None
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
from agent.configuration import Configuration
1+
from langgraph.pregel import Pregel
22

3+
from agent.graph import graph
34

4-
def test_configuration_empty() -> None:
5-
Configuration.from_runnable_config({})
5+
6+
def test_placeholder() -> None:
7+
# TODO: You can add actual unit tests
8+
# for your graph and other logic here.
9+
assert isinstance(graph, Pregel)

0 commit comments

Comments
 (0)