Skip to content

feat: persistent Python console — working memory outside the context - #176

Closed
KevRojo wants to merge 2 commits into
SAIL-Research-Lab:mainfrom
KevRojo:python-console
Closed

feat: persistent Python console — working memory outside the context#176
KevRojo wants to merge 2 commits into
SAIL-Research-Lab:mainfrom
KevRojo:python-console

Conversation

@KevRojo

@KevRojo KevRojo commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

A new Python tool: a persistent REPL whose namespace survives across calls. Scan a large structure once into a variable and it stays alive in the kernel's heap — filter, count, and aggregate it across turns while the model only ever prints the small slice it needs.

Why

When an agent explores something big (a directory tree, a parsed file, an API dump), the result normally lands in the conversation and gets re-sent every turn for the rest of the session — you end up paying to re-read the search forever. Keeping the data in a live kernel heap instead of the context means only small slices ever cost tokens. Working memory outside the context window.

Example: 101,619 files scanned into a variable, then queried three ways across separate calls — the context only ever saw a number, an 8-line slice, and a one-line summary.

How it's built

  • Isolated subprocess kernelpyconsole.py doubles as the worker via --pykernel-worker; an infinite loop or crash kills the kernel, never the agent. The parent enforces a wall-clock timeout and auto-restarts a dead/killed kernel on the next call.
  • Output capped at the source by characters (not just lines) with a bounded reprlib echo, so one enormous line or a huge repr() can't flood the context and get re-billed every turn.
  • input() is neutralised (clean EOFError, never hangs the protocol), tracebacks are trimmed to the caller's frames, and a trailing bare expression echoes like a REPL.
  • Self-registers through the tools/ auto-import — adds "pyconsole" to the tuple, matching the existing files/browser/email submodules. The cheetahclaws.tool_registry import stays lazy so the worker subprocess never drags in the package.

Verified

Registration through tool_registry, state persistence across separate execute_tool calls, REPL echo, giant-line / huge-repr caps, input() no-hang, and timeout-kills-a-runaway-loop + auto-restart. Pyright-clean.

Scope: two files — new cheetahclaws/tools/pyconsole.py, one line in cheetahclaws/tools/__init__.py.

KevRojo added 2 commits July 28, 2026 15:56
…ontext

A new `Python` tool: a REPL whose namespace persists across calls, so the
agent scans a large structure once into a variable and queries it across turns
while only small slices ever enter the conversation. The bulk lives in the
kernel's heap, not the context, so it is never re-read or re-transmitted.

Runs in an isolated subprocess kernel (this module doubles as the worker via
--pykernel-worker), so an infinite loop or crash kills the kernel, never the
agent; the parent enforces a wall-clock timeout and auto-restarts a dead/killed
kernel. Output is capped at the source by characters (not just lines) with a
bounded reprlib echo, so one giant line or a huge repr can't flood the context
and get re-billed every turn. input() is neutralised, tracebacks are trimmed to
the caller's frames, and trailing bare expressions echo like a REPL.

Self-registers through the tools/ auto-import (adds "pyconsole" to the tuple),
matching the existing files/browser/email submodules.
Registering the Python console adds `Python` to the enabled-tools line in the
system prompt, so the e2e_prompt_regression golden fixture drifts. Insert
`Python` in its alphabetical slot (between NotebookEdit and Read) to match.
@KevRojo KevRojo closed this by deleting the head repository Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant