
Create read-only ellmer tools for multi-stream reviewed memory
Source:R/memory-tool.R
graft_tools.RdCreate a pair of ellmer::ToolDef tools so an agent can list eligible
reviewed streams for one host-chosen purpose and recall any eligible
stream on demand. Unlike graft_tool(), the model chooses which stream to
recall, but its argument is never authority by itself: every call checks
the host's streams allowlist (when supplied) and evaluates
eligible(stream) afresh before reading retained content.
Usage
graft_tools(
store,
purpose,
eligible,
streams = NULL,
list_name = "list_project_memory",
recall_name = "recall_project_memory",
max_streams = 100L,
max_text_bytes = 64 * 1024L
)Arguments
- store
A store returned by
graft_store()orgraft_store_postgres(). The handle remains private inside the tools.- purpose
The consultation purpose fixed by the host application.
- eligible
A required host-supplied one-argument function taking a stream name and returning one
TRUEorFALSEvalue. Evaluated for each candidate stream during listing and again on every recall invocation.- streams
Optional host allowlist of stream names:
NULLto discover accepted streams instoreforpurpose, a character vector of allowed stream names, or a zero-argument function returning a character vector of currently allowed stream names.- list_name
Tool name for listing eligible streams. Defaults to
"list_project_memory".- recall_name
Tool name for recalling one stream. Defaults to
"recall_project_memory".- max_streams
Maximum eligible accepted streams returned by the listing tool. Defaults to
100L.- max_text_bytes
Maximum total UTF-8 bytes of text previews returned for one recall invocation. Defaults to 64 KiB.
Value
A named list of two ellmer::ToolDef objects (list_name and
recall_name), ready for chat$set_tools(), deputy::Agent$new(), or
mcptools::mcp_server().
Details
The listing tool returns only streams whose current decision is "accept"
for purpose and for which eligible(stream) returns TRUE. Withdrawn
streams, streams for other purposes, ineligible streams, and total store
counts are never disclosed. When streams is supplied, only those stream
names are inspected.
The recall tool accepts one stream string argument, verifies it against
streams (when supplied) and eligible(stream), and returns the same
bounded ellmer::ContentToolResult, JSON payload, @extra$graft metadata,
and optional shinychat display metadata as graft_tool(). A stream not in
the host allowlist fails with the same graft_ineligible_error as an
ineligible stream.