feat: add view_image tool and optimize web fetch tools

Add image viewing capability for vision-enabled models with ViewImageMiddleware and view_image_tool. Limit web_fetch tool output to 4096 characters to prevent excessive content. Update model config to support vision capability flag.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hetao
2026-01-29 13:44:04 +08:00
parent 73a5a7972e
commit 09d9c18a28
12 changed files with 390 additions and 13 deletions

View File

@@ -28,15 +28,12 @@ def present_file_tool(
Notes:
- You should call this tool after creating files and moving them to the `/mnt/user-data/outputs` directory.
- IMPORTANT: Do NOT call this tool in parallel with other tools. Call it separately.
- This tool can be safely called in parallel with other tools. State updates are handled by a reducer to prevent conflicts.
Args:
filepaths: List of absolute file paths to present to the user. **Only** files in `/mnt/user-data/outputs` can be presented.
"""
existing_artifacts = runtime.state.get("artifacts") or []
# Use dict.fromkeys to deduplicate while preserving order
new_artifacts = list(dict.fromkeys(existing_artifacts + filepaths))
runtime.state["artifacts"] = new_artifacts
# The merge_artifacts reducer will handle merging and deduplication
return Command(
update={"artifacts": new_artifacts, "messages": [ToolMessage("Successfully presented files", tool_call_id=tool_call_id)]},
update={"artifacts": filepaths, "messages": [ToolMessage("Successfully presented files", tool_call_id=tool_call_id)]},
)