feat: persistent Python console — working memory outside the context - #176
Closed
KevRojo wants to merge 2 commits into
Closed
feat: persistent Python console — working memory outside the context#176KevRojo wants to merge 2 commits into
KevRojo wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new
Pythontool: 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
pyconsole.pydoubles 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.reprlibecho, so one enormous line or a hugerepr()can't flood the context and get re-billed every turn.input()is neutralised (cleanEOFError, never hangs the protocol), tracebacks are trimmed to the caller's frames, and a trailing bare expression echoes like a REPL.tools/auto-import — adds"pyconsole"to the tuple, matching the existingfiles/browser/emailsubmodules. Thecheetahclaws.tool_registryimport stays lazy so the worker subprocess never drags in the package.Verified
Registration through
tool_registry, state persistence across separateexecute_toolcalls, 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 incheetahclaws/tools/__init__.py.