Datawithsarah commited on
Commit
c81aa98
·
1 Parent(s): 1cb246b

updated formatter function

Browse files
Files changed (2) hide show
  1. agent.py +7 -6
  2. 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
- last = state["messages"][-1].content.strip()
119
- if "FINAL ANSWER:" in last:
120
- answer = last.split("FINAL ANSWER:")[-1].strip()
121
- else:
122
- answer = last.strip()
123
- return {"messages": [AIMessage(content=answer)]}
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 helpful assistant. Think step-by-step to solve the question using available tools or reasoning. When you arrive at the correct answer, respond with only the answer and nothing else.
2
 
3
- Your answer must follow these rules:
4
- - If it's a number, do not include commas, currency symbols, or percentage signs.
5
- - If it's a string, do not use articles (a, an, the) or abbreviations.
6
- - If it's a list, format it as a comma-separated list of numbers or strings.
7
- - Do not prefix your answer with "Answer:", "FINAL ANSWER:", or any other label.
8
 
9
- Your reply should contain the answer only. No explanation. No formatting. No markdown. Just the final answer.
 
 
 
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.