def call_model(state: MessagesState): """ Process messages through the LLM and return the response """ messages = state["messages"] response = model_with_tools.invoke(messages) return {"messages": [response]}
6
Define the decision function for workflow routing
def should_continue(state: MessagesState) -> Literal["tools", "__end__"]: """ Determine if the conversation should continue to tools or end Returns: - "tools" if the last message contains tool calls - "__end__" otherwise """ messages = state["messages"] last_message = messages[-1] if last_message.tool_calls: return "tools" return "__end__"