2026-01-16 23:04:38 +08:00
|
|
|
from typing import Annotated
|
|
|
|
|
|
|
|
|
|
from langchain.tools import InjectedToolCallId, ToolRuntime, tool
|
|
|
|
|
from langchain_core.messages import ToolMessage
|
|
|
|
|
from langgraph.types import Command
|
|
|
|
|
from langgraph.typing import ContextT
|
|
|
|
|
|
|
|
|
|
from src.agents.thread_state import ThreadState
|
2026-01-16 21:48:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@tool("present_files", parse_docstring=True)
|
2026-01-16 23:04:38 +08:00
|
|
|
def present_file_tool(
|
|
|
|
|
runtime: ToolRuntime[ContextT, ThreadState],
|
|
|
|
|
filepaths: list[str],
|
|
|
|
|
tool_call_id: Annotated[str, InjectedToolCallId],
|
|
|
|
|
) -> Command:
|
2026-01-16 21:48:00 +08:00
|
|
|
"""Make files visible to the user for viewing and rendering in the client interface.
|
|
|
|
|
|
|
|
|
|
When to use the present_files tool:
|
|
|
|
|
|
|
|
|
|
- Making any file available for the user to view, download, or interact with
|
|
|
|
|
- Presenting multiple related files at once
|
2026-01-16 22:10:08 +08:00
|
|
|
- After creating files that should be presented to the user
|
2026-01-16 21:48:00 +08:00
|
|
|
|
|
|
|
|
When NOT to use the present_files tool:
|
|
|
|
|
- When you only need to read file contents for your own processing
|
|
|
|
|
- For temporary or intermediate files not meant for user viewing
|
|
|
|
|
|
2026-01-16 22:10:08 +08:00
|
|
|
Notes:
|
|
|
|
|
- You should call this tool after creating files and moving them to the `/mnt/user-data/outputs` directory.
|
2026-01-29 13:44:04 +08:00
|
|
|
- This tool can be safely called in parallel with other tools. State updates are handled by a reducer to prevent conflicts.
|
2026-01-16 22:10:08 +08:00
|
|
|
|
2026-01-16 21:48:00 +08:00
|
|
|
Args:
|
|
|
|
|
filepaths: List of absolute file paths to present to the user. **Only** files in `/mnt/user-data/outputs` can be presented.
|
|
|
|
|
"""
|
2026-01-29 13:44:04 +08:00
|
|
|
# The merge_artifacts reducer will handle merging and deduplication
|
2026-01-16 23:04:38 +08:00
|
|
|
return Command(
|
2026-01-29 13:44:04 +08:00
|
|
|
update={"artifacts": filepaths, "messages": [ToolMessage("Successfully presented files", tool_call_id=tool_call_id)]},
|
2026-01-16 23:04:38 +08:00
|
|
|
)
|