33Works with a chat model with tool calling support.
44"""
55
6- from datetime import datetime , timezone
6+ from datetime import UTC , datetime
77from typing import Dict , List , Literal , cast
88
99from langchain_core .messages import AIMessage
10- from langchain_core .runnables import RunnableConfig
1110from langgraph .graph import StateGraph
1211from langgraph .prebuilt import ToolNode
1312
1918# Define the function that calls the model
2019
2120
22- async def call_model (
23- state : State , config : RunnableConfig
24- ) -> Dict [str , List [AIMessage ]]:
21+ async def call_model (state : State ) -> Dict [str , List [AIMessage ]]:
2522 """Call the LLM powering our "agent".
2623
2724 This function prepares the prompt, initializes the model, and processes the response.
@@ -33,21 +30,21 @@ async def call_model(
3330 Returns:
3431 dict: A dictionary containing the model's response message.
3532 """
36- configuration = Configuration .from_runnable_config ( config )
33+ configuration = Configuration .from_context ( )
3734
3835 # Initialize the model with tool binding. Change the model or add more tools here.
3936 model = load_chat_model (configuration .model ).bind_tools (TOOLS )
4037
4138 # Format the system prompt. Customize this to change the agent's behavior.
4239 system_message = configuration .system_prompt .format (
43- system_time = datetime .now (tz = timezone . utc ).isoformat ()
40+ system_time = datetime .now (tz = UTC ).isoformat ()
4441 )
4542
4643 # Get the model's response
4744 response = cast (
4845 AIMessage ,
4946 await model .ainvoke (
50- [{"role" : "system" , "content" : system_message }, * state .messages ], config
47+ [{"role" : "system" , "content" : system_message }, * state .messages ]
5148 ),
5249 )
5350
@@ -115,9 +112,4 @@ def route_model_output(state: State) -> Literal["__end__", "tools"]:
115112builder .add_edge ("tools" , "call_model" )
116113
117114# Compile the builder into an executable graph
118- # You can customize this by adding interrupt points for state updates
119- graph = builder .compile (
120- interrupt_before = [], # Add node names here to update state before they're called
121- interrupt_after = [], # Add node names here to update state after they're called
122- )
123- graph .name = "ReAct Agent" # This customizes the name in LangSmith
115+ graph = builder .compile (name = "ReAct Agent" )
0 commit comments