Code Agents
TheAgentCtrl facade provides a unified interface for invoking CLI-based code agents that can execute code, modify files, and perform complex tasks.
Supported Agents
| Agent | Description | Use Case |
|---|---|---|
| Claude Code | Anthropic’s Claude agent with code execution | General coding tasks, file modifications |
| Codex | OpenAI’s Codex agent | Code generation and completion |
| OpenCode | Multi-model code agent | Research and coding with model flexibility |
Quick Start
Agent Selection
Claude Code
Best for general coding tasks with Anthropic’s Claude models:Codex
Best for OpenAI-powered code generation:OpenCode
Best for multi-model flexibility:Dynamic Selection
Select agent type at runtime:Configuration
Builder Methods
All agents support these configuration methods:Laravel Configuration
Configure defaults inconfig/instructor.php:
Environment Variables
Streaming
Process output in real-time with streaming callbacks:Response Object
TheAgentResponse object contains:
Session Management
Resume previous sessions for continued work:Error Handling
Testing
UseAgentCtrl::fake() for testing without actual agent execution:
Available Assertions
| Method | Description |
|---|---|
assertExecuted() | Agent was executed at least once |
assertNotExecuted() | Agent was never executed |
assertExecutedTimes(n) | Agent was executed exactly n times |
assertExecutedWith(prompt) | Prompt contains specific text |
assertAgentType(type) | Specific agent type was used |
assertUsedClaudeCode() | Claude Code agent was used |
assertUsedCodex() | Codex agent was used |
assertUsedOpenCode() | OpenCode agent was used |
assertStreaming() | Streaming execution was used |
getExecutions() | Get all recorded executions |
reset() | Reset fake state |
Real-World Examples
Code Generation Service
Queued Code Generation
Interactive Code Review
Sandbox Drivers
Control agent execution isolation:| Driver | Description | Use Case |
|---|---|---|
host | Direct execution (no isolation) | Development, trusted environments |
docker | Docker container isolation | Production, untrusted code |
podman | Podman container isolation | Rootless containers |
firejail | Linux sandbox | Lightweight isolation |
bubblewrap | Minimal sandbox | CI/CD environments |
Best Practices
- Set Timeouts: Always set appropriate timeouts for your use case
- Use Sandbox: In production, use Docker or other sandbox drivers
- Handle Errors: Check
isSuccess()and handle failures gracefully - Log Sessions: Store session IDs for debugging and continuation
- Test with Fakes: Use
AgentCtrl::fake()in tests to avoid API calls - Queue Long Tasks: Use Laravel queues for time-consuming operations