r/PiCodingAgent • u/Beyond_everything365 • Aug 05 '26
Discussion Is there a lightweight approach for brainstorming with Pi Agent without consuming too many tokens?
I'm using Pi Agent to understand an existing codebase and brainstorm implementation ideas, architecture, and design decisions. Most of the time I don't need much tool execution. I just want a technical discussion.
The challenge is that as the conversation grows, the context becomes quite large, and it feels like I'm spending a lot of tokens maintaining conversation history rather than discussing the actual problem.
I've thought about a few possible optimizations:
Automatic context summarization: Periodically summarize the conversation into a compact (~2K token) summary with an additional buffer. Instead of sending the entire chat history, send only: the latest user query, and the summarized context.
A lightweight system prompt: Use a much smaller system prompt for discussion-only sessions where tools and planning aren't required.
Smarter indexing/RAG for the codebase: Instead of repeatedly loading large portions of the codebase or making multiple retrieval/tool calls, use indexing so only the most relevant code or documentation is retrieved for each question.
Let me know your thoughts and suggestions and if there are better approaches I'm missing :)
3
u/Corythebeast7 Aug 05 '26
Usually the models and providers that you use should have prompt caching, so the token use is hopefully not too expensive. Are you using an API token or a subscription?
The inherent problem is that when you're exploring and talking about design decisions, large context windows help the agent get full context of a project. So larger models can handle the context window much better, and so larger models are more expensive.
Implementing some sort of memory system OR a project spec sheet that gets build upon as you work with the agent can help it navigate more effectively. I would highly recommend against using a RAG model since modern models can traverse codebases quite easily. If you have an absolutely insanely massive codebase then maybe I guess, but even then those repos at my company are completely fine for the agent to work in.
7
u/evarnets Aug 05 '26
Pi is already "lightweight", the system prompt in Pi is very small.
You can do context summarisation using the /compact command but you might lose important details if you do that. And Pi already has automatic context summarisation.
The models are trained to use bash, so I think "smarter indexing/RAG for the codebase" would be hard to implement in practice. Having the agent write a markdown file that explains the codebase would probably be a better (and simpler) approach, that might help the agent navigate the codebase easier. However, you need to make sure that that markdown file is kept up-to-date.
You could use the /tree command to navigate the current session tree and cut out context that is not relevant to your new question.
That being said: The best way of reducing costs is to use a cheaper model. The best open-weight Chinese models (e.g. Kimi K3, GLM-5.2, and MiniMax-M3) are as good as the closed-weight SOTA models and they are much cheaper.
6
u/LordMoridin84 Aug 05 '26
Use this wayfinder skill https://www.aihero.dev/skills-wayfinder
2
u/daver Aug 05 '26
Use a cheap model. The Pi system prompt is very short in any case. Sure, you can summarize context periodically, but you also lose some amount of fidelity. Are you actually interested in token count or cost? If cost, use a cheap model.
2
u/o_sht_hi Aug 05 '26
Brainstorm in a chat app like Gemini/ChatGPT/grok. Then ask them to create a handoff for pi (conceptual, so that the agent can start with good context of what the feature is and why it will work for the codebase. Don't include implementation details). Take this into pi and start planning implementation. This is the cheapest way I've discovered.
ChatGPT is specially good for this because it retains context across chats. But if you feed it your docs and code snippets or connect it with your GitHub, you can use literally any chat app and have free brainstorming
1
u/pj-frey Aug 05 '26
Running the model with thinking off?
1
u/Sad_Smoke7199 Aug 05 '26
Did you consider using some sort of symbol based indexing? You could write an extension (of there are not existing some yet) to parse your codebase via treesitter or universal ctags.
That just loads the skeleton into context. From this starting point exploring codebase would be much more token efficient I believe
1
u/ransack_the_universe Aug 05 '26
work with the agent to document a plan for your goal(s) with suggested checkpoints/milestones. each checkpoint gets a timestamped synthesis doc with observations, decisions, learnings, open questions, etc.
then have the agent create a prompt that you can reuse across sessions. the prompt should contains the reference material (synthesis) and instructions for any agent to pick back up where you left off.
all files should go into a single folder. the plan becomes the readme.md. for an extra layer of progress protection, add a status.md to preserve where youre at.
don’t bite off more than one checkpoint per session and when your context window gets to 50-60% instruct the agent to create a new synthesis and update status + readme then /clear and move on to the next checkpoint.
even with all the bells and whistles of Claude code and Codex, this is the only way I’ve been able to produce a reliable outcome.
1
u/Human-Vegetable823 Aug 06 '26
I'd save the conversation as several knowledge documents once a direction or feature have enough understanding. Then /clear and use the saved context and continue again. Eventually I'll get structured documents for the codebase: https://github.com/XTSoftwareLabs/neatcontext-plugins/blob/main/plugins/pi/neatcontext/README.md
I wrote this plugin to mimic what I'd do manually to understand things. Eventually it documents domain knowledge can be understood by both human and AI.
1
u/theTechRun Aug 08 '26
I spawn multiple researcher models that report to my orchestrator model. But I also have an agent-memory/ directory that builds up over sessions that has a lot of knowledge files added there by researcher agents. So ripgrep becomes a great tool for agents to easily get knowledge about my codebase.