Install
Install with PiG
pig install npm:@linnify/agentlens-piInstall with Pi
pi install npm:@linnify/agentlens-piPackages 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": [
"./dist/index.js"
]
}README
Written by the package's publisher, shown as published in version 0.9.0 (README.md). PiG does not review it.
@linnify/agentlens-pi
A pi extension that sends every prompt pi runs to AgentLens as one trace:
| pi | AgentLens |
|---|---|
A prompt, from before_agent_start until the run settles | The trace, rooted at an agent span named pi: the user's prompt in, the last answer out |
| A model call | A generation with the prompt (system prompt and conversation), the reply, the model, its parameters and thinking level, token usage and pi's cost |
A tool call (read, bash, edit, an extension's tool…) | A tool span with its arguments and result |
| A compaction during a run | A compaction generation |
| The pi session | The trace's session |
Tokens and cost are pi's own, the same for any provider or gateway: the usage the provider reported and the cost pi works out from the model's prices. A model pi has no prices for reports no cost, and AgentLens prices it from the usage. A tool that calls a model itself and reports its usage in its result, such as a subagent, gets a generation under its span.
Install
pi install npm:@linnify/agentlens-pi # for every project
pi install -l npm:@linnify/agentlens-pi # for this project, in .pi/settings.json
pi -e npm:@linnify/agentlens-pi # for one run
An app that ships pi with its own extensions can bundle it as one of them: export { default } from '@linnify/agentlens-pi';.
Configure
Everything comes from the environment, so the same extension serves every agent:
| Variable | (blank) |
|---|---|
AGENTLENS_API_KEY | Required. An API key of the project the agent belongs to |
AGENTLENS_ENABLED | false, 0, no or off turns the extension off, silently. On by default |
AGENTLENS_AGENT | Required. The agent the traces belong to, e.g. builder |
AGENTLENS_BASE_URL | The AgentLens web app's address. Defaults to https://agentlens.linnify.com; http://localhost:3000 for a local platform. The SDK adds /api/v1 itself |
AGENTLENS_SESSION_ID | The trace's session; pi's session id when unset |
AGENTLENS_USER_ID | The user the traces are for |
AGENTLENS_TENANT | The tenant the traces belong to |
AGENTLENS_ENVIRONMENT | e.g. production |
AGENTLENS_EXPERIMENT_ID | The experiment the traces belong to. They are hidden from AgentLens's normal views and shown with the experiment instead |
AGENTLENS_EVALUATION_ID | The evaluation run the traces belong to, hidden from the normal views like an experiment's |
AGENTLENS_METADATA | A JSON object added to the metadata of every trace's root span, e.g. {"ticket":"SF-12","branch":"feat/x"}. A value that is not a JSON object is left out, with a warning |
AGENTLENS_TRACE_ID | The id of the first trace the process sends: 32 hex characters, e.g. crypto.randomBytes(16).toString('hex'). The app that spawns pi picks it so it can score that trace later with client.score.create({ traceId }) from @linnify/agentlens-client. Later prompts get random ids. A malformed value is ignored, with a warning |
Without an API key or an agent nothing is sent: the footer reads agentlens: off, or a warning is logged when pi runs without its interface (--print, --mode rpc).
To attach a prompt to an experiment, the app that spawns pi for it sets AGENTLENS_EXPERIMENT_ID (or AGENTLENS_EVALUATION_ID) and picks the trace's id with AGENTLENS_TRACE_ID, so it knows which trace the prompt became. The id is sent on every span of the trace, as agentlens.trace.experiment_id or agentlens.trace.evaluation_id, and applies to every trace the process sends. A span whose experiment or evaluation AgentLens doesn't know for its agent is rejected by AgentLens.
Traces are flushed when each run settles, so a pi process that exits right after its prompt still delivers them.