Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,9 @@ import os
|
|
| 3 |
import inspect
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
-
import pandas as pd
|
| 7 |
-
from langchain_core.messages import HumanMessage
|
| 8 |
-
from
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -21,14 +21,35 @@ class BasicAgent:
|
|
| 21 |
"""A langgraph agent."""
|
| 22 |
def __init__(self):
|
| 23 |
print("BasicAgent initialized.")
|
| 24 |
-
self.graph = build_graph
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 28 |
-
messages = [HumanMessage(content=question)]
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
|
|
|
|
| 3 |
import inspect
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
+
#import pandas as pd
|
| 7 |
+
#from langchain_core.messages import HumanMessage
|
| 8 |
+
from gaia_agent import HumanMessage, SystemMessage, build_graph
|
| 9 |
|
| 10 |
|
| 11 |
|
|
|
|
| 21 |
"""A langgraph agent."""
|
| 22 |
def __init__(self):
|
| 23 |
print("BasicAgent initialized.")
|
| 24 |
+
self.graph = build_graph
|
| 25 |
+
self.systemMsg = SystemMessage(
|
| 26 |
+
content="""
|
| 27 |
+
"You are a helpful assistant tasked with answering questions using a set of tools.\n"
|
| 28 |
+
"Your final answer must strictly follow this format:\n"
|
| 29 |
+
"FINAL ANSWER: [ANSWER]\n"
|
| 30 |
+
"Only write the answer in that exact format. Do not explain anything. Do not include any other text. \n"
|
| 31 |
+
"If you are provided with a similar question and its final answer, and the current question is **exactly the same**, then simply return the same final answer without using any tools. \n"
|
| 32 |
+
"Only use tools if the current question is different from the similar one. \n"
|
| 33 |
+
"Examples: \n"
|
| 34 |
+
"- FINAL ANSWER: FunkMonk \n"
|
| 35 |
+
"- FINAL ANSWER: Paris \n"
|
| 36 |
+
"- FINAL ANSWER: 128 \n"
|
| 37 |
+
" \n"
|
| 38 |
+
"Once you output 'FINAL ANSWER', stop reasoning and do not call any tool.\n"
|
| 39 |
+
"If you do not follow this format exactly, your response will be considered incorrect. \n"
|
| 40 |
+
"Use the most up-to-date information available to you we are in December 2025.
|
| 41 |
+
"""
|
| 42 |
+
)
|
| 43 |
|
| 44 |
def __call__(self, question: str) -> str:
|
| 45 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 46 |
+
messages = [self.systemMsg, HumanMessage(content=question)]
|
| 47 |
+
response = self.graph.invoke({"messages": messages})
|
| 48 |
+
ai_msg = response["messages"][-1].content
|
| 49 |
+
if "FINAL ANSWER:" in ai_msg:
|
| 50 |
+
return ai_msg.split("FINAL ANSWER:")[-1].strip()
|
| 51 |
+
else:
|
| 52 |
+
return ai_msg.strip()
|
| 53 |
|
| 54 |
|
| 55 |
|