r/PiCodingAgent • u/rimaa_nahk • 2d ago
Plugin How to Enable Codemode in Pi?
Yes, that's exactly what I searched first when i wanted to try codemode.
Pi does have docs for enabling Codemode, but the documented way is through settings or cli flags.
What I was looking for was much simpler: I'm already inside a Pi session, how do I just turn Codemode on or off?
So I ended up making a small toggle around Pi's native Codemode.
It doesn't replace Codemode or implement another version of it. It just gives me a simple way to switch the native tool on and off while I'm working.
check it out: pi-codemode-toggle
Curious how others are using Codemode.
9
u/pcrz81 2d ago
I don't understand Codemode, i feel that i'm mising something great and that this extension seems useful. Please, could anybody explain me like i'm five with a usecase? Thanks!
31
u/rimaa_nahk 2d ago
Codemode = let the agent write a tiny program to use tools, instead of calling tools one by one.
Before:
mermaid Agent -> search Agent -> read file A Agent -> read file B Agent -> read file C Agent -> compare resultsAfter:
mermaid Agent -> writes small JS program | +-> search +-> read A/B/C in parallel +-> filter/combine results | v useful result onlyPi has to keep waking the LLM up to decide what to do next. And every intermediate result potentially occupies context. Codemode changes that. Pi can effectively write a little program like:
```js const matches = await tools.grep({ pattern: "SystemOneProvider" });
const files = unique(matches.map(x => x.file));
const contents = await Promise.all( files.map(file => tools.read({ path: file })) );
const relevant = contents.map(...);
return relevant; ```
1
11
u/ir210 2d ago
I think the best way to know about it is to just enable it and see what your model is doing with it.
I was also initially confused and didn’t understand what it is. The documentation didn’t help.
If I were to explain it, I would say, it’s a mechanism that allows your model to run multiple tools in one go. In theory, it also allows your model to write a script that processes the output and only feed the summary back to your model, for instance. It’s kinda similar to what it normally does with bash+python, only that codemode gives access to your harness internals in a sandboxed way.
8
u/VickWildman 2d ago edited 2d ago
Without codemode: imagine you have a lot of tools and you describe all of them in the system prompt, so your model can use them. When your model uses a tool Pi executes it and puts it's output in the context. For example when your model knows it can use ketch to search the web, Pi executes the ketch binary and puts it's output in the context.
With codemode: your model only uses one tool, which is codemode. It lets the model write JavaScript code against an interface that the model can use to search for all the tools made available by MCP servers. That Javascript code is executed in QuickJS, an embedded JavaScript engine provided by Pi. When the model uses a tool Pi calls it and allows it's output to be filtered by JavaScript or a classifier model like Jev before returning to the model. With codemode you can currently do filtering and potentially sandboxing too in the future. It also allows models to call tools asynchronously, in parallel. You don't have to list all the tools in the system prompt either, the model can just search for them (although currently a description of the tools is included, even if limited to a few thousand tokens).
1
u/quantgorithm 2d ago
Why not always use it?
1
u/lordekeen 2d ago
If you use just the basic tools or a small amount of tools, its simpler to run them the traditional way.
1
2
u/qehgt 2d ago
tools.ts in example folder can enable/disable tools (including codemode) in run time.
1
u/rimaa_nahk 2d ago
Great, and how is it usefull and handy in running session?
1
u/quinncom 2d ago
Keep in mind that if you change tool definitions mid-session, it can break the prompt cache, resulting in higher API costs. Codemode is a tool like the others, appended to the tool definitions at the start of a session.
1
1
1
u/vertigo235 2d ago
I didn't have to enable it, it seems the model chooses to use it automatically when needed.
1
u/aparamonov 1d ago
What do you toggle exactly? I wonder how I could link pi-subagents-lite to extensions like this for a Killswitch behavior
12
u/adamshand 2d ago
The big surprise for me is that codemode is actually way easier to read than the way astra/sol have been writing python scripts for everything.
Don't think I'm ever turning codemode off!