omp packages

pi-given0.1.0

Provide user and assistant messages to a one-off agent task

player1537 Published 7 days ago MIT ~336 downloads/mo

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.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-given

CI Publish npm version npm downloads License: MIT Pi package

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 C adds user A, assistant B, then runs C as the next user message.
  • The -p prompt is always the final user message, so the message before it must be an assistant message. --given A -p B would 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

License

MIT