Files
graphtest/src/agent/graph.py

53 lines
1.3 KiB
Python
Raw Normal View History

"""LangGraph single-node graph template.
2024-09-13 16:28:17 -07:00
Returns a predefined response. Replace logic and configuration as needed.
2024-09-13 16:28:17 -07:00
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Dict, TypedDict
2024-09-13 16:28:17 -07:00
from langchain_core.runnables import RunnableConfig
from langgraph.graph import StateGraph
class Configuration(TypedDict):
"""Configurable parameters for the agent.
Set these when creating assistants OR when invoking the graph.
See: https://langchain-ai.github.io/langgraph/cloud/how-tos/configuration_cloud/
"""
my_configurable_param: str
@dataclass
class State:
"""Input state for the agent.
Defines the initial structure of incoming data.
See: https://langchain-ai.github.io/langgraph/concepts/low_level/#state
"""
changeme: str = "example"
2024-09-13 17:06:33 -07:00
2024-09-13 16:28:17 -07:00
async def my_node(state: State, config: RunnableConfig) -> Dict[str, Any]:
"""Example node: processes input and returns output.
Can use runtime configuration to alter behavior.
"""
configuration = config["configurable"]
return {
"changeme": "output from my_node. "
f'Configured with {configuration.get("my_configurable_param")}'
}
2024-09-13 16:28:17 -07:00
# Define the graph
graph = (
StateGraph(State, config_schema=Configuration)
.add_node(my_node)
.add_edge("__start__", "my_node")
.compile(name="New Graph")
)