feat: add artifacts logic (#8)

This commit is contained in:
DanielWalnut
2026-01-16 23:04:38 +08:00
committed by GitHub
parent 6464a67230
commit facde645d7
6 changed files with 129 additions and 7 deletions

View File

@@ -1,8 +1,19 @@
from langchain.tools import tool
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
@tool("present_files", parse_docstring=True)
def present_file_tool(filepaths: list[str]) -> str:
def present_file_tool(
runtime: ToolRuntime[ContextT, ThreadState],
filepaths: list[str],
tool_call_id: Annotated[str, InjectedToolCallId],
) -> Command:
"""Make files visible to the user for viewing and rendering in the client interface.
When to use the present_files tool:
@@ -22,4 +33,9 @@ def present_file_tool(filepaths: list[str]) -> str:
Args:
filepaths: List of absolute file paths to present to the user. **Only** files in `/mnt/user-data/outputs` can be presented.
"""
return "OK"
existing_artifacts = runtime.state.get("artifacts") or []
new_artifacts = existing_artifacts + filepaths
runtime.state["artifacts"] = new_artifacts
return Command(
update={"artifacts": new_artifacts, "messages": [ToolMessage("Successfully presented files", tool_call_id=tool_call_id)]},
)