Update agent.py
Browse files
agent.py
CHANGED
|
@@ -29,20 +29,40 @@ def build_graph():
|
|
| 29 |
print("🔍 No match found. Falling back to LLM.")
|
| 30 |
return {"messages": state["messages"]}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
builder.add_edge("retriever", "assistant")
|
| 43 |
-
builder.set_finish_point("assistant")
|
| 44 |
|
| 45 |
-
return builder.compile()
|
| 46 |
|
| 47 |
|
| 48 |
# --- Agent class wrapper for app.py ---
|
|
|
|
| 29 |
print("🔍 No match found. Falling back to LLM.")
|
| 30 |
return {"messages": state["messages"]}
|
| 31 |
|
| 32 |
+
def assistant_node(state: MessagesState):
|
| 33 |
+
query = state["messages"][-1].content.strip()
|
| 34 |
+
|
| 35 |
+
# Instrukcja — jak ma wyglądać odpowiedź
|
| 36 |
+
system_prompt = (
|
| 37 |
+
"You are a helpful AI assistant taking part in the GAIA evaluation benchmark.\n"
|
| 38 |
+
"You must return only the final answer to the user's question.\n"
|
| 39 |
+
"- No explanations.\n"
|
| 40 |
+
"- No formatting like 'Final answer:' or similar.\n"
|
| 41 |
+
"- If the answer is a list, return comma-separated values.\n"
|
| 42 |
+
"- If the answer is unknown, return 'Unknown'."
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
try:
|
| 46 |
+
# Preferowany tryb: chat format
|
| 47 |
+
chat_input = [
|
| 48 |
+
{"role": "system", "content": system_prompt},
|
| 49 |
+
{"role": "user", "content": query}
|
| 50 |
+
]
|
| 51 |
+
response = llm.invoke(chat_input)
|
| 52 |
+
print("✅ Used chat-style prompt.")
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"⚠️ Chat-style failed: {e}")
|
| 55 |
+
# Fallback: classic prompt-based
|
| 56 |
+
fallback_prompt = (
|
| 57 |
+
f"{system_prompt}\n\n"
|
| 58 |
+
f"Question: {query}\n"
|
| 59 |
+
f"Answer:"
|
| 60 |
+
)
|
| 61 |
+
response = llm.invoke(fallback_prompt)
|
| 62 |
+
print("🔁 Used fallback prompt format.")
|
| 63 |
|
| 64 |
+
return {"messages": [AIMessage(content=response.strip())]}
|
|
|
|
|
|
|
| 65 |
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
# --- Agent class wrapper for app.py ---
|