How to activate the agentic mode of TableGPT-R1 when input contains csv path?
Problem
I run TableGPT-R1 with tables represented as csv path in the user prompt. I tried different user prompts but all attempts fail to activate the agentic mode. The model refused to call tools (Python) with , and it simply output ... followed by the answer. It believes it can not access files and can not run code. Examples include:
[{"role": "system", "content": "\nYou are a helpful assistant.\n"},
{"role": "user", "content": "Given access to several csv files, write the Python code to answer the user's question.\nQuestion: What are the respective total income before tax in 2017 and 2018?\n#Filepath: [/mnt/data/DID_202411_TAT_574.csv]\nThe final answer **must be enclosed in `\\boxed{...}`**, and there should not be '$' symbols around it and no '' in the box."},
{"role": "assistant", "content": "<think>\nOkay, let's see. The user wants me to find the total income before tax for 2017 and 2018 from the given CSV file. Hmm, first I need to figure out how to read the CSV file using Python. Oh right, pandas is the way to go here.\n\nSo, I'll start by importing pandas. Then load the CSV file into a DataFrame. Wait, the file path is provided as /mnt/data/DID_202411_TAT_574.csv. I should make sure that the file exists at that location. But maybe the user has already set up the environment correctly.\n\nOnce the data is loaded, I need to inspect the columns to understand what they represent. Maybe there's a column for 'Year' or 'Date', and another for 'Income Before Tax'. Let me think. If the CSV has rows with years and corresponding income figures, I can filter the rows where the year is 2017 and 2018, then sum the income values.\n\nAlternatively, maybe each row represents a different entity (like companies) and we need to aggregate all their incomes for those two years. The question says \"total income before tax\", so probably summing across all entries for each year.\n\nFirst step: Load the data.\n\nimport pandas as pd\n\ndf = pd.read_csv('/mnt/data/DID_202411_TAT_574.csv')\n\nThen check the columns:\n\nprint(df.columns)\n\nAssuming the columns might be something like 'Year', 'Income_Before_Tax', etc. Or maybe 'Date' and 'Amount'.\n\nIf the data isn't immediately clear, perhaps looking at the first few rows would help.\n\nprint(df.head())\n\nBut since I can't actually run this code here, I have to proceed based on typical structures. Let's assume there's a 'Year' column and an 'Income_Before_Tax' column.\n\nThen, filter for 2017 and 2018:\n\nincome_2017 = df[df['Year'] == 2017]['Income_Before_Tax'].sum()\nincome_2018 = df[df['Year'] == 2018]['Income_Before_Tax'].sum()\n\nThen output these values.\n\nWait, but maybe the years are stored differently, like as strings. So checking if the 'Year' column is numeric or needs conversion.\n\nAlso, ensure that the column names match exactly. For example, if the column is named 'Year' vs 'year', case sensitivity matters.\n\nPutting it all together, the code would look something like:\n\nimport pandas as pd\n\n# Load the CSV file\ndf = pd.read_csv('/mnt/data/DID_202411_TAT_574.csv')\n\n# Display column names to understand structure\nprint(df.columns)\n\n# Assuming columns are 'Year' and 'Income_Before_Tax'\n# Filter for 2017 and 2018\ntotal_2017 = df[df['Year'] == 2017]['Income_Before_Tax'].sum()\ntotal_2018 = df[df['Year'] == 2018]['Income_Before_Tax'].sum()\n\nprint(\"Total income before tax in 2017:\", total_2017)\nprint(\"Total income before tax in 2018:\", total_2018)\n\nBut since I don't know the actual column names, this could fail. However, given the problem statement, this is the general approach. The user will need to adjust column names if necessary.\n\nFinally, enclose the answers in \\boxed{} without any $ signs. So the final answer would be boxed numbers for 2017 and 2018 totals.\n\n**Final Answer**\n\\boxed{<value_for_2017>} and \\boxed{<value_for_2018>}\n</think>\n\n\\boxed{<value_for_2017>} and \\boxed{<value_for_2018>}"}]
Could you please help me with instructions on how to activate the agentic mode? Many thanks.
Thank you for raising this important question.This is often not a limitation of the model's capability, but rather a result of the System Prompt not being explicit and constrained enough to guide the model's behavior. The key to activating TableGPT-R1's Agentic mode is to provide a structured, high-constraint SYSTEM_PROMPT. Below is an example that significantly increases the model's success rate in following instructions and performing tool calls by utilizing XML tags and clearly defined steps.
SYSTEM_PROMPT = """You are provided with function signatures within <tools></tools> XML tags:
<tools>
{"type": "function", "function": {"name": "python_repl", "description": "A Python shell. Use this to execute python commands. If you want to see the output of a value, you should print it out with `print(...)`. ", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": "The Python code snippet to execute."}, "required": ["code"]}}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
---
You are an AI assistant specialized in data analysis using Python and Pandas. Follow this structured workflow:
## Workflow:
1. **Analyze the Problem**
Clearly outline your reasoning in <think></think> tags. Specify:
- The information needed
- The analysis steps
2. **Tool Call**
To inspect or analyze a DataFrame (e.g., preview data, statistics, missing values), call the `python_repl` tool in <tool_call></tool_call> tags. Example:
<tool_call>
{
"name": "python_repl",
"arguments": {
"code": "your python code here"
}
}
</tool_call>
3. **Review Tool Output**
The tool's response will be wrapped in <observation></observation>. Analyze it to determine the next step.
Repeat steps 1–3 until you have sufficient information.
4. **Final Answer**
Once the analysis is complete, provide a concise summary.
---
## Context:
- Relevant information of the table:
{table_infos}
- Current time: {current_time}
## Rules:
- **No assumptions**: Always query the DataFrame directly.
"""
Thanks. it works~