This commit is contained in:
Sydney Runkle
2025-08-10 16:44:10 -04:00
parent 404a3e2962
commit 5a795ff5f2

View File

@@ -8,12 +8,12 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Dict, TypedDict from typing import Any, Dict, TypedDict
from langchain_core.runnables import RunnableConfig
from langgraph.graph import StateGraph from langgraph.graph import StateGraph
from langgraph.runtime import Runtime
class Configuration(TypedDict): class Context(TypedDict):
"""Configurable parameters for the agent. """Context parameters for the agent.
Set these when creating assistants OR when invoking the graph. Set these when creating assistants OR when invoking the graph.
See: https://langchain-ai.github.io/langgraph/cloud/how-tos/configuration_cloud/ See: https://langchain-ai.github.io/langgraph/cloud/how-tos/configuration_cloud/
@@ -33,21 +33,20 @@ class State:
changeme: str = "example" changeme: str = "example"
async def call_model(state: State, config: RunnableConfig) -> Dict[str, Any]: async def call_model(state: State, runtime: Runtime[Context]) -> Dict[str, Any]:
"""Process input and returns output. """Process input and returns output.
Can use runtime configuration to alter behavior. Can use runtime context to alter behavior.
""" """
configuration = config["configurable"]
return { return {
"changeme": "output from call_model. " "changeme": "output from call_model. "
f'Configured with {configuration.get("my_configurable_param")}' f"Configured with {runtime.context.get('my_configurable_param')}"
} }
# Define the graph # Define the graph
graph = ( graph = (
StateGraph(State, config_schema=Configuration) StateGraph(State, context_schema=Context)
.add_node(call_model) .add_node(call_model)
.add_edge("__start__", "call_model") .add_edge("__start__", "call_model")
.compile(name="New Graph") .compile(name="New Graph")