rsobieski commited on
Commit
c932e96
·
verified ·
1 Parent(s): ba74371

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +31 -11
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
- def assistant_node(state: MessagesState):
33
- query = state["messages"][-1].content.strip()
34
- response = llm.invoke(query)
35
- return {"messages": [AIMessage(content=response)]}
 
 
 
 
 
 
 
 
36
 
37
- builder = StateGraph(MessagesState)
38
- builder.add_node("retriever", retriever_node)
39
- builder.add_node("assistant", assistant_node)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- builder.set_entry_point("retriever")
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 ---