Skip to content

API Reference parrot.tools.working_memory.tool

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.working_memory.tool

View source

WorkingMemoryToolkit: Intermediate result store for long-running analytical operations.

Alias AbstractToolkit

Re-exported from parrot.tools.toolkit.AbstractToolkit.

Alias AggFunc

Re-exported from parrot.tools.working_memory.models.AggFunc.

Alias CatalogEntry

Re-exported from parrot.tools.working_memory.internals.CatalogEntry.

Alias ComputeAndStoreInput

Re-exported from parrot.tools.working_memory.models.ComputeAndStoreInput.

Alias DropStoredInput

Re-exported from parrot.tools.working_memory.models.DropStoredInput.

Alias EnabledGetResultInput

Re-exported from parrot.tools.working_memory.models.EnabledGetResultInput.

Alias EntryType

Re-exported from parrot.tools.working_memory.models.EntryType.

Alias GenericEntry

Re-exported from parrot.tools.working_memory.internals.GenericEntry.

Alias GetResultInput

Re-exported from parrot.tools.working_memory.models.GetResultInput.

Alias GetStoredInput

Re-exported from parrot.tools.working_memory.models.GetStoredInput.

Alias ImportFromToolInput

Re-exported from parrot.tools.working_memory.models.ImportFromToolInput.

Alias ListStoredInput

Re-exported from parrot.tools.working_memory.models.ListStoredInput.

Alias ListToolDataFramesInput

Re-exported from parrot.tools.working_memory.models.ListToolDataFramesInput.

Alias MergeStoredInput

Re-exported from parrot.tools.working_memory.models.MergeStoredInput.

Alias OperationExecutor

Re-exported from parrot.tools.working_memory.internals.OperationExecutor.

Alias OperationSpecInput

Re-exported from parrot.tools.working_memory.models.OperationSpecInput.

Alias RecallInteractionInput

Re-exported from parrot.tools.working_memory.models.RecallInteractionInput.

Alias SaveInteractionInput

Re-exported from parrot.tools.working_memory.models.SaveInteractionInput.

Alias SearchStoredInput

Re-exported from parrot.tools.working_memory.models.SearchStoredInput.

Alias ShapeLimit

Re-exported from parrot.tools.working_memory.internals.ShapeLimit.

Alias StoreInput

Re-exported from parrot.tools.working_memory.models.StoreInput.

Alias StoreResultInput

Re-exported from parrot.tools.working_memory.models.StoreResultInput.

Alias SummarizeStoredInput

Re-exported from parrot.tools.working_memory.models.SummarizeStoredInput.

Alias TASK_TOOL_METHODS

Re-exported from parrot.tools.working_memory.task_memory.tools.TASK_TOOL_METHODS.

Alias TaskMemoryToolsMixin

Re-exported from parrot.tools.working_memory.task_memory.tools.TaskMemoryToolsMixin.

Alias WorkingMemoryCatalog

Re-exported from parrot.tools.working_memory.internals.WorkingMemoryCatalog.

Class WorkingMemoryToolkit

Intermediate result store for long-running analytical operations.

Every public async method is automatically exposed as an agent tool by AbstractToolkit. Pydantic models validate inputs via @tool_schema.

The agent NEVER sees raw DataFrames — only compact summaries (shape, dtypes, stats, small preview). Generic (non-DataFrame) entries are also summarised in a type-aware manner.

An optional AnswerMemory bridge allows the agent to save and recall Q&A interactions directly through the toolkit. Auto-injected by BasicAgent.configure() when a WorkingMemoryToolkit is found registered.

Methods (agent-callable tools) ────────────────────────────── store : Store a DataFrame directly store_result : Store any Python object (text, dict, list, bytes, …) drop_stored : Remove a stored entry (any type) get_stored : Get summary of a stored DataFrame get_result : Get summary of a stored generic entry search_stored : Find entries by key/description substring or type list_stored : List all stored entries (all types) compute_and_store : Execute DSL operation and store result merge_stored : Merge multiple stored DataFrames into one summarize_stored : Aggregate multiple stored DataFrames import_from_tool : Bridge — import from PandasTool/REPLTool list_tool_dataframes : Discover DataFrames in other tools save_interaction : Save Q&A pair to AnswerMemory (bridge) recall_interaction : Recall Q&A pair from AnswerMemory (bridge)

Parameter Type Default Description
session_id Optional[str] None Optional session identifier for the working memory catalog.
max_rows int 10 Max rows in summary previews returned to the LLM.
max_cols int 30 Max columns in summary previews returned to the LLM.
tool_locals_registry Optional[dict[str, dict]] None Dict mapping tool names to a REPL namespace snapshot dict, e.g. {"PythonPandasTool": {...}, "PythonREPLTool": {...}}. FEAT-380 (TASK-1944): the REPL namespace lives in each tool's worker process now, so these are snapshots frozen at wiring time (await tool.snapshot() — namespace API), not a live reference; DataFrames the agent loads AFTER wiring runs are not automatically visible here. BasicAgent.configure() auto-wires this from any registered REPL-family tool; explicit wiring takes precedence and is never overwritten.
answer_memory Optional[Any] None Optional AnswerMemory instance for the Q&A bridge. Typically auto-injected by BasicAgent.configure() — explicit wiring takes precedence over auto-injection.
thread_offload_cells Optional[int] None Cell-count (rows × cols) threshold at or above which DataFrame copy/summary work is offloaded to a worker thread. Defaults to :attr:DEFAULT_THREAD_OFFLOAD_CELLS.
task_memory Optional[Any] None
**kwargs {}

Attributes:

Attribute Type Description
name str
tool_prefix str
exclude_tools tuple[str, ...]
description str
DEFAULT_THREAD_OFFLOAD_CELLS int
task_memory_enabled bool Whether task memory is configured for this toolkit.
DEFAULT_MAX_REHYDRATE_BYTES int

Method WorkingMemoryToolkit.from_runtime

Build a toolkit over a runtime's ALREADY-CONNECTED stores.

The point of routing through the runtime is that the toolkit, the observer and the plan factory then hold the same task store and the same artifact store. Constructing a toolkit's backend separately is how a deployment ends up with a sibling artifact store: writes land in one, evidence is validated against the other, and every completion is refused for reasons that make no sense from the outside.

from_runtime(runtime: Any, scope: Any, **kwargs: Any) -> 'WorkingMemoryToolkit'

Parameter Type Default Description
runtime Any A started :class:~parrot.tools.working_memory.task_memory.config.TaskMemoryRuntime.
scope Any The trusted runtime scope for this toolkit.
**kwargs Any {} Forwarded to the constructor.

Returns: 'WorkingMemoryToolkit' — The toolkit, wired to the shared backends.

Method WorkingMemoryToolkit.store

Store a DataFrame directly into working memory.

store(key: str, df: pd.DataFrame, description: str = '', turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
key str
df pd.DataFrame
description str ''
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.store_result

Store any intermediate result (text, dict, list, AIMessage, bytes, etc.) into working memory for later retrieval.

Use data_type="auto" (default) to let the toolkit infer the type. Explicit values: text, json, message, binary, object.

store_result(key: str, data: Any, data_type: str = 'auto', description: str = '', metadata: Optional[dict] = None, turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
key str
data Any
data_type str 'auto'
description str ''
metadata Optional[dict] None
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.drop_stored

Remove a stored entry (DataFrame or generic) from working memory.

drop_stored(key: str) -> dict

Parameter Type Default Description
key str

Returns: dict

Method WorkingMemoryToolkit.get_stored

Get a compact summary of a stored DataFrame (shape, stats, preview). The LLM uses this to inspect intermediate results without loading raw data.

get_stored(key: str, max_rows: Optional[int] = None, max_cols: Optional[int] = None) -> dict

Parameter Type Default Description
key str
max_rows Optional[int] None
max_cols Optional[int] None

Returns: dict

Method WorkingMemoryToolkit.get_result

Retrieve a stored generic result with a type-aware compact summary.

get_result(key: str, max_length: int = 500, include_raw: bool = False, max_rehydrate_bytes: Optional[int] = None, offset: int = 0, limit: Optional[int] = None) -> dict

Parameter Type Default Description
key str The key of the entry to retrieve.
max_length int 500 Maximum characters for text/content preview truncation.
include_raw bool False When True, the raw data object is included in the response under raw_data (non-serialisable objects are repr()-truncated).
max_rehydrate_bytes Optional[int] None
offset int 0
limit Optional[int] None

Returns: dict

Method WorkingMemoryToolkit.search_stored

Search stored entries by key or description substring, optionally filtered by type.

search_stored(query: str, entry_type: Optional[str] = None) -> dict

Parameter Type Default Description
query str Case-insensitive substring to match against entry key or description. Pass an empty string to match all entries (useful for type-only filtering).
entry_type Optional[str] None Optional type filter: text, json, message, binary, object, or dataframe.

Returns: dict

Method WorkingMemoryToolkit.list_stored

List all entries in working memory with compact summaries (all types).

list_stored(turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.compute_and_store

Execute a declarative data operation (DSL) and store the result. The agent sends a structured spec — never arbitrary code. Operations: filter, aggregate, join, merge, correlate, pivot, rank, window, sort, select, rename, fillna, drop_duplicates, group_correlate, describe.

compute_and_store(spec: Union[OperationSpecInput, dict], turn_id: Optional[str] = None, description: str = '') -> dict

Parameter Type Default Description
spec Union[OperationSpecInput, dict]
turn_id Optional[str] None
description str ''

Returns: dict

Method WorkingMemoryToolkit.merge_stored

Merge multiple stored DataFrames into one. If merge_on is provided, performs sequential joins on a common key. Otherwise concatenates vertically (same schema) or horizontally (different schemas).

merge_stored(keys: list[str], store_as: str, merge_on: Optional[str] = None, merge_how: str = 'outer', turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
keys list[str]
store_as str
merge_on Optional[str] None
merge_how str 'outer'
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.summarize_stored

Merge + aggregate stored DataFrames in one step.

  1. Merges all specified keys into a single DataFrame.
  2. Applies aggregation rules.
  3. Stores the summarized result.

summarize_stored(keys: list[str], store_as: str, agg_rules: dict[str, str], group_by: Optional[list[str]] = None, merge_on: Optional[str] = None, turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
keys list[str]
store_as str
agg_rules dict[str, str]
group_by Optional[list[str]] None
merge_on Optional[str] None
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.import_from_tool

Import a DataFrame from another tool's namespace (PythonPandasTool, PythonREPLTool) into working memory. Deep copies the data to decouple from the source tool.

import_from_tool(tool_name: str, variable_name: str, store_as: str, description: str = '', turn_id: Optional[str] = None) -> dict

Parameter Type Default Description
tool_name str
variable_name str
store_as str
description str ''
turn_id Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.list_tool_dataframes

Discover DataFrames available in other registered tools' namespaces. Helps the agent find data to import.

list_tool_dataframes(tool_name: Optional[str] = None) -> dict

Parameter Type Default Description
tool_name Optional[str] None

Returns: dict

Method WorkingMemoryToolkit.save_interaction

Save a question/answer pair to the agent's AnswerMemory, keyed by turn_id.

Useful for persisting important exchanges that the LLM may need to recall later. Returns an error dict when no AnswerMemory has been configured.

save_interaction(turn_id: str, question: str, answer: str) -> dict

Parameter Type Default Description
turn_id str
question str
answer str

Returns: dict

Method WorkingMemoryToolkit.recall_interaction

Recall a previous Q&A interaction from AnswerMemory.

Lookup modes:

  • By turn_id: exact match (fast, preferred when id is known).
  • By query: case-insensitive substring match against stored questions; returns the most recently stored match.

At least one of turn_id or query must be provided.

If import_as is given, the retrieved interaction is also stored into the working memory catalog as a GenericEntry (entry_type=json) so it can be referenced by downstream tools.

Returns an error dict when no AnswerMemory has been configured or when the lookup finds nothing.

recall_interaction(turn_id: Optional[str] = None, query: Optional[str] = None, import_as: Optional[str] = None) -> dict

Parameter Type Default Description
turn_id Optional[str] None
query Optional[str] None
import_as Optional[str] None

Returns: dict

Alias tool_schema

Re-exported from parrot.tools.decorators.tool_schema.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally