pi-given0.1.0
Provide user and assistant messages to a one-off agent task
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-given
Provide user and assistant messages to a one-off agent task.
What this is
When doing one-off tasks, like with pi -p '...', it's sometimes helpful to construct a conversation history to better match how the model works.
For example, to have the model answer as if it had already picked a number:
pi --given 'Select a random number' --given 'Okay, I chose 14. Try to guess my number!' -p 'I think you chose 13, am I right?'
The first --given is a user message, the second is the assistant's reply, and the -p prompt is the next user message.
There's a bit of nuance to how this is created, and it doesn't always make sense to build this from scratch each time it's needed. So, the purpose of this package is to make it easier to construct those conversation histories.
This also comes up when trying to continue from an earlier one-off prompt. For example, you ask a model to write a spec proposal and it comes back with questions rather than a proposal itself. Rather than re-prompt the model from scratch, it would be nice to just add on the part you're missing — and importantly, to do this without access to the original chat session JSONL file. In that case, pass the original prompt and the assistant's previous reply (e.g. $LAST_RESPONSE) as a pair of --given messages:
pi --given 'Write a spec proposal for the new API' --given "$LAST_RESPONSE" -p 'Answer your questions and produce the proposal.'
Features
--given '...'Shorthand for interactive use: add a user or assistant message. Types strictly alternate, starting with a user message.
--given-user-message '...'or--given-assistant-message '...'Explicit form that states the message type, making scripts easier to read. As a safeguard, errors out if the type that would be added isn't the specified type.
pi --given-user-message 'Select a random number' --given-assistant-message 'Okay, I chose 14. Try to guess my number!' -p 'I think you chose 13, am I right?'
How it works
Each given-message flag (--given, --given-user-message, --given-assistant-message) adds a message to the conversation history that precedes the -p prompt:
- Message types strictly alternate, starting with a user message:
--given A --given B -p Cadds user A, assistant B, then runs C as the next user message. - The
-pprompt is always the final user message, so the message before it must be an assistant message.--given A -p Bwould produce two consecutive user messages and errors out. --given-user-message '...'and--given-assistant-message '...'force the message type and error out if the inferred type would be different.
Install
Install the published npm package with Pi:
pi install npm:pi-given
Pin a specific version when you want reproducible installs:
pi install npm:pi-given@0.1.0
Install into the current project instead of your user Pi settings:
pi install npm:pi-given -l
Or install from GitHub:
pi install git:github.com/player1537/pi-given
Try it without permanently installing:
pi -e npm:pi-given --given 'The capital of France is Paris.' --given 'Good to know!' -p 'What is the capital of France?'
Quick start
Try this package locally:
pi -e . --given 'The capital of France is Paris.' --given 'Good to know!' -p 'What is the capital of France?'
Expected output:
Paris
Package contents
| Path | Purpose |
|---|---|
extensions/ |
Pi TypeScript extension entrypoints |
lib/ |
Shared TypeScript helpers (message construction, type inference, flag collection) |
docs/ |
Optional supporting docs |
Development
npm install
npm run ci
npm run ci runs typecheck, unit tests, the Pi-host smoke harness, and a pack check.
Security
Pi packages can execute code with your local permissions. Review extensions before installing third-party packages.
For vulnerability reporting, see SECURITY.md.
Links
- npm: https://www.npmjs.com/package/pi-given
- GitHub: https://github.com/player1537/pi-given
- Issues: https://github.com/player1537/pi-given/issues
License
MIT