logo
1

有用LangChain/LangGraph集成的例子么?

  
  
from langchain_core.messages import AnyMessage
from langgraph.errors import GraphRecursionError
from langgraph.prebuilt import create_react_agent
from langchain.tools import tool
from langchain_community.chat_models import QianfanChatEndpoint
chat = QianfanChatEndpoint(model="ERNIE-3.5-8K", stream=False)
magic_step_num = 1
@tool
def magic_function(input: int) -> int:
"""Applies a magic function to an input."""
global magic_step_num
print(f"Call number: {magic_step_num}")
magic_step_num += 1
return input + magic_step_num
tools = [magic_function]
def _modify_messages(messages: list[AnyMessage]):
# Give the agent amnesia, only keeping the original user query
return [("system", "You are a helpful assistant"), messages[0]]
app = create_react_agent(model=chat, tools=tools, messages_modifier=_modify_messages)
#%%
query = "Call the magic function 4 times in sequence with the value 3. You cannot call it multiple times at once."
try:
for step in app.stream({"messages": [("human", query)]}, stream_mode="updates"):
print(step)
except GraphRecursionError as e:
print("Stopping agent prematurely due to triggering stop condition")
上面代码照着官网照葫芦画瓢的,跑不通哇
tool_call_id
none is not an allowed value (type=type_error.none.not_allowed)
有没有现成跑得通的Function Call例子
评论
用户头像