Код: Выделить всё
call_llm = get_history_messages | llm.bind(tools)
def call_tool(messages: List[BaseMessage]):
response = ...
return ToolMessage(tool_call_id=uuid4(), content=json.dumps(response))
graph = StateGraph()
graph.add_node(Node.LLM, call_llm)
graph.add_node(Node.Tool, call_tool)
graph.add_edge(Node.LLM, Node.Tool)
graph.add_edge(Node.Tool, Node.End)
graph.compile()
human_message = HumanMessage(content=...)
async for event in graph.astream_events(human_message, version="v2", stream_mode="values"):
print(event)
Подробнее здесь: https://stackoverflow.com/questions/791 ... -langgraph
Мобильная версия