mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-14 02:34:46 +08:00
feat: add artifacts logic (#8)
This commit is contained in:
@@ -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)]},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user