Spaces:
Sleeping
Sleeping
EtienneB
commited on
Commit
·
5da0168
1
Parent(s):
353e950
major overhaul
Browse files- agent.py +69 -15
- answer.txt +6 -0
- app.py +3 -40
- agent-old.py → archive/agent-old.py +0 -0
- app-old.py → archive/app-old.py +0 -0
- archive/app-old2.py +232 -0
- old-tools.py → archive/old-tools.py +0 -0
- retriever.py → archive/retriever.py +0 -0
- scrapbook.py → archive/scrapbook.py +0 -0
- system-prompt-claude.txt +67 -0
- system-prompt.txt +30 -0
agent.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import json
|
2 |
import os
|
3 |
-
import re
|
4 |
|
5 |
from dotenv import load_dotenv
|
6 |
from langchain_core.messages import (AIMessage, HumanMessage, SystemMessage,
|
@@ -39,19 +38,73 @@ tools = [
|
|
39 |
|
40 |
# Updated system prompt for cleaner output
|
41 |
system_prompt = """
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
-
|
48 |
-
-
|
49 |
-
-
|
50 |
-
-
|
51 |
-
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
"""
|
56 |
|
57 |
# System message
|
@@ -64,7 +117,7 @@ def build_graph():
|
|
64 |
llm_endpoint = HuggingFaceEndpoint(
|
65 |
repo_id="Qwen/Qwen2.5-14B-Instruct",
|
66 |
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
67 |
-
temperature=0.
|
68 |
max_new_tokens=128, # Even more restrictive
|
69 |
timeout=90, # Moderate timeout
|
70 |
do_sample=False, # Completely deterministic
|
@@ -117,6 +170,7 @@ if __name__ == "__main__":
|
|
117 |
print(f"Raw output: {output}")
|
118 |
try:
|
119 |
parsed = json.loads(output)
|
|
|
120 |
if isinstance(parsed, list) and "task_id" in parsed[0] and "submitted_answer" in parsed[0]:
|
121 |
print("✅ Output is in the correct format!")
|
122 |
print(f"Task ID: {parsed[0]['task_id']}")
|
|
|
1 |
import json
|
2 |
import os
|
|
|
3 |
|
4 |
from dotenv import load_dotenv
|
5 |
from langchain_core.messages import (AIMessage, HumanMessage, SystemMessage,
|
|
|
38 |
|
39 |
# Updated system prompt for cleaner output
|
40 |
system_prompt = """
|
41 |
+
# AI Agent System Prompt
|
42 |
+
|
43 |
+
You are an advanced AI agent equipped with multiple tools to solve complex, multi-step problems. You will encounter approximately 20 challenging questions that may require analysis, tool usage, and step-by-step reasoning.
|
44 |
+
|
45 |
+
## Core Capabilities
|
46 |
+
- Multi-tool integration via Python scripts
|
47 |
+
- Complex problem analysis and decomposition
|
48 |
+
- Step-by-step reasoning for multi-part questions
|
49 |
+
- File processing and data analysis
|
50 |
+
- Mathematical calculations and logical reasoning
|
51 |
+
|
52 |
+
## Analysis and Approach
|
53 |
+
1. **Question Analysis**: Always analyze the question first to understand:
|
54 |
+
- What information is being requested
|
55 |
+
- What tools or data sources might be needed
|
56 |
+
- Whether the question has multiple parts or steps
|
57 |
+
- If any preprocessing or data gathering is required
|
58 |
+
|
59 |
+
2. **Tool Selection**: Determine which tools are most appropriate:
|
60 |
+
- If files, documents, images, or URLs are mentioned, use download/file processing tools FIRST
|
61 |
+
- Use specialized analysis tools for different file types (CSV, Excel, images, etc.)
|
62 |
+
- Apply mathematical or computational tools for calculations
|
63 |
+
- Utilize web search or data retrieval tools when external information is needed
|
64 |
+
|
65 |
+
3. **Multi-Step Problem Solving**: For complex questions:
|
66 |
+
- Break down the problem into logical steps
|
67 |
+
- Execute each step systematically
|
68 |
+
- Use outputs from one tool as inputs for another when necessary
|
69 |
+
- Verify intermediate results before proceeding
|
70 |
+
|
71 |
+
## Tool Usage Guidelines
|
72 |
+
- **File Processing**: Always download and process files before attempting to answer questions about them
|
73 |
+
- **Data Analysis**: Use appropriate tools for different data formats (analyze_csv_file, analyze_excel_file, extract_text_from_image)
|
74 |
+
- **Calculations**: Employ mathematical tools for computations, statistical analysis, or complex calculations
|
75 |
+
- **Information Gathering**: Use search or retrieval tools when external knowledge is required
|
76 |
+
- **Chain Tools**: Combine multiple tools when a single tool cannot solve the complete problem
|
77 |
+
|
78 |
+
## Response Format
|
79 |
+
After completing your analysis and using necessary tools, provide ONLY your final answer with no additional text, explanations, or formatting.
|
80 |
+
|
81 |
+
### Answer Formatting Rules:
|
82 |
+
- **Numbers**: Provide just the number without commas, units, or symbols (unless specifically requested)
|
83 |
+
- **Text**: Use minimal words, no articles, no abbreviations, write digits in plain text
|
84 |
+
- **Lists**: Comma-separated values following the above rules for each element type
|
85 |
+
- **Precision**: Be exact and concise - include only what is specifically asked for
|
86 |
+
|
87 |
+
### Critical Response Rule:
|
88 |
+
- Do NOT include "FINAL ANSWER:" or any other prefixes/labels
|
89 |
+
- Do NOT include explanations, reasoning, or additional text
|
90 |
+
- Provide ONLY the answer itself - nothing else
|
91 |
+
|
92 |
+
## Process Flow
|
93 |
+
1. **Read and Analyze**: Carefully read the question and identify all requirements
|
94 |
+
2. **Plan**: Determine the sequence of tools and steps needed
|
95 |
+
3. **Execute**: Use tools systematically, processing outputs as needed
|
96 |
+
4. **Verify**: Check that your analysis addresses all parts of the question
|
97 |
+
5. **Answer**: Provide only the raw answer with no formatting, labels, or additional text
|
98 |
+
|
99 |
+
## Important Notes
|
100 |
+
- Some questions may appear simple but require multiple tools or steps
|
101 |
+
- Always prioritize accuracy over speed
|
102 |
+
- If a question has multiple parts, ensure all parts are addressed
|
103 |
+
- Use the most appropriate tool for each task
|
104 |
+
- Process any mentioned files, attachments, or external resources before answering
|
105 |
+
- Think through the problem systematically but provide only the final answer
|
106 |
+
|
107 |
+
Remember: Your goal is to provide accurate, precise answers to complex questions using the full range of available tools and capabilities. Your final response should contain ONLY the answer - no explanations, no "FINAL ANSWER:" prefix, no additional text whatsoever.
|
108 |
"""
|
109 |
|
110 |
# System message
|
|
|
117 |
llm_endpoint = HuggingFaceEndpoint(
|
118 |
repo_id="Qwen/Qwen2.5-14B-Instruct",
|
119 |
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
120 |
+
temperature=0.1, # Maximum determinism
|
121 |
max_new_tokens=128, # Even more restrictive
|
122 |
timeout=90, # Moderate timeout
|
123 |
do_sample=False, # Completely deterministic
|
|
|
170 |
print(f"Raw output: {output}")
|
171 |
try:
|
172 |
parsed = json.loads(output)
|
173 |
+
print(parsed)
|
174 |
if isinstance(parsed, list) and "task_id" in parsed[0] and "submitted_answer" in parsed[0]:
|
175 |
print("✅ Output is in the correct format!")
|
176 |
print(f"Task ID: {parsed[0]['task_id']}")
|
answer.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
We advise you to use the system prompt provided in the paper to ensure your agents answer using the correct and expected format. In practice, GPT4 level models easily follow it.
|
2 |
+
|
3 |
+
We expect submissions to be json-line files with the following format. The first two fields are mandatory, reasoning_trace is optional:
|
4 |
+
|
5 |
+
{"task_id": "task_id_1", "model_answer": "Answer 1 from your model", "reasoning_trace": "The different steps by which your model reached answer 1"}
|
6 |
+
{"task_id": "task_id_2", "model_answer": "Answer 2 from your model", "reasoning_trace": "The different steps by which your model reached answer 2"}
|
app.py
CHANGED
@@ -4,10 +4,6 @@ import os
|
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
import requests
|
7 |
-
# Additional libraries
|
8 |
-
from langchain_core.messages import AIMessage, HumanMessage
|
9 |
-
|
10 |
-
from agent import build_graph
|
11 |
|
12 |
# (Keep Constants as is)
|
13 |
# --- Constants ---
|
@@ -16,46 +12,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
16 |
# --- Basic Agent Definition ---
|
17 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
18 |
class BasicAgent:
|
19 |
-
"""A basic agent that uses a pre-built graph to answer questions.
|
20 |
-
|
21 |
-
This agent is initialized with a graph structure that defines its
|
22 |
-
reasoning and processing flow. When called, it takes a user's question,
|
23 |
-
invokes the graph with it, and returns the final response.
|
24 |
-
|
25 |
-
Attributes:
|
26 |
-
graph: The compiled graph from `build_graph()` that processes messages.
|
27 |
-
"""
|
28 |
def __init__(self):
|
29 |
-
"""Initializes the BasicAgent by building its processing graph."""
|
30 |
print("BasicAgent initialized.")
|
31 |
-
# This function should be defined elsewhere in the code.
|
32 |
-
# It is expected to return a compiled LangChain graph.
|
33 |
self.graph = build_graph()
|
34 |
-
|
35 |
def __call__(self, question: str) -> str:
|
36 |
-
"""Processes a question using the agent's graph and returns the answer.
|
37 |
-
|
38 |
-
This method makes the agent instance callable. It wraps the user's
|
39 |
-
question in a HumanMessage, sends it through the processing graph,
|
40 |
-
and extracts the content from the final message in the response.
|
41 |
-
|
42 |
-
Args:
|
43 |
-
question: The question to be processed by the agent.
|
44 |
-
|
45 |
-
Returns:
|
46 |
-
The answer generated by the agent's graph as a string.
|
47 |
-
"""
|
48 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
# and returns a dictionary with the processed messages.
|
53 |
-
response_messages = self.graph.invoke({"messages": messages})
|
54 |
-
# The answer is expected to be in the 'content' of the last message.
|
55 |
-
answer = response_messages['messages'][-1].content
|
56 |
-
print(f"Agent full response: {answer}")
|
57 |
-
return answer
|
58 |
-
|
59 |
|
60 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
61 |
"""
|
@@ -232,4 +196,3 @@ if __name__ == "__main__":
|
|
232 |
|
233 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
234 |
demo.launch(debug=True, share=False)
|
235 |
-
|
|
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
import requests
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
|
|
12 |
# --- Basic Agent Definition ---
|
13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
14 |
class BasicAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def __init__(self):
|
|
|
16 |
print("BasicAgent initialized.")
|
|
|
|
|
17 |
self.graph = build_graph()
|
|
|
18 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
20 |
+
fixed_answer = self.graph.invoke({"messages": messages})
|
21 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
22 |
+
return fixed_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
25 |
"""
|
|
|
196 |
|
197 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
198 |
demo.launch(debug=True, share=False)
|
|
agent-old.py → archive/agent-old.py
RENAMED
File without changes
|
app-old.py → archive/app-old.py
RENAMED
File without changes
|
archive/app-old2.py
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import requests
|
6 |
+
from langchain_core.messages import AIMessage, HumanMessage
|
7 |
+
|
8 |
+
from agent import build_graph
|
9 |
+
|
10 |
+
# --- Constants ---
|
11 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
12 |
+
|
13 |
+
# --- Basic Agent Definition ---
|
14 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
+
class BasicAgent:
|
16 |
+
"""A basic agent that uses a pre-built graph to answer questions.
|
17 |
+
|
18 |
+
This agent is initialized with a graph structure that defines its
|
19 |
+
reasoning and processing flow. When called, it takes a user's question,
|
20 |
+
invokes the graph with it, and returns the final response.
|
21 |
+
|
22 |
+
Attributes:
|
23 |
+
graph: The compiled graph from `build_graph()` that processes messages.
|
24 |
+
"""
|
25 |
+
def __init__(self):
|
26 |
+
"""Initializes the BasicAgent by building its processing graph."""
|
27 |
+
print("BasicAgent initialized.")
|
28 |
+
# This function should be defined elsewhere in the code.
|
29 |
+
# It is expected to return a compiled LangChain graph.
|
30 |
+
self.graph = build_graph()
|
31 |
+
|
32 |
+
def __call__(self, question: str) -> str:
|
33 |
+
"""Processes a question using the agent's graph and returns the answer.
|
34 |
+
|
35 |
+
This method makes the agent instance callable. It wraps the user's
|
36 |
+
question in a HumanMessage, sends it through the processing graph,
|
37 |
+
and extracts the content from the final message in the response.
|
38 |
+
|
39 |
+
Args:
|
40 |
+
question: The question to be processed by the agent.
|
41 |
+
|
42 |
+
Returns:
|
43 |
+
The answer generated by the agent's graph as a string.
|
44 |
+
"""
|
45 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
46 |
+
# Wrap the question in a HumanMessage from langchain_core
|
47 |
+
messages = [HumanMessage(content=question)]
|
48 |
+
# The graph.invoke method takes a dictionary with the key "messages"
|
49 |
+
# and returns a dictionary with the processed messages.
|
50 |
+
response_messages = self.graph.invoke({"messages": messages})
|
51 |
+
# The answer is expected to be in the 'content' of the last message.
|
52 |
+
answer = response_messages['messages'][-1].content
|
53 |
+
print(f"Agent full response: {answer}")
|
54 |
+
return answer
|
55 |
+
|
56 |
+
|
57 |
+
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
58 |
+
"""
|
59 |
+
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
60 |
+
and displays the results.
|
61 |
+
"""
|
62 |
+
# --- Determine HF Space Runtime URL and Repo URL ---
|
63 |
+
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
64 |
+
|
65 |
+
if profile:
|
66 |
+
username= f"{profile.username}"
|
67 |
+
print(f"User logged in: {username}")
|
68 |
+
else:
|
69 |
+
print("User not logged in.")
|
70 |
+
return "Please Login to Hugging Face with the button.", None
|
71 |
+
|
72 |
+
api_url = DEFAULT_API_URL
|
73 |
+
questions_url = f"{api_url}/questions"
|
74 |
+
submit_url = f"{api_url}/submit"
|
75 |
+
|
76 |
+
# 1. Instantiate Agent ( modify this part to create your agent)
|
77 |
+
try:
|
78 |
+
agent = BasicAgent()
|
79 |
+
except Exception as e:
|
80 |
+
print(f"Error instantiating agent: {e}")
|
81 |
+
return f"Error initializing agent: {e}", None
|
82 |
+
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
83 |
+
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
84 |
+
print(agent_code)
|
85 |
+
|
86 |
+
# 2. Fetch Questions
|
87 |
+
print(f"Fetching questions from: {questions_url}")
|
88 |
+
try:
|
89 |
+
response = requests.get(questions_url, timeout=15)
|
90 |
+
response.raise_for_status()
|
91 |
+
questions_data = response.json()
|
92 |
+
if not questions_data:
|
93 |
+
print("Fetched questions list is empty.")
|
94 |
+
return "Fetched questions list is empty or invalid format.", None
|
95 |
+
print(f"Fetched {len(questions_data)} questions.")
|
96 |
+
except requests.exceptions.RequestException as e:
|
97 |
+
print(f"Error fetching questions: {e}")
|
98 |
+
return f"Error fetching questions: {e}", None
|
99 |
+
except requests.exceptions.JSONDecodeError as e:
|
100 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
101 |
+
print(f"Response text: {response.text[:500]}")
|
102 |
+
return f"Error decoding server response for questions: {e}", None
|
103 |
+
except Exception as e:
|
104 |
+
print(f"An unexpected error occurred fetching questions: {e}")
|
105 |
+
return f"An unexpected error occurred fetching questions: {e}", None
|
106 |
+
|
107 |
+
# 3. Run your Agent
|
108 |
+
results_log = []
|
109 |
+
answers_payload = []
|
110 |
+
print(f"Running agent on {len(questions_data)} questions...")
|
111 |
+
for item in questions_data:
|
112 |
+
task_id = item.get("task_id")
|
113 |
+
question_text = item.get("question")
|
114 |
+
if not task_id or question_text is None:
|
115 |
+
print(f"Skipping item with missing task_id or question: {item}")
|
116 |
+
continue
|
117 |
+
try:
|
118 |
+
submitted_answer = agent(question_text)
|
119 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
120 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
121 |
+
except Exception as e:
|
122 |
+
print(f"Error running agent on task {task_id}: {e}")
|
123 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
124 |
+
|
125 |
+
if not answers_payload:
|
126 |
+
print("Agent did not produce any answers to submit.")
|
127 |
+
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
128 |
+
|
129 |
+
# 4. Prepare Submission
|
130 |
+
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
131 |
+
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
132 |
+
print(status_update)
|
133 |
+
|
134 |
+
# 5. Submit
|
135 |
+
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
136 |
+
try:
|
137 |
+
response = requests.post(submit_url, json=submission_data, timeout=60)
|
138 |
+
response.raise_for_status()
|
139 |
+
result_data = response.json()
|
140 |
+
final_status = (
|
141 |
+
f"Submission Successful!\n"
|
142 |
+
f"User: {result_data.get('username')}\n"
|
143 |
+
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
144 |
+
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
145 |
+
f"Message: {result_data.get('message', 'No message received.')}"
|
146 |
+
)
|
147 |
+
print("Submission successful.")
|
148 |
+
results_df = pd.DataFrame(results_log)
|
149 |
+
return final_status, results_df
|
150 |
+
except requests.exceptions.HTTPError as e:
|
151 |
+
error_detail = f"Server responded with status {e.response.status_code}."
|
152 |
+
try:
|
153 |
+
error_json = e.response.json()
|
154 |
+
error_detail += f" Detail: {error_json.get('detail', e.response.text)}"
|
155 |
+
except requests.exceptions.JSONDecodeError:
|
156 |
+
error_detail += f" Response: {e.response.text[:500]}"
|
157 |
+
status_message = f"Submission Failed: {error_detail}"
|
158 |
+
print(status_message)
|
159 |
+
results_df = pd.DataFrame(results_log)
|
160 |
+
return status_message, results_df
|
161 |
+
except requests.exceptions.Timeout:
|
162 |
+
status_message = "Submission Failed: The request timed out."
|
163 |
+
print(status_message)
|
164 |
+
results_df = pd.DataFrame(results_log)
|
165 |
+
return status_message, results_df
|
166 |
+
except requests.exceptions.RequestException as e:
|
167 |
+
status_message = f"Submission Failed: Network error - {e}"
|
168 |
+
print(status_message)
|
169 |
+
results_df = pd.DataFrame(results_log)
|
170 |
+
return status_message, results_df
|
171 |
+
except Exception as e:
|
172 |
+
status_message = f"An unexpected error occurred during submission: {e}"
|
173 |
+
print(status_message)
|
174 |
+
results_df = pd.DataFrame(results_log)
|
175 |
+
return status_message, results_df
|
176 |
+
|
177 |
+
|
178 |
+
# --- Build Gradio Interface using Blocks ---
|
179 |
+
with gr.Blocks() as demo:
|
180 |
+
gr.Markdown("# Basic Agent Evaluation Runner")
|
181 |
+
gr.Markdown(
|
182 |
+
"""
|
183 |
+
**Instructions:**
|
184 |
+
|
185 |
+
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
186 |
+
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
187 |
+
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
188 |
+
|
189 |
+
---
|
190 |
+
**Disclaimers:**
|
191 |
+
Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
|
192 |
+
This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
|
193 |
+
"""
|
194 |
+
)
|
195 |
+
|
196 |
+
gr.LoginButton()
|
197 |
+
|
198 |
+
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
199 |
+
|
200 |
+
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
201 |
+
# Removed max_rows=10 from DataFrame constructor
|
202 |
+
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
203 |
+
|
204 |
+
run_button.click(
|
205 |
+
fn=run_and_submit_all,
|
206 |
+
outputs=[status_output, results_table]
|
207 |
+
)
|
208 |
+
|
209 |
+
if __name__ == "__main__":
|
210 |
+
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
211 |
+
# Check for SPACE_HOST and SPACE_ID at startup for information
|
212 |
+
space_host_startup = os.getenv("SPACE_HOST")
|
213 |
+
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
214 |
+
|
215 |
+
if space_host_startup:
|
216 |
+
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
217 |
+
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
218 |
+
else:
|
219 |
+
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
220 |
+
|
221 |
+
if space_id_startup: # Print repo URLs if SPACE_ID is found
|
222 |
+
print(f"✅ SPACE_ID found: {space_id_startup}")
|
223 |
+
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
224 |
+
print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
|
225 |
+
else:
|
226 |
+
print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
|
227 |
+
|
228 |
+
print("-"*(60 + len(" App Starting ")) + "\n")
|
229 |
+
|
230 |
+
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
231 |
+
demo.launch(debug=True, share=False)
|
232 |
+
|
old-tools.py → archive/old-tools.py
RENAMED
File without changes
|
retriever.py → archive/retriever.py
RENAMED
File without changes
|
scrapbook.py → archive/scrapbook.py
RENAMED
File without changes
|
system-prompt-claude.txt
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AI Agent System Prompt
|
2 |
+
|
3 |
+
You are an advanced AI agent equipped with multiple tools to solve complex, multi-step problems. You will encounter approximately 20 challenging questions that may require analysis, tool usage, and step-by-step reasoning.
|
4 |
+
|
5 |
+
## Core Capabilities
|
6 |
+
- Multi-tool integration via Python scripts
|
7 |
+
- Complex problem analysis and decomposition
|
8 |
+
- Step-by-step reasoning for multi-part questions
|
9 |
+
- File processing and data analysis
|
10 |
+
- Mathematical calculations and logical reasoning
|
11 |
+
|
12 |
+
## Analysis and Approach
|
13 |
+
1. **Question Analysis**: Always analyze the question first to understand:
|
14 |
+
- What information is being requested
|
15 |
+
- What tools or data sources might be needed
|
16 |
+
- Whether the question has multiple parts or steps
|
17 |
+
- If any preprocessing or data gathering is required
|
18 |
+
|
19 |
+
2. **Tool Selection**: Determine which tools are most appropriate:
|
20 |
+
- If files, documents, images, or URLs are mentioned, use download/file processing tools FIRST
|
21 |
+
- Use specialized analysis tools for different file types (CSV, Excel, images, etc.)
|
22 |
+
- Apply mathematical or computational tools for calculations
|
23 |
+
- Utilize web search or data retrieval tools when external information is needed
|
24 |
+
|
25 |
+
3. **Multi-Step Problem Solving**: For complex questions:
|
26 |
+
- Break down the problem into logical steps
|
27 |
+
- Execute each step systematically
|
28 |
+
- Use outputs from one tool as inputs for another when necessary
|
29 |
+
- Verify intermediate results before proceeding
|
30 |
+
|
31 |
+
## Tool Usage Guidelines
|
32 |
+
- **File Processing**: Always download and process files before attempting to answer questions about them
|
33 |
+
- **Data Analysis**: Use appropriate tools for different data formats (analyze_csv_file, analyze_excel_file, extract_text_from_image)
|
34 |
+
- **Calculations**: Employ mathematical tools for computations, statistical analysis, or complex calculations
|
35 |
+
- **Information Gathering**: Use search or retrieval tools when external knowledge is required
|
36 |
+
- **Chain Tools**: Combine multiple tools when a single tool cannot solve the complete problem
|
37 |
+
|
38 |
+
## Response Format
|
39 |
+
After completing your analysis and using necessary tools, provide ONLY your final answer with no additional text, explanations, or formatting.
|
40 |
+
|
41 |
+
### Answer Formatting Rules:
|
42 |
+
- **Numbers**: Provide just the number without commas, units, or symbols (unless specifically requested)
|
43 |
+
- **Text**: Use minimal words, no articles, no abbreviations, write digits in plain text
|
44 |
+
- **Lists**: Comma-separated values following the above rules for each element type
|
45 |
+
- **Precision**: Be exact and concise - include only what is specifically asked for
|
46 |
+
|
47 |
+
### Critical Response Rule:
|
48 |
+
- Do NOT include "FINAL ANSWER:" or any other prefixes/labels
|
49 |
+
- Do NOT include explanations, reasoning, or additional text
|
50 |
+
- Provide ONLY the answer itself - nothing else
|
51 |
+
|
52 |
+
## Process Flow
|
53 |
+
1. **Read and Analyze**: Carefully read the question and identify all requirements
|
54 |
+
2. **Plan**: Determine the sequence of tools and steps needed
|
55 |
+
3. **Execute**: Use tools systematically, processing outputs as needed
|
56 |
+
4. **Verify**: Check that your analysis addresses all parts of the question
|
57 |
+
5. **Answer**: Provide only the raw answer with no formatting, labels, or additional text
|
58 |
+
|
59 |
+
## Important Notes
|
60 |
+
- Some questions may appear simple but require multiple tools or steps
|
61 |
+
- Always prioritize accuracy over speed
|
62 |
+
- If a question has multiple parts, ensure all parts are addressed
|
63 |
+
- Use the most appropriate tool for each task
|
64 |
+
- Process any mentioned files, attachments, or external resources before answering
|
65 |
+
- Think through the problem systematically but provide only the final answer
|
66 |
+
|
67 |
+
Remember: Your goal is to provide accurate, precise answers to complex questions using the full range of available tools and capabilities. Your final response should contain ONLY the answer - no explanations, no "FINAL ANSWER:" prefix, no additional text whatsoever.
|
system-prompt.txt
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You are a general AI assistant. I will ask you a question.
|
2 |
+
Report your thoughts, and finish your answer with the following template:
|
3 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
4 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR
|
5 |
+
a comma separated list of numbers and/or strings. If you are asked for a number,
|
6 |
+
don't use comma to write your number neither use units such as $ or percent sign
|
7 |
+
unless specified otherwise.
|
8 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities),
|
9 |
+
and write the digits in plain text unless specified otherwise.
|
10 |
+
If you are asked for a comma separated list, apply the above rules depending of
|
11 |
+
whether the element to be put in the list is a number or a string.
|
12 |
+
|
13 |
+
|
14 |
+
---
|
15 |
+
|
16 |
+
You are a helpful AI assistant. When asked a question, think through it step by step and provide only the final answer.
|
17 |
+
|
18 |
+
CRITICAL INSTRUCTIONS:
|
19 |
+
- If the question mentions attachments, files, images, documents, or URLs, use the download_file tool FIRST to download them
|
20 |
+
- Use available tools when needed to gather information or perform calculations
|
21 |
+
- For file analysis, use appropriate tools (analyze_csv_file, analyze_excel_file, extract_text_from_image, etc.)
|
22 |
+
- After using tools and analyzing the information, provide ONLY the final answer
|
23 |
+
- Do not include explanations, reasoning, or extra text in your final response
|
24 |
+
- If the answer is a number, provide just the number (no units unless specifically requested)
|
25 |
+
- If the answer is text, provide just the essential text (no articles or extra words unless necessary)
|
26 |
+
- If the answer is a list, provide it as comma-separated values
|
27 |
+
|
28 |
+
Your response should contain ONLY the answer - nothing else.
|
29 |
+
|
30 |
+
---
|