Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -157,10 +157,17 @@ def planner(state: MessagesState):
|
|
| 157 |
msgs = state["messages"]
|
| 158 |
if msgs[0].type != "system":
|
| 159 |
msgs = [SYSTEM_PROMPT] + msgs
|
|
|
|
| 160 |
resp = with_backoff(lambda: gemini_llm.invoke(msgs))
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
def route(state):
|
| 166 |
return "END" if state["should_end"] else "tools"
|
|
@@ -169,10 +176,17 @@ def route(state):
|
|
| 169 |
TOOLS = [web_search, wiki_search, parse_csv, parse_excel, python_repl]
|
| 170 |
|
| 171 |
graph = StateGraph(MessagesState)
|
|
|
|
| 172 |
graph.add_node("planner", planner)
|
| 173 |
graph.add_node("tools", ToolNode(TOOLS))
|
|
|
|
| 174 |
graph.add_edge(START, "planner")
|
| 175 |
-
graph.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
# compile → LangGraph-Executor
|
| 178 |
agent_executor = graph.compile()
|
|
|
|
| 157 |
msgs = state["messages"]
|
| 158 |
if msgs[0].type != "system":
|
| 159 |
msgs = [SYSTEM_PROMPT] + msgs
|
| 160 |
+
|
| 161 |
resp = with_backoff(lambda: gemini_llm.invoke(msgs))
|
| 162 |
+
|
| 163 |
+
# WICHTIG: Gib tool_calls weiter – sie lösen im ToolNode die Ausführung aus
|
| 164 |
+
return {
|
| 165 |
+
"messages": msgs + [resp],
|
| 166 |
+
"should_end": (
|
| 167 |
+
not getattr(resp, "tool_calls", None) # kein Tool gewünscht
|
| 168 |
+
and "\n" not in resp.content # einfache Heuristik
|
| 169 |
+
)
|
| 170 |
+
}
|
| 171 |
|
| 172 |
def route(state):
|
| 173 |
return "END" if state["should_end"] else "tools"
|
|
|
|
| 176 |
TOOLS = [web_search, wiki_search, parse_csv, parse_excel, python_repl]
|
| 177 |
|
| 178 |
graph = StateGraph(MessagesState)
|
| 179 |
+
|
| 180 |
graph.add_node("planner", planner)
|
| 181 |
graph.add_node("tools", ToolNode(TOOLS))
|
| 182 |
+
|
| 183 |
graph.add_edge(START, "planner")
|
| 184 |
+
graph.add_edge("tools", "planner") # 🔁 Rücksprung zum Planner nach Tool-Ausführung
|
| 185 |
+
|
| 186 |
+
graph.add_conditional_edges("planner", route, {
|
| 187 |
+
"tools": "tools",
|
| 188 |
+
"END": END,
|
| 189 |
+
})
|
| 190 |
|
| 191 |
# compile → LangGraph-Executor
|
| 192 |
agent_executor = graph.compile()
|