Skip to main content

Overview

The OffensiveSecurityAgent is the core agent harness that powers all specialized agents in Pensar Apex. It handles tool creation, stream management, and result resolution, allowing specialized agents to focus solely on their domain-specific logic. The agent owns tool creation — all available tools are built from the session context, and specific agents select which ones to activate via the activeTools array. The stream starts immediately on construction — no need to call a separate .run() method.

Key Features

  • Automatic Tool Management: Creates and manages all available tools from session context
  • Streaming by Default: Stream starts immediately on construction
  • Flexible Consumption: Multiple ways to consume the stream (callbacks, async iteration, raw stream)
  • Type-Safe Results: Generic type parameter TResult for typed return values
  • Approval Gate Integration: Optional approval gate for human-in-the-loop operations
  • Credential Management: Automatic credential resolution without exposing secrets to the model

Constructor

OffensiveSecurityAgentInput<TResult>
required
Configuration object for the agent

OffensiveSecurityAgentInput

string
required
System prompt defining agent persona and behavior
string
required
Initial user prompt that kicks off the agent
AIModel
required
AI model identifier (e.g., "claude-sonnet-4-20250514")
SessionInfo
required
Session providing paths for findings, POCs, logs, etc.
(ToolName | string)[]
required
Which tools the agent is allowed to use. Accepts both built-in tool names and custom tool names from extraTools.
string
The target URL / host — passed to browser tools for context
ToolSet
Additional tools to merge into the toolset. Use this to inject agent-specific tools without modifying the shared tool registry.
Array<ModelMessage>
Existing conversation history (for resumption / multi-turn)
StopCondition<ToolSet> | StopCondition<ToolSet>[]
Condition(s) under which the agent should stop
ToolChoice<ToolSet>
Strategy for selecting which tool to call
StreamTextOnStepFinishCallback<ToolSet>
Callback fired after each agent step completes
StreamTextOnFinishCallback<ToolSet>
Callback fired when the entire stream finishes
AbortSignal
AbortSignal to cancel the agent mid-run
AIAuthConfig
Per-provider API key overrides
UnifiedSandbox
When set, tools like execute_command / http_request / create_poc route execution through this sandbox instead of running locally
FindingsRegistry
Shared findings registry for cross-agent dedup. When present, document_vulnerability checks for duplicates before writing.
CredentialManager
In-memory credential store. When present, tools resolve credential IDs to secrets at execution time — the agent never sees raw passwords or tokens.
(streamResult: StreamTextResult<ToolSet, never>) => TResult | Promise<TResult>
Called after the stream is fully consumed to produce a typed result. If omitted, consume() returns void.
z.ZodSchema
Zod schema for structured output via the response tool. When provided, the base class automatically creates and injects a response tool, merges hasToolCall("response") into stop conditions, and defaults resolveResult to return the captured structured data.
ApprovalGate
When provided, each tool call is gated through the approval gate. The gate will pause execution until the operator approves or denies the call.
string
Identifier for this agent when running as a subagent
SubagentConsumeCallbacks
Callbacks for forwarding subagent stream events to the parent consumer
ConsumeCallbacks
Callbacks for persisting agent discoveries to external storage (e.g., database)

Methods

consume()

Consume the stream with typed callbacks, then resolve the final result.
ConsumeCallbacks
Optional callbacks for stream events
TResult
The value produced by resolveResult, or void if none was provided

ConsumeCallbacks

(delta: TextStreamPart) => void
Called when text is streamed from the model
(delta: ToolCallPart) => void
Called when a tool is invoked
(delta: ToolResultPart) => void
Called when a tool returns a result
(error: unknown) => void
Called when an error occurs
SubagentConsumeCallbacks
Callbacks for forwarding subagent events

Properties

streamResult

The underlying Vercel AI SDK stream result — escape hatch for advanced use.

fullStream

The raw async-iterable stream of chunks. Equivalent to streamResult.fullStream.

response

Promise that resolves to the final response metadata once the stream has been fully consumed.

Usage Examples

Basic Usage with Callbacks

Async Iteration

With Structured Output

With Approval Gate

With Credential Manager

Consumption Patterns

The agent stream can be consumed in three ways:
The underlying stream can only be consumed once. Choose one consumption pattern per agent instance.

Type Parameters

any
default:"void"
The type returned by consume(). When the input includes a resolveResult function, consume() awaits it after the stream finishes and returns the value.