Skip to main content

Overview

This example demonstrates how to use the Pi CLI integration to execute simple prompts. The AgentCtrl facade provides a clean API for invoking the pi CLI in JSON mode with full event observability. Key concepts:
  • AgentCtrl::pi(): Factory for Pi agent builder
  • ephemeral(): Run without saving session state
  • withThinking(): Control reasoning depth (6 levels from off to xhigh)
  • AgentCtrlConsoleLogger: Shows execution lifecycle with color-coded labels

Example

Expected Output

Key Points

  • Simple execution: One method call handles the entire interaction
  • Full observability: Console logger shows request building, sandbox setup, and response parsing
  • Ephemeral mode: Use ephemeral() for one-off prompts that don’t need session persistence
  • Cost and usage: Pi provides both token usage and cost data in the response