Skip to main content

Builtins API Reference

SelfReference

Durable backend for agent memory, context management, and fork orchestration.

Constructor

Key Methods

Memory Key Isolation

Each key has independent state:
  • History (conversation transcript)
  • Experiences (durable facts)
  • Summary state (compaction checkpoints)
  • Fork handles (child agent state)

Usage with @llm_chat

Runtime Primitives (via PyRepl)

When SelfRef is active, these are available in execute_code:

PyRepl

Persistent IPython REPL in a subprocess with runtime primitive support.

Constructor

Properties

Methods

Tools Provided

execute_code

Returns:
When used through the agent toolset, execute_code returns a natural-language summary. If code outputs images through display(Image(...)), an image-rich last expression, or ImgPath(...) / ImgUrl(...), the tool result becomes multimodal so the model can inspect the image.

reset_repl

Example

Custom Events

Execution Limits


FileToolset

Workspace-scoped file operations with stale-write protection.

Constructor

All paths are resolved relative to workspace. Path traversal above workspace is rejected.

Properties

Tools Provided

read_file

Returns line-numbered content: <lineno> | <content>.

read_image

Returns image as multimodal content (detail=“high”).

grep

Regex search over workspace files. path_pattern scopes which files to search.

sed

Regex find-and-replace within a line range. Protected by hash-based stale detection.

echo_into

Overwrite entire file. Protected by hash-based stale detection (file must be read first).

Stale-Write Protection

FileToolset tracks file hashes on read. If a file was modified externally between read and write, sed and echo_into will reject the write and ask the agent to re-read.

Example