Scan your whole stack
Are you using @oh-my-pi-zen/pi-agent-core?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v19.2.1-zen.1
@oh-my-pi-zen/pi-agent-core was last scanned on 26 Nov 2026 at version 19.2.1-zen.1. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 19.2.1-zen.1 LATEST | 26 Nov 2026 | No rules fired |
| 19.1.1-zen.1 | 24 Nov 2026 | No rules fired |
| 19.1.0-zen.2 | 22 Nov 2026 | No rules fired |
| 18.22.2-zen.1 | 18 Nov 2026 | Not shown |
| 18.20.0-zen.4 | 13 Nov 2026 | Not shown |
Findings for v19.2.1-zen.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 19.2.1-zen.1; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Stateful agent with tool execution and event streaming. Built on @oh-my-pi-zen/pi-ai.
npm install @oh-my-pi-zen/pi-agent
import { Agent } from "@oh-my-pi-zen/pi-agent";
import { getModel } from "@oh-my-pi-zen/pi-ai";
const agent = new Agent({
initialState: {
systemPrompt: ["You are a helpful assistant."],
model: getModel("anthropic", "claude-sonnet-4-20250514"),
},
});
agent.subscribe(event => {
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
// Stream just the new text chunk
process.stdout.write(event.assistantMessageEvent.delta);
}
});
await agent.prompt("Hello!");
The agent works with AgentMessage, a flexible type that can include:
user, assistant, toolResult)LLMs only understand user, assistant, and toolResult. The convertToLlm function bridges this gap by filtering and transforming messages before each LLM call.
AgentMessage[] → transformContext() → AgentMessage[] → convertToLlm() → Message[] → LLM
(optional) (required)
The agent emits events for UI updates. Understanding the event sequence helps build responsive interfaces.
When you call prompt("Hello"):
prompt("Hello")
├─ agent_start
├─ turn_start
├─ message_start { message: userMessage } // Your prompt
├─ message_end { message: userMessage }
├─ message_start { message: assistantMessage } // LLM starts responding
├─ message_update { message: partial... } // Streaming chunks
├─ message_update { message: partial... }
├─ message_end { message: assistantMessage } // Complete response
├─ turn_end { message, toolResults: [] }
└─ agent_end { messages: [...] }
If the assistant calls tools, the loop continues:
prompt("Read config.json")
├─ agent_start
├─ turn_start
├─ message_start/end { userMessage }
├─ message_start { assistantMessage with toolCall }
├─ message_update...
├─ message_end { assistantMessage }
├─ tool_execution_start { toolCallId, toolName, args }
├─ tool_execution_update { partialResult } // If tool streams
├─ tool_execution_end { toolCallId, result }
├─ message_start/end { toolResultMessage }
├─ turn_end { message, toolResults: [toolResult] }
│
├─ turn_start // Next turn
├─ message_start { assistantMessage } // LLM responds to tool result
├─ message_update...
├─ message_end
├─ turn_end
└─ agent_end
continue() resumes from existing context without adding a new message. Use it for retries after errors.
// After an error, retry from current state
await agent.continue();
The last message in context must be user or toolResult (not assistant).
| Event | Description |
|---|---|
agent_start |
Agent begins processing |
agent_end |
Agent completes with all new messages |
turn_start |
New turn begins (one LLM call + tool executions) |
turn_end |
Turn completes with assistant message and tool results |
message_start |
Any message begins (user, assistant, toolResult) |
message_update |
Assistant only. Includes assistantMessageEvent with delta |
message_end |
Message completes |
tool_execution_start |
Tool begins |
tool_execution_update |
Tool streams progress |
tool_execution_end |
Tool completes |
const agent = new Agent({
// Initial state
initialState: {
systemPrompt: string[],
model: Model,
thinkingLevel: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max",
tools: AgentTool<any>[],
messages: AgentMessage[],
},
// Convert AgentMessage[] to LLM Message[] (required for custom message types)
convertToLlm: (messages) => messages.filter(...),
// Transform context before convertToLlm (for pruning, compaction)
transformContext: async (messages, signal) => pruneOldMessages(messages),
// How to handle queued messages: "one-at-a-time" (default) or "all"
queueMode: "one-at-a-time",
// Custom stream function (for proxy backends)
streamFn: streamProxy,
// Dynamic model-scoped API key resolution (for expiring OAuth tokens)
getApiKey: async (model) => tokenForModel(model),
// Tool execution context (late-bound UI/session access). Surface the loop's
// passive-context sink so tools can call ctx.addAdditionalContext(...).
getToolContext: toolCall => ({ addAdditionalContext: toolCall?.addAdditionalContext /* app-defined */ }),
});
interface AgentState {
systemPrompt: string[];
model: Model;
thinkingLevel: ThinkingLevel;
tools: AgentTool<any>[];
messages: AgentMessage[];
isStreaming: boolean;
streamMessage: AgentMessage | null; // Current partial during streaming
pendingToolCalls: Set<string>;
error?: string;
}
Access via agent.state. During streaming, streamMessage contains the partial assistant message.
// Text prompt
await agent.prompt("Hello");
// With images
await agent.prompt("What's in this image?", [{ type: "image", data: base64Data, mimeType: "image/jpeg" }]);
// AgentMessage directly
await agent.prompt({ role: "user", content: "Hello", timestamp: Date.now() });
// Continue from current context (last message must be user or toolResult)
await agent.continue();
agent.setSystemPrompt("New prompt");
agent.setModel(getModel("openai", "gpt-4o"));
agent.setThinkingLevel("medium");
agent.setTools([myTool]);
agent.replaceMessages(newMessages);
agent.appendMessage(message);
agent.clearMessages();
agent.reset(); // Clear everything
agent.abort(); // Cancel current operation
await agent.waitForIdle(); // Wait for completion
const unsubscribe = agent.subscribe(event => {
console.log(event.type);
});
unsubscribe();
Queue messages to inject during tool execution (steering) or after the agent would otherwise stop (follow-up):
agent.setSteeringMode("one-at-a-time");
agent.setInterruptMode("immediate");
// While agent is running tools
agent.steer({
role: "user",
content: "Stop! Do this instead.",
timestamp: Date.now(),
});
// Queue a follow-up to run after the current turn completes
agent.followUp({
role: "user",
content: "After that, summarize the changes.",
timestamp: Date.now(),
});
Steering messages are checked after each tool call by default. Set interruptMode to "wait" to defer
steering until the current turn completes.
Hosts can use setQueuedMessageGrouping((previous, next) => boolean) to keep adjacent companion
records and their prompt together in one-at-a-time mode. Without a grouping predicate, records
remain separate. replaceQueue("steering" | "followUp", messages) replaces only the selected queue.
Extend AgentMessage via declaration merging:
declare module "@oh-my-pi-zen/pi-agent" {
interface CustomAgentMessages {
notification: { role: "notification"; text: string; timestamp: number };
}
}
// Now valid
const msg: AgentMessage = { role: "notification", text: "Info", timestamp: Date.now() };
Handle custom types in convertToLlm:
const agent = new Agent({
convertToLlm: messages =>
messages.flatMap(m => {
if (m.role === "notification") return []; // Filter out
return [m];
}),
});
Define tools using AgentTool with an omptype parameter schema.
import { type } from "@oh-my-pi-zen/omptype";
const readFileTool: AgentTool = {
name: "read_file",
label: "Read File", // For UI display
description: "Read a file's contents",
parameters: type({
path: type("string").describe("File path"),
}),
execute: async (toolCallId, params, signal, onUpdate, context) => {
const content = await fs.readFile(params.path, "utf-8");
// Optional: stream progress
onUpdate?.({ content: [{ type: "text", text: "Reading..." }], details: {} });
return {
content: [{ type: "text", text: content }],
details: { path: params.path, size: content.length },
};
},
};
agent.setTools([readFileTool]);
Throw an error when a tool fails. Do not return error messages as content.
execute: async (toolCallId, params, signal, onUpdate) => {
if (!fs.existsSync(params.path)) {
throw new Error(`File not found: ${params.path}`);
}
// Return content only on success
return { content: [{ type: "text", text: "..." }] };
};
Thrown errors are caught by the agent and reported to the LLM as tool errors with isError: true.
For browser apps that proxy through a backend:
import { Agent, streamProxy } from "@oh-my-pi-zen/pi-agent";
const agent = new Agent({
streamFn: (model, context, options) =>
streamProxy(model, context, {
...options,
authToken: "...",
proxyUrl: "https://your-server.com",
}),
});
For direct control without the Agent class:
import { agentLoop, agentLoopContinue } from "@oh-my-pi-zen/pi-agent";
const context: AgentContext = {
systemPrompt: ["You are helpful."],
messages: [],
tools: [],
};
const config: AgentLoopConfig = {
model: getModel("openai", "gpt-4o"),
convertToLlm: msgs => msgs.filter(m => ["user", "assistant", "toolResult"].includes(m.role)),
};
const userMessage = { role: "user", content: "Hello", timestamp: Date.now() };
for await (const event of agentLoop([userMessage], context, config)) {
console.log(event.type);
}
// Continue from existing context
for await (const event of agentLoopContinue(context, config)) {
console.log(event.type);
}
Every invoke_agent produces two values alongside the OTEL spans:
AgentRunSummary — chat / tool / usage / cost / error counters bucketed
by status, with per-tool-name breakdowns. Pure aggregation, safe to
persist, diff, or assert.AgentRunCoverage — sorted+deduped toolsAvailable / toolsInvoked /
toolsUnused / modelsUsed / providersUsed arrays. Stable for snapshot
tests.Three delivery channels (use whichever fits):
agent_end event (additive)for await (const event of agentLoop([userMessage], context, {
...config,
telemetry: {},
})) {
if (event.type === "agent_end" && event.telemetry) {
console.log("tokens:", event.telemetry.usage.totalTokens);
console.log("unused tools:", event.coverage?.toolsUnused);
}
}
The messages field is unchanged. Consumers that ignore telemetry/
coverage continue to work.
onRunEnd hook (non-fatal)const stream = agentLoop([userMessage], context, {
...config,
telemetry: {
onRunEnd: (summary, coverage) => {
await persistRunSummary(summary, coverage);
},
},
});
Exceptions thrown from onRunEnd are caught and logged via console.warn;
a misbehaving telemetry consumer can never turn a successful agent run
into a failed one.
agentLoopDetailed (typed detailed() result)Convenience wrapper that preserves the existing stream API and exposes the rollup as a typed value:
const { stream, detailed } = agentLoopDetailed([userMessage], context, {
...config,
telemetry: {}, // required to populate telemetry/coverage
});
for await (const event of stream) {
// existing event handling
}
const { messages, telemetry, coverage } = await detailed();
stream.result() still resolves to AgentMessage[] — no breaking change.
Callers that drive the loop multiple times (verify pass, benchmark harness)
fold N summaries with aggregateAgentRunSummaries / aggregateAgentRunCoverage:
import { aggregateAgentRunSummaries, aggregateAgentRunCoverage } from "@oh-my-pi-zen/pi-agent";
const summaries: AgentRunSummary[] = [];
const coverages: AgentRunCoverage[] = [];
for (const target of targets) {
const { detailed } = agentLoopDetailed(/* ... */);
const result = await detailed();
if (result.telemetry) summaries.push(result.telemetry);
if (result.coverage) coverages.push(result.coverage);
}
const runSummary = aggregateAgentRunSummaries(summaries);
const runCoverage = aggregateAgentRunCoverage(coverages);
execute_tool spans carry omp.gen_ai.tool.status ∈
"ok" | "error" | "skipped" | "blocked" | "timeout" | "aborted".
beforeToolCall blocks throw a distinguishable ToolCallBlockedError
internally; the catch path reports status: "blocked" instead of conflating
with generic tool errors. Pre-run interrupts and tail-sweep skips are
recorded as "skipped" even though they never start a span.
MIT
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.