Langraph —tools_condition — условное реброPython

Программы на Python
Anonymous
Langraph —tools_condition — условное ребро

Сообщение Anonymous »

Я новичок в langgraph (python) и пытаюсь просмотреть некоторые примеры, найденные на страницах Langgraph.
Мой код выглядит следующим образом:

Код: Выделить всё

class State(TypedDict):
summary: str
messages: list

def summarize_conversation(state: State):
# First, we summarize the conversation
summary = state.get("summary", "")
if summary:
# If a summary already exists, we use a different system prompt
# to summarize it than if one didn't
summary_message = (
f"This is summary of the conversation to date: {summary}\n\n"
"Extend the summary by taking into account the new messages above:"
)
else:
summary_message = "Create a summary of the conversation above:"

messages = state["messages"] + [HumanMessage(content=summary_message)]
response = model.invoke(messages)
return {"summary": response.content, "messages": messages}

graph_builder = StateGraph(State)
graph_builder.add_node("tools", ToolNode(tool_set))
graph_builder.add_node("chatbot", lambda state: {"messages":assistant_runnable.invoke(state)})
graph_builder.add_node("summarize_conversation", summarize_conversation)
graph_builder.add_edge("tools", "summarize_conversation")
graph_builder.add_edge("summarize_conversation", "chatbot")
graph_builder.add_conditional_edges(
"chatbot", tools_condition
)
graph_builder.set_entry_point("chatbot")
graph = graph_builder.compile()graph_builder = StateGraph(State)
graph_builder.add_node("tools", ToolNode(tool_set))
graph_builder.add_node("chatbot", lambda state: {"messages":assistant_runnable.invoke(state)})
graph_builder.add_node("summarize_conversation", summarize_conversation)
graph_builder.add_edge("tools", "summarize_conversation")
graph_builder.add_edge("summarize_conversation", "chatbot")
graph_builder.add_conditional_edges(
"chatbot", tools_condition
)
graph_builder.set_entry_point("chatbot")
graph = graph_builder.compile()

Проблема в том, что я получаю это дополнительное условное преимущество от узла Chatbot к узлу summarise_conversation. Почему это и как это удалить?
Изображение

PS: Для краткости я не привожу полный код.

Подробнее здесь: https://stackoverflow.com/questions/790 ... ional-edge

Вернуться в «Python»