Skip to main content

Overview

AgentCtrl provides a unified interface for executing prompts against CLI-based code agents (like Claude Code, OpenCode, Codex, etc.). This example demonstrates the simplest possible usage: sending a prompt and receiving a structured response with metadata. Key concepts:
  • AgentCtrl::make(): Factory for creating agent instances
  • AgentType: Enum specifying which CLI agent to use
  • AgentResponse: Structured response with text, session info, usage stats, and cost
  • AgentCtrlConsoleLogger: Provides visibility into agent execution stages

Example

Expected Output

Key Points

  • Unified interface: Same API works across different CLI agents
  • Agent selection: Use AgentType enum to specify which agent to use
  • Console logger: AgentCtrlConsoleLogger shows execution stages with color-coded labels
  • Response metadata: Access session IDs, token usage, and cost information
  • Typed config: AgentCtrlConfig packages shared builder options into one object
  • Error handling: Check isSuccess() before accessing response data
  • Simple execution: One method call (execute()) handles the entire interaction