Skip to main content

Introduction

Every call to execute() or executeStreaming() returns an AgentResponse — a readonly DTO that provides a normalized view of the agent’s output regardless of which CLI tool produced it. The response contains the text content, process exit code, session identifier, token usage statistics, cost, tool call records, and parse diagnostics. The AgentResponse class is defined at Cognesy\AgentCtrl\Dto\AgentResponse.

Response Properties

The following public properties are available directly on the AgentResponse object:

agentType: AgentType

The agent type that produced this response. This is one of AgentType::ClaudeCode, AgentType::Codex, AgentType::OpenCode, AgentType::Pi, or AgentType::Gemini:

text: string

The agent’s main text output. This is the concatenation of all text content blocks from the agent’s response. For most use cases, you should access this through the text() method instead:

exitCode: int

The process exit code. A value of 0 indicates success. Non-zero values indicate errors, timeouts, or other failures:
Common exit codes:
  • 0 — Success
  • 1 — General error (invalid configuration, agent-side failure)
  • 2 — Invalid arguments passed to the CLI
  • 124 / 137 — Process killed due to timeout

usage: ?TokenUsage

Token usage statistics, when available. This is null for agents that do not expose usage data (Claude Code does not; Codex, OpenCode, Pi, and Gemini do when the data is present in the CLI output):

cost: ?float

The estimated cost in USD, when available. Currently, OpenCode and Pi expose cost data:

toolCalls: array

An array of ToolCall objects representing every tool invocation made during the execution. See the Tool Calls section below for details:

rawResponse: mixed

The original bridge-specific response object (ClaudeResponse, CodexResponse, OpenCodeResponse, PiResponse, or GeminiResponse). This provides access to agent-specific data that is not part of the normalized response:

parseFailures: int

The number of malformed JSON lines that were skipped during response parsing:

Response Methods

isSuccess(): bool

Returns true if the exit code is 0. This is the recommended way to check whether the execution succeeded:
A completed execution with a non-zero exit code does not throw an exception. Always check isSuccess() before treating the text output as authoritative.

text(): string

Returns the agent’s text output. Equivalent to accessing the text property directly:

sessionId(): ?AgentSessionId

Returns the session identifier as an AgentSessionId value object, or null if no session ID was available. The value object implements __toString() for easy serialization:

usage(): ?TokenUsage

Returns the token usage statistics, or null if the agent does not expose this data:

cost(): ?float

Returns the estimated cost in USD, or null if the agent does not expose cost data:

parseFailures(): int

Returns the number of malformed JSON lines encountered during parsing:

parseFailureSamples(): array

Returns a list of sample malformed payload strings (truncated to 200 characters each) for debugging purposes:

Tool Calls

The toolCalls array contains ToolCall objects — a normalized representation of every tool invocation across all agent types. Each ToolCall has the following structure:

ToolCall Properties

ToolCall Methods

Tool Name Normalization

Agent-Ctrl normalizes tool names across all agents so you can handle them consistently: Claude Code tool calls preserve their original tool names and include separate tool_result entries for tool outputs:
  • Tool invocations: original tool name (e.g., 'Read', 'Edit', 'Bash')
  • Tool results: 'tool_result' with ['tool_use_id' => '...'] in the input
Codex items are normalized as follows:
  • CommandExecution becomes tool: 'bash', input: ['command' => '...']
  • FileChange becomes tool: 'file_change', input: ['path' => '...', 'action' => '...']
  • McpToolCall becomes tool: <original tool name>, input: <arguments>
  • WebSearch becomes tool: 'web_search', input: ['query' => '...']
  • PlanUpdate becomes tool: 'plan_update'
  • Reasoning becomes tool: 'reasoning'
OpenCode tool calls preserve their original tool names from the ToolUseEvent.

Working with Tool Calls

Token Usage

The TokenUsage DTO provides detailed token statistics when the agent’s CLI exposes this data. It is defined at Cognesy\AgentCtrl\Dto\TokenUsage.

TokenUsage Properties

TokenUsage Methods

Usage Data Availability by Agent

Complete Example