Improve file writing and activity replay

This commit is contained in:
wuyang6
2026-05-12 20:48:25 +08:00
parent c118e010e3
commit 126f35ae46
6 changed files with 171 additions and 22 deletions
+30 -4
View File
@@ -40,21 +40,47 @@ def build_file_tools(handlers: Mapping[str, ToolHandler]) -> list[AgentTool]:
name='write_file',
description=(
'Write or append a UTF-8 text file inside the workspace. Creates parent directories when needed. '
'For multi-line content, prefer content_lines to reduce JSON escaping errors.'
'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.'
),
parameters={
'type': 'object',
'properties': {
'path': {'type': 'string', 'description': 'Relative path. output/, scratchpad/, and input/ route to the current session.'},
'content': {'type': 'string', 'description': 'Full text content for short or simple files.'},
'content_lines': {
'type': 'array',
'items': {'type': 'string'},
'description': 'Lines to join with "\\n"; recommended for scripts, markdown, CSV, and other multi-line text.',
'description': 'Lines to join with "\\n"; use this for normal text, scripts, markdown, and any multi-line content.',
},
'content': {
'type': 'string',
'description': 'Short one-line/simple text only. For multi-line or quote-heavy content use content_lines or structured fields.',
},
'content_base64': {
'type': 'string',
'description': 'Base64-encoded UTF-8 content. Use only when content contains many quotes or complex escaping.',
'description': 'Base64-encoded UTF-8 content. Use only if the content is already available as base64.',
},
'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.',
},
'jsonl_records': {
'type': 'array',
'items': {'type': 'object'},
'description': 'Objects to serialize as compact JSONL, one object per line. Use for .jsonl files.',
},
'csv_headers': {
'type': 'array',
'items': {'type': 'string'},
'description': 'Optional CSV header order. Use with csv_rows.',
},
'csv_rows': {
'type': 'array',
'items': {
'type': 'array',
'items': {'type': 'string'},
},
'description': 'Rows to serialize as CSV. Each row is an array of cell strings.',
},
'append': {
'type': 'boolean',