Pi Agent Extensions

by Nikita Chernyi in AI (RSS)

TL;DR for the bots (humans, scroll on)

Which Pi Agent Extensions Should I Use? Comment Gate, No Sleep, Phantom User, Schema Trim, Slop Guard, Session Title, Tab Title, Rulebooks, TTSR, and Plan Mode

A catalog of the extensions the author wrote for the Pi coding agent. comment-gate blocks writes and edits that add long comments, nosleep blocks bash `sleep` calls over 30 seconds in the main context, phantom-user drops reasoning blocks that invent a user quote, schema-trim swaps tool descriptions on the wire, slop-guard blocks machine-flavoured prose, session-title names a session with a 1.7B model and a GBNF grammar, tab-title puts the session state (idle, working, blocked, done, error) in the terminal window title, rulebooks attach path-scoped rule files to the tool result, ttsr attaches rule reminders when a regex or AST pattern matches, and plan-mode reviews a plan with a subagent before the user approves it.

Hi there,

In 8 Agents Come Into A Bar I mentioned that I’m done with the compromises required when you work with agents, and chose Pi agent (opens in new tab) because you can make it work exactly as you need. On this page I will explain each of the extensions I use, because the one-liners in github.com/rakshazi/pi-extensions (opens in new tab) are pretty short. So, that’s more a catalog than a blog post, and I’ll keep it updated when something changes.

I’d suggest you fork specific extensions you need and adjust them for your preferences rather than just installing them as-is, but if you are brave enough:

pi install git:github.com/rakshazi/pi-extensions

A catgirl in a black blazer holds an open palm toward a cart of paper scrolls at the door of a cream building marked NOPE, while a tired engineer with a coffee waits beside the cart AI-generated catgirl, contractually obligated to lure you into the post.

The catalog may grow a lot, so here is a table of contents:

Small things

This section holds small extensions, mostly QoL improvements that are nice-to-have.

Comment Gate (short comments)

Source (opens in new tab)

I’m pretty annoyed when an agent writes 15 lines of comments for a 3-line function, so I made an extension that rejects writes and edits with long comments. Of course, there are cases when long comments are actually needed, so the extension comes with a bypass for that.

And don’t worry, your agent won’t use the bypass unless absolutely necessary, because it is deliberately uncomfortable, so complying with the gate is easier for the model than bypassing it (learned from LLM Psychology 101, btw).

No Sleep (prevent long sleeps)

Source (opens in new tab)

Sometimes an agent may start bragging with its bash jutsu and run long-running tasks in the background, then decide it has nothing to do, and start shooting sleep 100500 && ... tool calls to wait, while the actual task is going to finish in a few minutes.

This extension blocks bash calls with sleep > 30 seconds in the main context and tells the agent to either use a regular blocking command (if it doesn’t have any other work to do), or, if absolutely necessary, use a bypass. Of course, as in Comment Gate, the bypass is designed to make complying easier than bypassing.

Phantom User (prevent hallucinated instructions)

Source (opens in new tab)

I noticed that some models with thinking preserved (default mode nowadays) at some point start hallucinating user messages and instructions, even when the user last wrote a message 100+ tool calls ago. Just imagine, you ask the agent to write a plan, and mid-planning it decides to go implement the thing, because it hallucinated WHY ARE YOU STILL WRITING THE PLAN, go implement it already!!! (real example, and that was the trigger to build the Plan mode extension instead of a skill, btw).

So, this extension parses the agent’s reasoning, and when it notices something like “the user said” without a real prior user message, it just drops this reasoning block (i.e., on the next turn, this specific reasoning block is excluded from the request).

Works pretty well, but has some false positives (when the agent recalls actual instructions from prior messages), though I didn’t notice degradation. Stats show that less than 2% of reasoning blocks were dropped in real sessions on real work (parsed jsonl files). Also, no impact on the cache ratio.

Schema Trim (replace bloated tool descriptions)

Source (opens in new tab)

At some point I noticed that some tools have pretty huge descriptions, and they looked like AI-generated slop, without a real need for such verbosity. One of the extensions had 12k characters in its description to name 3 args. Love it (not really).

This extension allows you to replace the tool descriptions (when sending them to the model) with your own, without impacting the cache ratio.

While initially it was made to cut costs (mostly time costs, because prefill on local models on my hardware is slow), it actually helped to improve tool triggering, because the replaced descriptions were made with model-lab, and tested (n=5) on real work tasks.

So, cheaper and more reliable, nice.

Slop Guard (block annoying slop patterns)

Source (opens in new tab)

I hate load-bearing (opens in new tab) slop, and this extension blocks such patterns in write/edit tool calls and tells the agent to rephrase the triggered places.

Pretty simple, just a list of patterns, but your eye stops ticking almost immediately, because you don’t have to read through It's not X — it's Y and similar bloat.

I prefer the agent to say what the thing IS, not just what it isn’t (sorry, can’t help myself. If at this moment your left eye ticks, go get the extension, and save some money on psychologist sessions).

Session Title (automatic title generation)

Source (opens in new tab)

Pi doesn’t have auto-generation of session titles by default, so this extension adds it. The part I’m most proud of: the generation is tuned on a 1.7B model, supports a GBNF grammar, and actually works, because I’m pretty tired of <tool_call>, or Certanly, I can ... or Describe Definitely Approximation Of Certantly Probation garbage, that is completely unrelated to the purpose of the session.

So, I took the target model (LFM3 1.7B at the moment) and 300+ existing session transcripts, and tuned the prompt and parsing to make it work with skill-only sessions, random starters like Hi there, big imperative design prompts, and other arbitrary things you can expect from backend dev’s agent.

I had big problems with title generation on both OMP and Pi (see the 8 Agents Come Into A Bar post), but with Pi you can actually tune it.

It also works with any model in the registry: the grammar is an optional flag.

Tab Title (terminal window title)

Source (opens in new tab)

This one adds a state-aware title to your terminal window, so you can see from it alone what’s going on with the agent:

  • idle (fresh session or you cancelled a turn): zzz icon
  • working (agent’s crunching): animated braille spinner
  • blocked (agent’s waiting for you): alert icon
  • done (agent’s finished): check icon
  • error (error happened with the agent itself): cross icon

So, your terminal window title will look like <glyph> <session title>.

Why tho? Because Pi doesn’t enable state signalling by default, and the default tab title naming is… ugh. So, when you have different agents in parallel, on different projects/tasks, the only way to find the needed one is tab roulette. Though my main pattern is: agent does something, and in the same terminal I do something else in neovim, and I don’t see when the agent is blocked or finished just from the tab title.

In-context learning

This section is more interesting and focuses on teaching the model in context. Yes-yes, weights are frozen, the model can’t be changed, yada-yada. The purpose of the extensions in this section is to provide knowledge and rules with progressive disclosure, so the information is injected into the context only when actually needed, avoiding unnecessary context bloat.

I was quite impressed with OMP’s context files system, and when I moved to Pi, I built something similar “at home” with blackjack and sorry, wrong post.

Rulebooks (path-scoped rules)

Source (opens in new tab)

This extension basically implements path-scoped rules from other harnesses: when the agent opens a file on a specific path, the extension appends the rulebook file’s content to the tool result.

In Write AGENTS.md skill I mentioned why, and shared go.md as an example, in case you want to see what such a rulebook looks like.

TTSR (Time-Travelling Stream Rules)

Source (opens in new tab)

Not really. I mean, this extension was heavily inspired by OMP’s TTSR, but it implements only the actually usable subset: non-blocking rule reminders.

Works similarly to Rulebooks, but triggered by specific patterns (regex and AST) in write/edit tool calls.

What it does (example): when the agent writes shit like resp, _ := client.Do(req) to ignore an error in Go code, a rule reminder is attached to the tool result, telling the agent that it should handle errors properly.

The rules themselves are plain .md files, here is an example of one of the actual rules I use: errors.AsType over errors.As, from the Write AGENTS.md skill post.

Special modes

This section contains “big stuff” that changes the agent’s behavior significantly, and I have opinions on how things should work, so don’t be surprised when things work in an unexpected way for you ;)

Plan mode

Source (opens in new tab), dependencies: npm:@tintinweb/pi-subagents (hard), npm:@juicesharp/rpiv-ask-user-question (soft).

In 8 Agents Come Into A Bar I mentioned my workflow for coding agents, which is:

  1. investigate -> review
  2. plan -> review
  3. then reconcile -> implement -> review
  4. final: human review (related post)

And this extension handles the #2 part: plan and review. You see, from all the harnesses I used, plan mode was some sacred thing where the agent prepares itself for complex work, but practice shows that such preparations are often shallow, and almost always miss nuances and details. So, to work around that, I use a mandatory plan review / pre-mortem step during planning, and then mandatory reconciliation before generating a single line of code.

This plan mode extension does exactly that: the agent prepares a plan, then a separate subagent reviews it, and only after the important findings are addressed (and trust me, almost every time there is something important missing), the agent proposes the plan for approval.

Also, the final step of plan mode is one of the options:

  • Implement in new session (fresh context) - my default choice, the plan is self-contained, so there is no point in keeping the context bloat from the planning session
  • Implement in current session (keep context) - sometimes, very rarely, when context info is actually valuable and for some reason it is not part of the plan. I never use it myself, added just for completeness.
  • Modify plan (adjustments) - when you have comments and want some changes to the plan, usually when the agent doesn’t have some specific domain knowledge you have
  • Save plan as file and exit - when you don’t want to implement it immediately, just save it for later
  • Open plan in editor - when it’s easier to fix the plan by hand than to explain all the nuances to the agent

AI, SI, AGI, ASI, LLMs, and other buzzwords from the position of a backend engineer already tired of ‘Dear colleagues, we are AI-first now!’

Too much AI for today? See Misc, SMTP for a change

llms.txt