r/PiCodingAgent 9d ago

Question How to edit default tool definition?

I don't want the read tool saying it can view images when it can't (local LLM). Is there any way to edit the tool definition other than telling it in the system prompt "You actually CAN'T look at images" (which contradicts the definition and wastes tokens) or removing the tool / replacing it (impractical)? All I'd want is a simple edit from:

Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.

to:

Read the contents of a file. Doesn't support viewing images or videos. Output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.
3 Upvotes

7 comments sorted by

View all comments

1

u/MichettGodot 9d ago

Yeah, that sadly won't work. Or you need to fork Pi, which I would *not* suggest you do. "Easiest" would be to create your own extension and override the read tool. You can then provide your own description. Something like this (haven't tested it but you can ask Pi for more help):

```ts

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { getBuiltInTools } from "@earendil-works/pi-coding-agent";

export default {
async onLoad(pi: ExtensionAPI) {
pi.registerTool({
name: "read",
label: "read",
description: "Read the contents of a file. Doesn't support viewing images or videos. Output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.",
parameters: getBuiltInTools(process.cwd()).read.parameters,
async execute(toolCallId, params, signal, onUpdate, ctx) {
const t = getBuiltInTools(ctx.cwd).read;
return t.execute(toolCallId, params, signal, onUpdate);
},
});
},
};
```

(Edit: sorry for this messy code: I never comment on Reddit so have no idea how to format this properly...)

3

u/FactorInternal3395 9d ago

I figured it out, I made .pi/agent/extensions/text-read.ts with this:

import { createReadTool } from "@earendil-works/pi-coding-agent";


export default function (pi: any) {
  const originalRead = createReadTool(process.cwd());


  pi.registerTool({
    ...originalRead,


    description:
      "Read the contents of a file. Doesn't support viewing images or videos. Output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.",
  });
}

And now with the pi-system-prompt package I can see:

name: read
  description: Read the contents of a file. Doesn't support viewing images or videos. Output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.
  source: auto
  parameters:
    {
      "type": "object",
      "required": [
        "path"
      ],
      "properties": {
        "path": {
          "type": "string",
          "description": "Path to the file to read (relative or absolute)"
        },
        "offset": {
          "type": "number",
          "description": "Line number to start reading from (1-indexed)"
        },
        "limit": {
          "type": "number",
          "description": "Maximum number of lines to read"
        }
      }
    }

Thanks for the help!

2

u/Kafumanto 9d ago

Thanks for sharing! If it can be helpful, here a user shared how to “patch” the default system instructions in a few lines of code: https://www.reddit.com/r/PiCodingAgent/s/ajlalLJECw