mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-29 11:19:54 +02:00
Undo
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import json
|
||||
from typing import Annotated, Any, Optional, Sequence, TypedDict, Union
|
||||
from typing import Annotated, Sequence, TypedDict, Union
|
||||
|
||||
from langchain_core.language_models import LanguageModelLike
|
||||
from langchain_core.messages import AIMessage, BaseMessage, FunctionMessage
|
||||
from langchain_core.messages import BaseMessage, FunctionMessage
|
||||
from langchain_core.runnables import RunnableLambda
|
||||
from langchain_core.tools import BaseTool
|
||||
from langchain_core.utils.function_calling import convert_to_openai_function
|
||||
@@ -14,13 +14,6 @@ from langgraph.prebuilt.tool_executor import ToolExecutor, ToolInvocation
|
||||
from langgraph.prebuilt.tool_node import ToolNode
|
||||
|
||||
|
||||
class RetriableError(Exception):
|
||||
"""An error that can be retried."""
|
||||
|
||||
def __init__(self, data: dict[str, Any]):
|
||||
self.data = data
|
||||
|
||||
|
||||
# We create the AgentState that we will pass around
|
||||
# This simply involves a list of messages
|
||||
# We want steps to return messages to append to the list
|
||||
@@ -54,16 +47,9 @@ def create_function_calling_executor(
|
||||
return "continue"
|
||||
|
||||
# Define the function that calls the model
|
||||
def call_model(state: AgentState, retry: Optional[RetriableError] = None):
|
||||
if retry:
|
||||
# TODO try to fix the invalid tool calls
|
||||
pass
|
||||
|
||||
# call the model
|
||||
response: AIMessage = model.invoke(state["messages"])
|
||||
# If there are invalid tool calls, we raise a RetriableError
|
||||
if response.invalid_tool_calls:
|
||||
raise RetriableError({"invalid_tool_calls": response.invalid_tool_calls})
|
||||
def call_model(state: AgentState):
|
||||
messages = state["messages"]
|
||||
response = model.invoke(messages)
|
||||
# We return a list, because this will get added to the existing list
|
||||
return {"messages": [response]}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user