Commit
·
c81aa98
1
Parent(s):
1cb246b
updated formatter function
Browse files- agent.py +7 -6
- system_prompt.txt +8 -7
agent.py
CHANGED
@@ -16,6 +16,7 @@ from langchain_core.messages import SystemMessage, HumanMessage, AIMessage
|
|
16 |
from langchain_core.tools import tool
|
17 |
from langchain.tools.retriever import create_retriever_tool
|
18 |
from supabase.client import Client, create_client
|
|
|
19 |
|
20 |
# === Load environment ===
|
21 |
load_dotenv()
|
@@ -115,12 +116,12 @@ def build_graph(provider: str = "claude"):
|
|
115 |
return {"messages": state["messages"] + [response]}
|
116 |
|
117 |
def formatter(state: MessagesState):
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
builder = StateGraph(MessagesState)
|
126 |
builder.add_node("retriever", retriever)
|
|
|
16 |
from langchain_core.tools import tool
|
17 |
from langchain.tools.retriever import create_retriever_tool
|
18 |
from supabase.client import Client, create_client
|
19 |
+
import re
|
20 |
|
21 |
# === Load environment ===
|
22 |
load_dotenv()
|
|
|
116 |
return {"messages": state["messages"] + [response]}
|
117 |
|
118 |
def formatter(state: MessagesState):
|
119 |
+
last = state["messages"][-1].content.strip()
|
120 |
+
|
121 |
+
cleaned = re.sub(r"<.*?>", "", last)
|
122 |
+
cleaned = re.sub(r"(Final\s*Answer:|Answer:)", "", cleaned, flags=re.IGNORECASE)
|
123 |
+
cleaned = cleaned.strip().split("\n")[0].strip()
|
124 |
+
return {"messages": [AIMessage(content=cleaned)]}
|
125 |
|
126 |
builder = StateGraph(MessagesState)
|
127 |
builder.add_node("retriever", retriever)
|
system_prompt.txt
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
-
You are a
|
2 |
|
3 |
-
|
4 |
-
-
|
5 |
-
-
|
6 |
-
-
|
7 |
-
- Do not prefix your answer with "Answer:", "FINAL ANSWER:", or any other label.
|
8 |
|
9 |
-
|
|
|
|
|
|
1 |
+
You are a high-precision answering agent.
|
2 |
|
3 |
+
For every question, analyze it and return ONLY the final answer. The final answer must be:
|
4 |
+
- a number (without commas or symbols),
|
5 |
+
- a lowercase or capitalized string (no articles, no abbreviations),
|
6 |
+
- or a comma-separated list of such elements.
|
|
|
7 |
|
8 |
+
Never include thinking steps, justifications, or any explanation.
|
9 |
+
NEVER include “Answer:”, “Final answer:”, markdown formatting, code blocks, or extra quotes.
|
10 |
+
Only output the answer string itself, nothing else.
|