|
1 | | -"""Define a simple chatbot agent. |
| 1 | +"""LangGraph single-node graph template. |
2 | 2 |
|
3 | | -This agent returns a predefined response without using an actual LLM. |
| 3 | +Returns a predefined response. Replace logic and configuration as needed. |
4 | 4 | """ |
5 | 5 |
|
6 | | -from typing import Any, Dict |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from dataclasses import dataclass |
| 9 | +from typing import Any, Dict, TypedDict |
7 | 10 |
|
8 | 11 | from langchain_core.runnables import RunnableConfig |
9 | 12 | from langgraph.graph import StateGraph |
10 | 13 |
|
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" |
13 | 32 |
|
14 | 33 |
|
15 | 34 | 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"] |
21 | 40 | return { |
22 | 41 | "changeme": "output from my_node. " |
23 | | - f"Configured with {configuration.my_configurable_param}" |
| 42 | + f'Configured with {configuration.get("my_configurable_param")}' |
24 | 43 | } |
25 | 44 |
|
26 | 45 |
|
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 | +) |
0 commit comments