AgentCtrl Cheat Sheet
Entry Points
AgentType values:
AgentType::ClaudeCodeAgentType::CodexAgentType::OpenCodeAgentType::PiAgentType::Gemini
claude-codecodexopencodepigemini
Common Builder API
All builders support:withConfig(AgentCtrlConfig $config): staticwithModel(string $model): staticwithTimeout(int $seconds): staticinDirectory(string $path): staticwithSandboxDriver(SandboxDriver $driver): staticonText(callable $handler): staticonToolUse(callable $handler): staticonComplete(callable $handler): staticonError(callable $handler): staticexecute(string|\Stringable $prompt): AgentResponseexecuteStreaming(string|\Stringable $prompt): AgentResponsebuild(): AgentBridge
onText(fn(string $text): void)onToolUse(fn(string $tool, array $input, ?string $output): void)onComplete(fn(AgentResponse $response): void)onError(fn(string $message, ?string $code): void)
AgentCtrlConfig shared fields:
modeltimeoutworkingDirectorysandboxDriver
AgentCtrlConfig additional methods:
fromDsn(string $dsn): selfwithOverrides(array $values): selftoArray(): array
AgentCtrlConfig::fromArray() also accepts:
directory->workingDirectorysandbox->sandboxDriver
Claude Code
withSystemPrompt(string|\Stringable $prompt): staticappendSystemPrompt(string|\Stringable $prompt): staticwithMaxTurns(int $turns): staticwithPermissionMode(PermissionMode $mode): staticverbose(bool $enabled = true): staticcontinueSession(): staticresumeSession(string $sessionId): staticwithAdditionalDirs(array $paths): static
Codex
withSandbox(SandboxMode $mode): staticdisableSandbox(): staticfullAuto(bool $enabled = true): staticdangerouslyBypass(bool $enabled = true): staticskipGitRepoCheck(bool $enabled = true): staticcontinueSession(): staticresumeSession(string $sessionId): staticwithAdditionalDirs(array $paths): staticwithImages(array $imagePaths): static
OpenCode
withAgent(string $agentName): staticwithFiles(array $filePaths): staticcontinueSession(): staticresumeSession(string $sessionId): staticshareSession(): staticwithTitle(string $title): static
Pi
withProvider(string $provider): staticwithThinking(ThinkingLevel $level): staticwithSystemPrompt(string|\Stringable $prompt): staticappendSystemPrompt(string|\Stringable $prompt): staticwithTools(array $tools): staticnoTools(): staticwithFiles(array $filePaths): staticwithExtensions(array $extensions): staticnoExtensions(): staticwithSkills(array $skills): staticnoSkills(): staticwithApiKey(string $apiKey): staticcontinueSession(): staticresumeSession(string $sessionId): staticephemeral(): staticwithSessionDir(string $dir): staticverbose(bool $enabled = true): static
Gemini
withApprovalMode(ApprovalMode $mode): staticyolo(): staticplanMode(): staticwithSandbox(bool $enabled = true): staticwithIncludeDirectories(array $paths): staticwithExtensions(array $extensions): staticwithAllowedTools(array $tools): staticwithAllowedMcpServers(array $names): staticwithPolicy(array $paths): staticcontinueSession(): staticresumeSession(string $sessionId): staticdebug(bool $enabled = true): static
Sessions
sessionId() returns AgentSessionId|null.
Response
AgentResponse public properties:
agentTypetextexitCodeusagecosttoolCallsrawResponseparseFailures
AgentResponse methods:
sessionId(): ?AgentSessionIdisSuccess(): booltext(): stringusage(): ?TokenUsagecost(): ?floatparseFailures(): intparseFailureSamples(): array
Tool Calls and Usage
ToolCall:
toolinputoutputisErrorcallId(): ?AgentToolCallIdisCompleted(): bool
TokenUsage:
inputoutputcacheReadcacheWritereasoningtotal(): int
StreamHandler
StreamHandler interface (Cognesy\AgentCtrl\Contract\StreamHandler):
onText(string $text): voidonToolUse(ToolCall $toolCall): voidonComplete(AgentResponse $response): voidonError(StreamError $error): void
CallbackStreamHandler implements StreamHandler with optional closures:
hasTextHandler(): boolhasToolUseHandler(): boolhasCompleteHandler(): boolhasErrorHandler(): boolhasAnyHandler(): bool
StreamError:
message(string)code(?string)details(array<string,mixed>)
Events
Concrete builders also expose event wiring throughHandlesEvents:
withEventHandler(CanHandleEvents $events): staticwiretap(?callable $listener): selfonEvent(string $class, ?callable $listener): self
Cognesy\AgentCtrl\Event\*):
Execution lifecycle:
AgentExecutionStarted— execution beginsAgentExecutionCompleted— execution finishesExecutionAttempted— an execution attempt is made
RequestBuilt— request object assembledCommandSpecCreated— CLI command spec created
ProcessExecutionStarted— sandbox process startsProcessExecutionCompleted— sandbox process finishes
StreamProcessingStarted— stream parsing beginsStreamChunkProcessed— a JSONL chunk is parsedStreamProcessingCompleted— stream parsing finishes
ResponseParsingStarted— response parser beginsResponseDataExtracted— data extracted from raw responseResponseParsingCompleted— response parser finishes
AgentTextReceived— text content receivedAgentToolUsed— tool call detectedAgentErrorOccurred— error event from agent
SandboxInitialized— sandbox driver initializedSandboxPolicyConfigured— sandbox policy setSandboxReady— sandbox ready for execution
Testing
Deterministic test seams:- core package logic
- test
AgentCtrlConfig, command builders, parsers, and DTOs directly
- test
Cognesy\Sandbox\Testing\FakeSandbox- use for deterministic command execution without running a real CLI
- best for bridge execution paths, timeout behavior, and stdout/stderr handling
Cognesy\Instructor\Laravel\Testing\AgentCtrlFake- use only when testing the Laravel facade layer
- queued responses and execution assertions live there, not in core
agent-ctrl