Files
graphtest/src/agent/graph.py

54 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 langgraph.graph import StateGraph
2025-08-10 16:44:10 -04:00
from langgraph.runtime import Runtime
2024-09-13 16:28:17 -07:00
2025-08-10 16:44:10 -04:00
class Context(TypedDict):
"""Context 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/
"""
2025-05-14 06:53:07 -07:00
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
"""
2025-05-14 06:53:07 -07:00
changeme: str = "example"
2024-09-13 17:06:33 -07:00
2024-09-13 16:28:17 -07:00
2025-08-10 16:44:10 -04:00
async def call_model(state: State, runtime: Runtime[Context]) -> Dict[str, Any]:
2025-05-14 06:53:07 -07:00
"""Process input and returns output.
2025-08-10 16:44:10 -04:00
Can use runtime context to alter behavior.
"""
return {
2025-05-14 06:53:07 -07:00
"changeme": "output from call_model. "
2025-08-10 16:44:10 -04:00
f"Configured with {runtime.context.get('my_configurable_param')}"
}
2024-09-13 16:28:17 -07:00
# Define the graph
graph = (
2025-08-10 16:44:10 -04:00
StateGraph(State, context_schema=Context)
2025-05-14 06:53:07 -07:00
.add_node(call_model)
.add_edge("__start__", "call_model")
.compile(name="New Graph")
)