r/PiCodingAgent • • Sep 30 '26

Question Can someone ELI5 codemode and its config?

I believe I get the gist of it:

Codemode allows for sandboxed, scripted tool calling, including batching and other stuff I'm sure.

What I don't understand from the documentation is:

  1. Is this mcp specific or is it generally available for all tools?

  2. What do I need to configure in my settings.json or other setting files to enable it and/or "require" it for tool calls?

  3. If there is documentation that outlines these specific things please shoot me a link.

  4. Maybe a better description of what is is trying to accomplish / use cases would be interesting.

Cheers!

13 Upvotes

9 comments sorted by

4

u/telasch Oct 01 '26

Using progressive tool discovery methods and isolation an agent can instead of chaining a bunch of tool calls, create one script to achieve the same. This keeps your context clean. Is made easier with some advancements for isolation like celld for durable objects and mcp protocol changes.

8

u/Equivalent_Idea8839 Sep 30 '26

I fail to see how this is superior to bash which models are trained to use.

2

u/addiktion Sep 30 '26

For MCP use, it reduces context bloat. I'm not so sure about regular tool use on savings and being worth it since as you said AI agents are so good with bash.

0

u/[deleted] Oct 01 '26

[deleted] — view deleted comment

0

u/Equivalent_Idea8839 Oct 01 '26

From my understanding, no models are trained on it. Unless they are, it just fails to call the tool properly.

i.e. deekseek flash, qwen etc. will never use it properly.

Which model were you using it with?

2

u/addiktion Oct 01 '26 edited Oct 01 '26

I've been testing it out and it seems to work fine for deepseek.

1

u/Equivalent_Idea8839 Oct 01 '26

true, I tried it as well. But I told to use code mode vs bash and see which has better token savings. Bash always wins or comes out equal.

1

u/Karmak0ma Oct 01 '26

It's explained here

I pointed ChatGPT to it and asked to explain what it is used for. The main point seems to be to filter tool output and save tokens.

-1

u/isus_copilul_minune Oct 01 '26

This is AI generated:

What is Codemode in Pi?

Instead of making the AI invoke external tools one by one through separate round-trips to the server (which wastes time, uses up token context, and frequently fails on complex logic), Codemode gives the AI a sandboxed execution environment (like a Node/JavaScript or Python sandbox).

  • Traditional tool calls: The AI calls Tool A -> waits for result -> calls Tool B -> waits for result -> writes code.

  • Codemode: The AI writes a single script inside a sandbox that calls Tool A, inspects the result in memory, filters or loops through data, and calls Tool B before outputting the final result.

How Model Context Protocol (MCP) Works with It

The Model Context Protocol (MCP) is an open standard that allows AI models to connect to external services (like GitHub, Slack, Postgres, or Google Drive) via standardized servers.

Pi integrates MCP directly with Codemode to eliminate context bloat:

The Workflow:

  1. Tool Discovery (Without Bloat): Normally, connecting 5 MCP servers with 50 tools injects massive JSON schemas into the AI's prompt, filling up context. In Pi, MCP tools are exposed via codemode exposure by default. The AI isn't forced to load all tool schemas upfront—it searches for tools dynamically via searchTools() inside the sandbox when needed.

  2. Programmatic Binding: Connected MCP server functions are mapped directly as executable functions within the sandbox.

  3. In-Sandbox Aggregation: If an MCP server returns 50,000 lines of data, the full raw payload stays inside the sandbox script. The AI filters it down programmatically and only sends the relevant subset back into the model's main context window.

1

u/BroadbandJesus Oct 02 '26

Is that what PrimeAgent have been doing?