runOffensiveSecurityAgent
Runs the general-purpose offensive security agent behind /operator mode and pensar -p. Unlike the specialized runners, it has no fixed workflow. You give it a prompt and a set of tools, and it works until the model finishes or a stop condition is met.
If you omit session, a session is created for you. Pass onSessionReady to receive it as soon as it exists. After each step, the conversation is saved to messages.json in the session directory.
Parameters
The user prompt that starts the run.
Model ID. See Models.
Tools the agent may call. Use ALL_TOOL_NAMES and SKILL_TOOL_NAMES from @pensar/apex/agents/offSecAgent for the full operator toolset, or pass a subset to restrict it.
Existing session to run in. When omitted, one is created from sessionConfig.
Config for the auto-created session. Ignored when session is set. See sessions.
AI provider credentials.
Target URL or host, passed to browser tools as context.
Replaces Apex’s base system prompt. The session workspace section is always appended.
Earlier conversation history, for multi-turn runs. The history must end with a user message.
AI SDK stop condition, for example stepCountIs(200).
plan restricts the agent to read-only tools. fast-strike runs one focused operator loop.
Your own AI SDK tools, merged into the toolset. Add their names to activeTools to enable them.
Streaming events. See AgentEventBus.
Cancels the run. Not accepted by createOffensiveSecurityAgentClient().run(), which owns its own signal.
Extended-thinking setting. See Reasoning.
Called with the session (provided or auto-created) before the agent starts.
Returns
Promise<RunAgentResult>
The completed AI SDK stream result. Read await streamResult.text, await streamResult.steps, or await streamResult.totalUsage.
The session the run used. This is the only way to get it when it was auto-created.
Run metrics. Only set when mode is lance.
Example
stepCountIs and ModelMessage come from the AI SDK (ai package), which @pensar/apex depends on. If your package manager doesn’t hoist dependencies (for example, pnpm), add ai to your own dependencies.
createOffensiveSecurityAgentClient
Creates a single-use client that owns the abort signal for one run. abort() works immediately, even while run() is still creating the session. Calling run() a second time throws, so create a new client for each run.