fix: escape braces in f-string prompts in agentic_data_api.py to fix python syntax error

This commit is contained in:
aries_ckt
2026-02-28 18:33:11 +08:00
parent bf5aa5168e
commit 04df52f124

View File

@@ -1011,7 +1011,7 @@ print(json.dumps(summary, ensure_ascii=False))
@tool(
description="Retrieve relevant information from the knowledge base. "
"Use this tool when the user question involves content that may be "
'in the knowledge base. Parameters: {"query": "search query"}'
'in the knowledge base. Parameters: {{"query": "search query"}}'
)
async def knowledge_retrieve(query: str) -> str:
if not knowledge_resources:
@@ -1214,7 +1214,7 @@ print(json.dumps(summary, ensure_ascii=False))
"Supports pandas, numpy, matplotlib, json, os, etc. "
"Use this tool when you need to run Python code to process data, "
"generate charts, or perform calculations. "
'Parameters: {"code": "python code string"}'
'Parameters: {{"code": "python code string"}}'
)
async def code_interpreter(code: str) -> str:
"""Execute arbitrary Python code and return stdout/stderr.
@@ -2159,39 +2159,39 @@ Please always response in the same language as the user's input language.
1. Strictly follow the instructions of the loaded skill.
2. For each step, output Thought -> Phase -> Action -> Action Input.
3. Wait for the system to return Observation before deciding on the next step.
4. If the task requires generating an analysis report, the process is: `execute_skill_script_file` to execute extract_financials.py to extract data -> `execute_skill_script_file` to execute calculate_ratios.py to calculate ratios (system records results automatically) -> `execute_skill_script_file` to execute generate_charts.py to generate charts (system merges images automatically) -> call `html_interpreter(template_path=..., data={...only the analysis text you wrote})` to render the report (system merges data and images automatically) -> `terminate` to return summary.
5. If the task does not require generating a report, directly call terminate to return the final result. The Action Input format must be {"result": "final answer"}.
4. If the task requires generating an analysis report, the process is: `execute_skill_script_file` to execute extract_financials.py to extract data -> `execute_skill_script_file` to execute calculate_ratios.py to calculate ratios (system records results automatically) -> `execute_skill_script_file` to execute generate_charts.py to generate charts (system merges images automatically) -> call `html_interpreter(template_path=..., data={{...only the analysis text you wrote}})` to render the report (system merges data and images automatically) -> `terminate` to return summary.
5. If the task does not require generating a report, directly call terminate to return the final result. The Action Input format must be {{"result": "final answer"}}.
{skill_prompt_context}
{execution_instruction}
## Skill Execution Norms
### Resource Usage
- **Need to execute skill script** -> Use `execute_skill_script_file` with parameters {"skill_name": "skill name", "script_file_name": "script file name", "args": {parameters}}. This tool will automatically handle image copying and data recording.
- **Need to execute skill script** -> Use `execute_skill_script_file` with parameters {{"skill_name": "skill name", "script_file_name": "script file name", "args": {{parameters}}}}. This tool will automatically handle image copying and data recording.
- **Need to understand indicator definitions/analysis framework** -> Use `get_skill_resource` and specify the `references/xxx.md` path to read the reference document.
- **Encounter image file** -> If the model does not support image input, it will return an error prompt.
- **Need to generate report** -> Call `html_interpreter`, passing `template_path` (relative path of the template) and `data` (only the analysis text you wrote yourself. Since the backend will automatically merge the 30 data indicators and image URLs generated by previous tools, absolutely do not write these data indicators in `data`, otherwise it will cause truncation due to excessive length). **Do not use `code_interpreter` to generate the report, and there is no need to use `get_skill_resource` to read the template first**.
## Available Tools Description
1. **execute_skill_script_file** (recommended for executing skill scripts): Execute script files in the skills scripts directory, automatically handling post-processing such as copying images to the static directory and recording calculation results.
Parameters: {"skill_name": "skill name", "script_file_name": "script file name", "args": {parameters}}
- Example: {"skill_name": "{pre_matched_skill.metadata.name if pre_matched_skill else 'skill'}", "script_file_name": "calculate_ratios.py", "args": {"input_data": "..."}}
Parameters: {{"skill_name": "skill name", "script_file_name": "script file name", "args": {{parameters}}}}
- Example: {{"skill_name": "{pre_matched_skill.metadata.name if pre_matched_skill else 'skill'}", "script_file_name": "calculate_ratios.py", "args": {{"input_data": "..."}}}}
- **Must use this tool when executing skill scripts**, do not use shell_interpreter.
2. **get_skill_resource**: Read reference documents, configurations, templates, and other non-script resource files in the skill.
Parameters: {"skill_name": "skill name", "resource_path": "resource path"}
Parameters: {{"skill_name": "skill name", "resource_path": "resource path"}}
- Read reference document: {"skill_name": "{pre_matched_skill.metadata.name if pre_matched_skill else 'skill'}", "resource_path": "references/analysis_framework.md"}
- Note: The report template does not need to be read using this tool; directly use the template_path parameter of html_interpreter.
3. **execute_skill_script**: Execute the inline script defined in the skill (backup). Parameters: {"skill_name": "skill name", "script_name": "script name", "args": {"parameter name": "parameter value"}}
3. **execute_skill_script**: Execute the inline script defined in the skill (backup). Parameters: {{"skill_name": "skill name", "script_name": "script name", "args": {{"parameter name": "parameter value"}}}}
4. **shell_interpreter**: Execute shell/bash commands (only for non-skill script system commands, such as ls, cat, etc.).
Parameters: {"code": "shell command"}
Parameters: {{"code": "shell command"}}
- Each call is independent and does not retain state. If multi-step operations are needed, use `&&` or `;` to connect commands.
- **Note: Do not use this tool to execute skill scripts**, as it will not automatically handle images and data recording.
5. **html_interpreter**: Render HTML templates into web reports.
Recommended usage: {"template_path": "skill name/templates/template file.html", "data": {"PLACEHOLDER_KEY": "value", ...}, "title": "report title"}
Recommended usage: {{"template_path": "skill name/templates/template file.html", "data": {{"PLACEHOLDER_KEY": "value", ...}}, "title": "report title"}}
- The backend will automatically merge previous financial data calculation results into the template. You only need to return analysis paragraphs you wrote manually, such as `PROFITABILITY_ANALYSIS`, in the `data` dictionary, without including `COMPANY_NAME` or `REVENUE`, etc.
- Example: {"template_path": "financial-report-analyzer/templates/report_template.html", "data": {"PROFITABILITY_ANALYSIS": "From the data, profitability is good...", "SOLVENCY_ANALYSIS": "..."}, "title": "Financial Report Analysis"}
- Example: {{"template_path": "financial-report-analyzer/templates/report_template.html", "data": {{"PROFITABILITY_ANALYSIS": "From the data, profitability is good...", "SOLVENCY_ANALYSIS": "..."}}, "title": "Financial Report Analysis"}}
{available_images_hint}
6. **terminate**: Return the final answer when the task is completed. Action Input must be {"result": "your final answer content"}.
6. **terminate**: Return the final answer when the task is completed. Action Input must be {{"result": "your final answer content"}}.
{file_context}
{knowledge_context}
@@ -2229,7 +2229,7 @@ Please always response in the same language as the user's input language.
2. Autonomously select required tools based on requirements (do not follow a fixed order, select as needed).
3. For each step, output Thought -> Phase -> Action -> Action Input.
4. Wait for the system to return Observation before deciding on the next step.
5. When the task is completed, call the terminate tool to return the final result. The Action Input format must be {"result": "final answer"}.
5. When the task is completed, call the terminate tool to return the final result. The Action Input format must be {{"result": "final answer"}}.
6. **[Mandatory Rule] When the user requests generating a webpage, HTML report, or interactive report, the final presentation step must call `html_interpreter` to render it. It is forbidden to output HTML using only `code_interpreter` and then directly terminate. Correct process: code_interpreter writes to .html file -> html_interpreter(file_path=...) renders -> terminate.**
## Available Skills List (Pre-loaded)
@@ -2243,7 +2243,7 @@ When using a skill, the following rules must be followed:
After loading the skill, carefully read the **Core Workflow** section in SKILL.md and execute it in order. If a step explicitly states conditions to skip (such as when user intent is clear), directly skip to the next step; do not force the execution of every step. Prioritize producing results quickly, and perform iterative optimization in subsequent steps.
### 2. Resource Usage Timing
- **Need to calculate/process data** -> Use `execute_skill_script_file` to execute scripts in the skill's scripts directory (this tool automatically handles images and data recording). Parameters are {"skill_name": "skill name", "script_file_name": "script.py", "args": {parameters}}.
- **Need to calculate/process data** -> Use `execute_skill_script_file` to execute scripts in the skill's scripts directory (this tool automatically handles images and data recording). Parameters are {{"skill_name": "skill name", "script_file_name": "script.py", "args": {{parameters}}}}.
- **Need to understand indicator definitions/analysis framework** -> Use `get_skill_resource` and specify the `references/xxx.md` path to read the reference document.
- **Encounter image file** -> If the model does not support image input, it will return an error prompt.
@@ -2254,21 +2254,21 @@ Complete each workflow step before moving to the next. Do not mix multiple tool
- For report generation: Same as the principle above, must finally call `html_interpreter` to render.
## Available Tools Description
1. **select_skill**: Select the most relevant skill based on the user's query from the available skills list. Parameters: {"query": "search query"}
2. **load_skill**: Load skill content by skill name and file path. Parameters: {"skill_name": "skill name", "file_path": "skill file path"}
3. **execute_skill_script_file**: Execute script files in the skill's scripts directory. Parameters: {"skill_name": "skill name", "script_file_name": "script file name", "args": {parameters}}
4. **get_skill_resource**: Read reference documents in the skill. Parameters: {"skill_name": "skill name", "resource_path": "resource path"}
5. **execute_skill_script**: Execute the inline script defined in the skill. Parameters: {"skill_name": "skill name", "script_name": "script name", "args": {parameters}}
6. **shell_interpreter**: Execute shell/bash commands. Parameters: {"code": "shell command"}
7. **code_interpreter**: Execute arbitrary Python code. Parameters: {"code": "python code string"}
1. **select_skill**: Select the most relevant skill based on the user's query from the available skills list. Parameters: {{"query": "search query"}}
2. **load_skill**: Load skill content by skill name and file path. Parameters: {{"skill_name": "skill name", "file_path": "skill file path"}}
3. **execute_skill_script_file**: Execute script files in the skill's scripts directory. Parameters: {{"skill_name": "skill name", "script_file_name": "script file name", "args": {{parameters}}}}
4. **get_skill_resource**: Read reference documents in the skill. Parameters: {{"skill_name": "skill name", "resource_path": "resource path"}}
5. **execute_skill_script**: Execute the inline script defined in the skill. Parameters: {{"skill_name": "skill name", "script_name": "script name", "args": {{parameters}}}}
6. **shell_interpreter**: Execute shell/bash commands. Parameters: {{"code": "shell command"}}
7. **code_interpreter**: Execute arbitrary Python code. Parameters: {{"code": "python code string"}}
8. **load_file**: Load uploaded file info. Parameters: none.
9. **execute_analysis**: Execute quick analysis on uploaded Excel/CSV file. Parameters: none.
10. **knowledge_retrieve**: Retrieve relevant info from knowledge base. Parameters: {"query": "search query"}
11. **sql_query**: Execute a read-only SQL query against the selected database. Parameters: {"sql": "SELECT statement"}
10. **knowledge_retrieve**: Retrieve relevant info from knowledge base. Parameters: {{"query": "search query"}}
11. **sql_query**: Execute a read-only SQL query against the selected database. Parameters: {{"sql": "SELECT statement"}}
12. **load_tools**: Resolve required tools for the selected skill. Parameters: none.
13. **execute_tool**: Execute a tool by name with JSON args. Parameters: {"tool_name": "tool name", "args": {parameters}}
14. **html_interpreter**: Render an HTML template or file. Parameters: {"template_path": "template file path", "file_path": "absolute path to html file", "data": {parameters}}
15. **terminate**: Finish the task. Parameters: {"result": "final answer"}
13. **execute_tool**: Execute a tool by name with JSON args. Parameters: {{"tool_name": "tool name", "args": {{parameters}}}}
14. **html_interpreter**: Render an HTML template or file. Parameters: {{"template_path": "template file path", "file_path": "absolute path to html file", "data": {{parameters}}}}
15. **terminate**: Finish the task. Parameters: {{"result": "final answer"}}
{file_context}
{knowledge_context}