Introduction
Every call toexecute() 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 theAgentResponse 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:
- 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:
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
ThetoolCalls array contains ToolCall objects — a normalized representation of every tool invocation across all agent types. Each ToolCall has the following structure:
ToolCall Properties
| Property | Type | Description |
|---|---|---|
tool | string | The tool name (e.g., 'bash', 'file_change', 'web_search', 'tool_result') |
input | array | The tool’s input parameters as an associative array |
output | ?string | The tool’s output, or null if not yet completed |
isError | bool | Whether the tool call resulted in an error |
ToolCall Methods
| Method | Return Type | Description |
|---|---|---|
callId() | ?AgentToolCallId | The unique identifier for this tool call, or null |
isCompleted() | bool | Whether the tool has produced output (output !== null) |
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 separatetool_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
CommandExecutionbecomestool: 'bash',input: ['command' => '...']FileChangebecomestool: 'file_change',input: ['path' => '...', 'action' => '...']McpToolCallbecomestool: <original tool name>,input: <arguments>WebSearchbecomestool: 'web_search',input: ['query' => '...']PlanUpdatebecomestool: 'plan_update'Reasoningbecomestool: 'reasoning'
ToolUseEvent.
Working with Tool Calls
Token Usage
TheTokenUsage DTO provides detailed token statistics when the agent’s CLI exposes this data. It is defined at Cognesy\AgentCtrl\Dto\TokenUsage.
TokenUsage Properties
| Property | Type | Description |
|---|---|---|
input | int | Number of input tokens consumed |
output | int | Number of output tokens produced |
cacheRead | ?int | Tokens read from cache (when available) |
cacheWrite | ?int | Tokens written to cache (when available) |
reasoning | ?int | Tokens used for reasoning (when available) |
TokenUsage Methods
| Method | Return Type | Description |
|---|---|---|
total() | int | Sum of input and output tokens |
Usage Data Availability by Agent
| Agent | Token Usage | Cost |
|---|---|---|
| Claude Code | No | No |
| Codex | Yes (input, output, cacheRead) | No |
| OpenCode | Yes (input, output, cacheRead, cacheWrite, reasoning) | Yes |
| Pi | Yes (input, output, cacheRead, cacheWrite) | Yes |
| Gemini | Yes (input, output, cacheRead) | No |