Skip to content

Commit f49f5cf

Browse files
author
Francisco
committed
fix: pin tempfile output dir in CODE_FILE_HANDLING system instruction
- Replace multi-rule prompt with single sticky instruction - Inject `tempfile.tempdir = "/app/generated_files"` at top of all file-generating scripts to prevent phantom file failures in sandbox
1 parent 8159a13 commit f49f5cf

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/api/entities_api/orchestration/instructions/definitions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@
408408
"4. **FILE FACTORY:** You have NATIVE capabilities to generate downloadable files. "
409409
"If a user wants a report, summary, or data, you MUST write code to create a .docx, .csv, or .xlsx file."
410410
),
411+
"CODE_FILE_HANDLING": (
412+
"\n🔹 [STICKY SYSTEMS INSTRUCTION — PERMANENT]\n"
413+
"All Python code execution contexts must inject the following line at the top of every script "
414+
"that generates files using libraries that rely on tempfile "
415+
"(e.g., python-docx, openpyxl, matplotlib, pandas with Excel output):\n\n"
416+
"import tempfile; tempfile.tempdir = \"/app/generated_files\"\n\n"
417+
"This ensures all temporary and final files are written to the correct sandbox output directory."
418+
),
411419
"ADVANCED_ANALYSIS": (
412420
"\n1. Always save generated files locally during code execution.\n"
413421
"2. Do not display, preview, or open files in memory.\n"

src/api/entities_api/orchestration/instructions/include_lists.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from entities_api.orchestration.instructions.definitions import \
2-
LEVEL_3_WEB_USE_INSTRUCTIONS
1+
from entities_api.orchestration.instructions.definitions import LEVEL_3_WEB_USE_INSTRUCTIONS
32

43
L2_INSTRUCTIONS = [
54
"TOOL_USAGE_PROTOCOL",
65
"FUNCTION_CALL_FORMATTING",
76
"FUNCTION_CALL_WRAPPING",
87
"CODE_INTERPRETER", # code interpreter
8+
"CODE_FILE_HANDLING",
99
]
1010

1111
L3_INSTRUCTIONS = [
@@ -14,6 +14,7 @@
1414
"TOOL_DECISION_PROTOCOL",
1515
"L3_PARALLEL_EXECUTION",
1616
"CODE_INTERPRETER" # code interprete
17+
"CODE_FILE_HANDLING", # code interpreter
1718
"CITATION_PROTOCOL",
1819
"TOOL_USAGE_PROTOCOL",
1920
"FUNCTION_CALL_FORMATTING",

0 commit comments

Comments
 (0)