Repository navigation
Agent: give every task a persistent python scratchpad - #1410
Draft
AnthonyRonning wants to merge 2 commits into
Draft
AnthonyRonning wants to merge 2 commits into
AnthonyRonning wants to merge 2 commits into
Conversation
Port #897's task binding onto Pi as Maple's `python` tool. Each loaded task gets one bundled-CPython interpreter, started on its first call in the task's project with the shell's PATH and AGENT_SESSION_ID, keeping variables, imports and background asyncio work between calls. The tool declares Pi's sequential execution mode, which replaces #897's Goose scheduler: a batch with a python call runs in the order the model made it. Goose-era choices are dropped: there is no approval card or Reset Python menu, and capacity no longer surfaces to the user. When all four interpreters exist, the least recently used idle scratchpad of another task is discarded. Archiving a task, archiving or removing its project, unloading it and stopping Maple discard or retire it, and the model is told on its next call; a task reloaded with history starts fresh and says so. The result text, reset and Stop semantics, and the transcript title come from #897. Builds without a bundled runtime offer no tool; `just build` prepares one beside the debug binary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AnthonyRonning
force-pushed
the
agent/python-tool
branch
from
November 2, 2026 01:20
792b7f4 to
6539c05
Compare
This branch has not been deployed
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.
Second layer of the CodeMode catch-up stack, on PR #1409 (the runtime). It gives every Maple Work task
python: a persistent CPython scratchpad that sits beside the shell, read and edit tools. This is the feature PR #897 built on Goose, re-ported onto the Pi runtime.What the model gets
AGENT_SESSION_ID).Noneexpression is shown and kept in_. Top-levelawaitruns on one long-lived event loop.{code, reset?}. Results carry stdout, stderr, the value or traceback, bounded output with truncation counts, and a state-loss notice whenever earlier state is gone.pythonis the one OpenAI's gpt-oss models were trained on.executetool calls. There is no Python-specific UI.What changed from #897
Goose forced most of #897's integration; Pi needs much less of it.
Sequentialexecution mode. That replaces the Goose fork's ordered-call scheduler and its 32-call cap. Pi runs the whole batch in call order, so other tools in a batch with apythoncall wait their turn too. Prime Agent, a Pi fork with the same design, does exactly this. The pi crates are unchanged.pythonruns likebash.reset.Why this design (research summary)
We compared CodeMode in upstream Pi (
codemode: stateless JavaScript in QuickJS, for composing tool calls), Codex (exec), OpenCode (execute), Goose (code_execution), Prime Agent (python_repl) and oh-my-pi (eval).Builds
just buildandjust runprepare the pinned runtime beside the debug binary (target/debug/runtime/python). An executable without a bundled runtime offers nopythontool, so release builds are unchanged until the packaging layer lands.Validation
cargo test -p maple-agent tools::python: persistence across calls, explicit reset, the notice on reload with history, freeing a slot by discarding the least recently used idle scratchpad (it reports the loss on its next call), archive discard, reset-only calls without starting Python, and the environment. All run against the real CPython 3.14.7 interpreter.python_title_tests: the title test ported from Port bundled CPython and ordered CodeMode into Maple Agent #897.just ci-lintandjust ci-test) passed. One app test failed once under the hook and passed on rerun (all 1,179 app tests pass).End-to-end with a real model (local stack, over ACP)
The setup:
deepseek-v4-1-flash.orders.csv.The run:
pythontwice. The rows read "Python: import csv, collections" and are ACP kindexecute.pbs-20260929-aarch64-apple-darwin), its executable and the project directory.pythoncall reusedrowsandcollections; it was execution 3 of generation 1. The medians were correct.maple-agentor Python processes remained. Then the same session was loaded in a new host.pythoncall raisedNameError, with "State loss: This is a fresh Python scratchpad: Maple restarted or reloaded this task, so variables, imports and background work from any earlier python calls are gone".orders.csvonce."🤖 Generated with Claude Code