Prefer python exec for complex file writes

This commit is contained in:
wuyang6
2026-05-13 16:35:17 +08:00
parent a9f229d222
commit 9984d35d1f
3 changed files with 20 additions and 16 deletions
+8 -7
View File
@@ -39,9 +39,10 @@ def build_file_tools(handlers: Mapping[str, ToolHandler]) -> list[AgentTool]:
AgentTool(
name='write_file',
description=(
'Write or append a UTF-8 text file inside the workspace. Creates parent directories when needed. '
'Use content_lines for text/scripts/markdown. Use json_content, jsonl_records, or csv_rows for structured data '
'so the tool serializes the file instead of forcing the model to escape large strings.'
'Write or append a SMALL UTF-8 file inside the workspace. Creates parent directories when needed. '
'Use this for short notes, lightweight markdown, and small config files. '
'For Python scripts, JSONL, large JSON/CSV, generated datasets, or quote-heavy/multi-line content, prefer python_exec '
'to write the file with pathlib/json/csv; do not pack large content into tool arguments.'
),
parameters={
'type': 'object',
@@ -50,11 +51,11 @@ def build_file_tools(handlers: Mapping[str, ToolHandler]) -> list[AgentTool]:
'content_lines': {
'type': 'array',
'items': {'type': 'string'},
'description': 'Lines to join with "\\n"; use this for normal text, scripts, markdown, and any multi-line content.',
'description': 'Lines to join with "\\n"; use only for short text/markdown or small scripts. For long scripts use python_exec to create the file.',
},
'content': {
'type': 'string',
'description': 'Short one-line/simple text only. For multi-line or quote-heavy content use content_lines or structured fields.',
'description': 'Short one-line/simple text only. Never use for multi-line scripts, JSON, JSONL, CSV, or quote-heavy content.',
},
'content_base64': {
'type': 'string',
@@ -62,12 +63,12 @@ def build_file_tools(handlers: Mapping[str, ToolHandler]) -> list[AgentTool]:
},
'json_content': {
'type': 'object',
'description': 'JSON value to serialize with ensure_ascii=false and indent=2. Use for .json files instead of stringifying JSON manually.',
'description': 'Small JSON value to serialize with ensure_ascii=false and indent=2. For large JSON use python_exec streaming write.',
},
'jsonl_records': {
'type': 'array',
'items': {'type': 'object'},
'description': 'Objects to serialize as compact JSONL, one object per line. Use for .jsonl files.',
'description': 'Small list of objects to serialize as compact JSONL. For more than a few dozen records or generated datasets use python_exec.',
},
'csv_headers': {
'type': 'array',