← Catalog

pi-agenthint

Agent Hint request metadata and lifecycle reporting for Pi

ExtensionProvider

Install

Install with PiG

pig install npm:pi-agenthint

Install with Pi

pi install npm:pi-agenthint
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/extension.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.4.0 (README.md). PiG does not review it.

pi-agenthint

Agent Hint request metadata for Pi.

pi-agenthint derives a bounded, standard view of the agent session driving each request from Pi's public ExtensionAPI and attaches it to model-provider requests as an X-Agent-Hint HTTP header. When the session pauses, resumes, stops, or is compacted it sends a manage request carrying exactly one lifecycle verb. It never adds an Agent Hint field to the provider request body.

Install · Verify · Configure · How it works · Safety · Test

Why

A provider, router, or observability service may benefit from facts that Pi already knows:

  • which session and request ordinal produced a call;
  • whether this request opens a session or continues one, and which context generation it belongs to;
  • whether a person is waiting on it, which is the difference between an interactive turn and background work;
  • how long the engine should hold the prefix this request is about to reuse;
  • when to release that hold — the session paused, resumed, finished, or had its context rewritten.

Without an extension those facts remain inside the agent process. This package exposes them in one size-limited header while keeping the model payload unchanged. The receiving service must understand the header; the extension does not assume that an unsupported provider will act on it.

The wire format is not defined here. The authoritative definition is the merged four-block protocol in evan7ang/dsh-agent-hints, and this package is one of its independent ports.

Install

Requires Node.js 22.19 or newer and Pi with the provider-header lifecycle hooks. The package is verified against @earendil-works/pi-coding-agent@1.1.0 and @1.2.0.

pi install npm:pi-agenthint

Installing the package is the opt-in. Header injection is enabled by default; the manage channel stays off until you give it an endpoint.

Upgrading from 0.3.x. 0.4.0 is a breaking protocol change: agent_status, prediction, derivation, session.agent_type, strict_priority, cache_control[].range/unit and latency_control are gone, cache_control is a single object with an explicit ttl_s and msg_offset, and the out-of-band event stream is replaced by manage requests. A consumer that still reads the old blocks will see them missing rather than wrong — but it will no longer learn when a session releases its context until it accepts manage requests.

pi update npm:pi-agenthint          # or: pi install npm:pi-agenthint (unpins a pinned install)

Do not enable this package alongside an AscendAgent-Pi release that still contains its embedded Agent Hint implementation. Both producers refuse to overwrite an existing X-Agent-Hint, so only the first loaded producer will send a value.

Verify

Start Pi and run:

/agenthint

The command reports the loaded Pi version, configuration source, injection / skip / manage-request counters, the current local lifecycle state, the manage channel's health, and the last hint sent. It does not make a model request.

An ordinary request carries this shape; a block is present only when it has something to say:

{
  "session": {
    "session_id": "…",
    "state": "append",
    "call_index": 1,
    "epoch": 0
  },
  "priority_control": { "priority": { "level": 3, "reason": "user_waiting" } },
  "cache_control": { "type": "ephemeral", "ttl_s": 600, "msg_offset": 2 }
}

A manage request carries the verb and the edit, and nothing about priority or caching:

{
  "session": { "session_id": "…", "state": "pause", "call_index": 4, "epoch": 0 },
  "context_management": {
    "manage_request": true,
    "edits": [{ "type": "offload", "target": "session" }]
  }
}

Configuration

Defaults require no file. To override them, point PI_AGENTHINT_CONFIG at one complete JSON file:

PI_AGENTHINT_CONFIG=/absolute/path/to/agenthint.json pi
{
  "enabled": true,
  "agentType": "pi-agent",
  "suspendAfterMs": 90000,
  "humanApprovalWaitMs": 300000,
  "humanInputWaitMs": 60000,
  "cacheControl": true,
  "cacheTtlS": null,
  "priority": true,
  "strictPriority": true,
  "strictPriorityEnv": "PI_AGENTHINT_STRICT_PRIORITY",
  "manage": {
    "enabled": false,
    "endpoint": "",
    "model": "",
    "tokenEnv": "PI_AGENTHINT_TOKEN",
    "timeoutMs": 5000,
    "maxRetries": 1,
    "queueLimit": 64
  }
}
OptionTypeDefaultMeaning
enabledbooleantrueMaster switch for both the header and the manage channel.
agentTypestring"pi-agent"Internal label that scopes the learned statistics. Never placed on the wire.
suspendAfterMsinteger90000Locally escalate a continuing human wait from pause to suspend; affects the expected resume latency only.
humanApprovalWaitMsinteger300000Expected approval-wait budget used by the local state machine.
humanInputWaitMsinteger60000Expected non-approval human-input wait budget.
cacheControlbooleantruePublish cache_control when the request has a prefix worth keeping.
cacheTtlSinteger | nullnullRetention seconds. null derives it from the observed gap (next tool's expected duration, else the inter-call interval, else 300 s, doubled and clamped to 60–3600); 0 sends no declaration at all; a number fixes it.
prioritybooleantruePublish priority_control. Levels are binary: 3 when a person is waiting on this request, 1 otherwise; reason is derived from the level (user_waiting / critical_path).
strictPrioritybooleantrueAllow a trusted external binding to override the derived level; the extension never self-assigns a top tier.
strictPriorityEnvstring"PI_AGENTHINT_STRICT_PRIORITY"Environment variable containing <level>[:<reason>]. The level is folded, and the reason is re-derived to match it.
manage.enabledbooleanfalseSend lifecycle verbs as manage requests. Off = no manage traffic at all.
manage.endpointHTTP URL""Where manage requests are POSTed; required when the channel is enabled.
manage.modelstring""model of the placeholder manage body. Empty omits the key.
manage.tokenEnvstring"PI_AGENTHINT_TOKEN"Environment variable read at delivery time for the bearer token.
manage.timeoutMsinteger5000Per-attempt timeout.
manage.maxRetriesinteger1Bounded retries for a failed manage request.
manage.queueLimitinteger64Maximum queued manage requests; the oldest is dropped first.

Configuration is strict: unknown fields, wrong types, invalid ranges, and non-HTTP manage endpoints are rejected. An invalid explicit file disables header injection and is shown by /agenthint; the extension does not silently fall back to enabled defaults.

The manage bearer token is resolved from its environment variable at delivery time. It travels in an Authorization header and is never stored in status, written to the hint, or retained by the client.

How it works

The extension uses Pi's public lifecycle surfaces:

  • before_provider_headers builds and attaches the hint for every provider attempt;
  • after_provider_response records completed provider timing;
  • context_with_system supplies the wire message count that becomes cache_control.msg_offset;
  • session, compaction, tree, tool, UI-prompt, and settle events drive the local state machine and, for the four lifecycle verbs, the manage channel;
  • custom session entries preserve request ordinals and context epochs across a restart.

The header value is canonical JSON encoded as base64url and capped at 4096 encoded bytes. Optional blocks are shed in a fixed order if necessary; session is never truncated, and a hint that cannot fit or that fails its own validation is omitted instead of being sent malformed.

Pi's internal vocabulary (running, tool, pause, suspend, finalize) is mapped to the six wire states at the build boundary. Those internal states are not the protocol, and a state change that the next ordinary request will describe anyway is not pushed out of band.

Two rounds carry no hint at all. A compaction window is an auxiliary request — it exists to rewrite the prefix, not to be scheduled or cached — so its summarization prompt goes out with no header and consumes no request ordinal. A branch-summary round is a normal request for the session block but publishes no cache_control, because the prefix it would have pinned is the one being replaced.

The four verbs map onto context edits as follows — compact names the generation that was dropped, so its session.epoch is one behind the epoch the rewrite produced:

Verbedits[0].typeFired when
pauseoffloadan approval or a human prompt blocks the turn
resumeprefetchthat wait is answered
stopevictthe session finalizes
compactevictthe context is rewritten by compaction

Manage requests

A lifecycle verb is not reported out of band; it owns one small request of its own, POSTed to manage.endpoint with the verb in the header and an empty placeholder body ({"model": …, "messages": [], "stream": false}, with model omitted when unset). The request exists to carry the edit, not to be answered, so its header carries session + context_management and nothing else — a priority tier or a cache declaration there would describe work the request is never going to do.

Only a changed verb is sent: two consecutive identical verbs carry no new information and are collapsed. An endpoint that does not accept manage requests leaves them unanswered by design; the extension keeps the channel advisory, queues at most manage.queueLimit requests, and retries a failed delivery manage.maxRetries times.

A resumed session writes checkpoints as pi-agenthint.checkpoint and can read the legacy ascendagent-pi.agent-hint-checkpoint type for migration.

Safety and failure behavior

  • Existing X-Agent-Hint headers are never overwritten.
  • Provider request bodies are never modified.
  • Header construction, manage delivery, checkpoint writes, and observation failures are isolated from the model request; the header path is pure and never throws into Pi's event loop.
  • The manage channel is off by default and accepts only an explicit HTTP or HTTPS endpoint.
  • Manage tokens are read from environment variables and are never returned by /agenthint.
  • Statistics use bounded windows and do not infer unsupported parent-child agent relationships.
  • A hint is advisory metadata, not an authentication, authorization, or sandbox boundary.

Compatibility and AscendAgent-Pi parity

The standalone package was extracted from the Agent Hint implementation in AscendAgent-Pi. After the protocol normalization the two are no longer wire-compatible, and the difference is deliberate:

  • hint construction and schema validation follow the merged four-block protocol;
  • the local lifecycle state machine is unchanged, and its vocabulary stays off the wire;
  • prediction / next_action are not published: measured latency, output tokens, and interval are enough to derive a TTL, and a guessed next action is not a fact;
  • the manage client resolves its token at delivery time instead of retaining it;
  • new checkpoints use the standalone name while legacy AscendAgent-Pi checkpoints remain readable;
  • /agenthint replaces the Bundle-specific /ascend-hint command.

Pi versions outside the verified set are reported by /agenthint and produce a TUI warning rather than being silently treated as verified.

Testing

npm install --ignore-scripts
npm run test:unit
npm run test:e2e
npm run check

The deterministic suite contains 183 unit, contract, integration, security, package-install, and session-recovery tests. The separate end-to-end test starts a real Pi 1.1/1.2 process against a local OpenAI-compatible mock provider and asserts from the captured HTTP request that:

  • X-Agent-Hint is present and decodes to the four-block shape;
  • the first provider request carries session.state = "start" and call_index = 1, and later ones carry append;
  • cache_control is a single object whose msg_offset equals the wire message count;
  • retired blocks (agent_status, prediction, derivation, strict_priority) are absent;
  • no agent_hint field is added to the provider body.

No network credentials or model quota are required for the test.

Layout

src/
├── extension.js       # Pi ExtensionAPI wiring, manage dispatch, and /agenthint
├── config.js          # strict standalone configuration
├── hint-build.js      # four-block construction, TTL derivation, size budget
├── hint-schema.js     # field validation and optional-block shedding
├── hint-state.js      # local lifecycle state machine
├── hint-stats.js      # bounded observations (latency, output tokens, interval)
├── hint-control.js    # trusted priority binding and the manage-request client
└── hint-recovery.js   # durable checkpoint compatibility

test/
├── *.test.js          # unit, contract, integration, security, and install tests
└── e2e/wire.test.js   # real Pi + local mock provider wire acceptance

License

Licensed under the Apache License, Version 2.0. See LICENSE.