@brglng/pi-prompt-emulated-tool-call
v0.2.0
Published
Pi extension that emulates tool calls via prompts for chat-only models
Readme
pi-prompt-emulated-tool-call
Extension for the Pi coding agent that emulates tool calls via prompts for chat-only models that do not support native tool calling.
How it works
For each configured model, the extension injects a system-prompt section that contains the full JSON schemas of the currently active tools. When the model needs a tool it responds with exactly one plural <tool_calls> block wrapping a non-empty JSON array, optionally with ordinary text before and/or after it:
I'll read the source first.
<tool_calls>
[{"name": "read", "arguments": {"path": "src/index.ts", "offset": 1}}]
</tool_calls>
Then I'll check how it fits together.The extension parses that block into native Pi tool calls, preserving thinking and ordinary text in before/calls/after order. Non-whitespace surrounding text is kept verbatim; whitespace-only surroundings are omitted. The JSON may optionally be wrapped in one json code fence inside the tags. Marker and fence text inside JSON argument strings remains data. Multiple blocks or malformed payloads are rejected as a whole, with format feedback and no partial conversion. Responses ending in error or aborted are neither converted nor given format feedback. Pi executes valid calls through its normal agent loop. All calls in one array run in parallel by default; if an active tool explicitly declares executionMode: "sequential", Pi's sequential execution constraint is respected. Results are injected back as a <tool_results> JSON array on the next turn. Ordinary responses without the marker pass through unchanged.
Installation
Install package from npm with Pi's package manager:
# global
pi install npm:@brglng/pi-prompt-emulated-tool-call
# project-local
pi install -l npm:@brglng/pi-prompt-emulated-tool-callPi loads extension entrypoint from package manifest. Create configuration files at paths below after installation.
Configuration
Create a config file at one of:
- global:
~/.pi/agent/extensions/pi-prompt-emulated-tool-call/config.json - project:
.pi/extensions/pi-prompt-emulated-tool-call/config.json
The shape is:
{
"models": [
"provider-id/model-id",
{ "model": "provider-id/model-id", "removeNativeToolFields": true }
]
}- String entries use default options.
- Object entries may set
removeNativeToolFields. modelsmay mix strings and objects.- A project config overrides the global config when present;
models: []disables the feature. Project config is only read when the project is trusted. removeNativeToolFieldsdefaults tofalse. Whentrue, the extension removes native tool definitions, tool selection, and parallel-tool fields from the provider request payload. This covers provider-specific shapes such as Google/Vertexconfig.tools/config.toolConfig, Bedrock root-leveltoolConfig, and equivalenttools/tool_choice/toolChoice/parallel_tool_calls/parallelToolCallsfields.
Invalid JSON or an illegal model entry logs a warning and disables that config file; it does not block Pi startup.
Development
# install dev dependencies
npm install
# run tests
npm test
# typecheck
npm run typecheckLicense
MPL-2.0
