A PHP-based AI agent management system that executes workflow-driven tasks using OpenAI's API
ConsoleAgent is a powerful framework for creating and executing AI-powered workflows through YAML configuration files. Define complex multi-step processes with conditional logic, user interactions, file operations, and LLM integration - all through simple configuration files.
- 📝 YAML-Driven Workflows: Define complex multi-step processes in simple YAML files
- 🤖 OpenAI Integration: Built-in support for GPT models with configurable parameters
- 🔄 Conditional Logic: Dynamic workflow routing based on user input and context variables
- 👤 Interactive Prompts: Collect user input through various UI components (text, radio, multi-choice)
- 📁 File Operations: Read from and write to files during workflow execution
- 🔄 Iteration Support: Process arrays and lists with per-item actions
- 🌐 MCP Support: Model Context Protocol integration for extended capabilities
- 🎯 Context Management: Share variables between workflow steps with template syntax
- 🧪 Testing: Comprehensive test suite with Pest framework
- 🛠️ Debug Mode: Built-in debugging and dry-run capabilities
- PHP 8.3 or higher
- Composer
- OpenAI API key
-
Clone the repository:
git clone https://github.com/mwguerra/console-agent.git cd console-agent
-
Install dependencies:
composer install
-
Set up environment:
cp .env.example .env # Edit .env and add your OpenAI API key echo "OPENAI_API_KEY=your-api-key-here" >> .env
-
Run an example agent:
php agent agents/project-documentation.yaml
# Run an agent
php agent path/to/agent.yaml
# Debug mode (shows detailed execution info)
php agent path/to/agent.yaml --debug
# Dry run (shows what would happen without executing)
php agent path/to/agent.yaml --dry-run
Create a YAML file in the agents/
directory:
# agents/my-agent.yaml
agent:
name: "MyAgent"
description: "A simple example agent"
version: "1.0.0"
llm:
model: "gpt-4o-mini"
temperature: 0.7
max_tokens: 1500
workflow:
steps:
- id: step_1
name: "Get User Input"
action:
type: user_input
input_type: text
prompt: "What would you like to document?"
output:
type: text
store_as: user_response
next_step: step_2
- id: step_2
name: "Process with LLM"
action:
type: llm
prompt: "Based on this input: {{ user_response }}, create a brief summary."
output:
type: text
store_as: summary
next_step: step_3
- id: step_3
name: "Save Result"
action:
type: file_write
path: "output/summary.md"
content: "# Summary\n\n{{ summary }}"
- ConsoleAgent.php: Main orchestrator that loads configurations and executes workflows
- WorkflowRunner: Handles step-by-step execution with conditional logic
- ActionRegistry: Manages available action types (LLM, user input, file operations, etc.)
- Context: Maintains variables and state across workflow steps
- Services: LLM and MCP service integrations
Action Type | Description | Example Use Case |
---|---|---|
user_input |
Collect user input via prompts | Gathering project requirements |
llm |
Call OpenAI API with prompts | Content generation, analysis |
file_write |
Write content to files | Saving generated documentation |
file_read |
Read file contents | Loading templates or data |
display |
Show messages to user | Progress updates, results |
script |
Execute shell commands | Project analysis, file operations |
mcp |
Model Context Protocol calls | Extended AI capabilities |
iteration |
Loop over arrays/lists | Processing multiple items |
Use {{ variable_name }}
syntax to reference context variables:
- action:
type: llm
prompt: "Analyze this project: {{ project_description }}"
output:
store_as: analysis
next_steps:
- step: approve_step
condition: "{{ user_decision }} == 'approve'"
- step: modify_step
condition: "{{ user_decision }} == 'modify'"
- step: exit_step
condition: "{{ user_decision }} == 'cancel'"
console-agent/
├── agents/ # YAML agent configurations
│ ├── project-documentation.yaml
│ ├── project-analyzer.yaml
│ └── docs-via-mcp.yaml
├── src/ # Core PHP classes
│ ├── Actions/ # Action implementations
│ ├── Console/ # Console interface and utilities
│ ├── Core/ # Core workflow components
│ └── Services/ # External service integrations
├── config/ # Configuration files
├── tests/ # Test suite
├── output/ # Generated files output directory
└── vendor/ # Composer dependencies
Run the comprehensive test suite:
# Run all tests
composer test
# or
vendor/bin/pest
# Run specific test categories
vendor/bin/pest tests/Feature/
vendor/bin/pest tests/Unit/Services/
# Run with coverage
vendor/bin/pest --coverage
- Feature Tests: End-to-end agent execution scenarios
- Unit Tests: Individual component testing
- Service Tests: OpenAI and MCP service integration tests
- Action Tests: Individual action type validation
The project includes several example agents:
File: agents/project-documentation.yaml
- Collects project details from user
- Generates comprehensive documentation
- Creates structured markdown files
File: agents/project-analyzer.yaml
- Analyzes existing codebases
- Identifies project structure and dependencies
- Generates technical documentation
File: agents/docs-via-mcp.yaml
- Demonstrates MCP (Model Context Protocol) integration
- Advanced AI capabilities beyond standard LLM calls
OPENAI_API_KEY=your-openai-api-key
DEBUG=false
DRY_RUN=false
agent:
name: "Agent Name"
description: "What this agent does"
version: "1.0.0"
llm:
model: "gpt-4o-mini" # OpenAI model to use
temperature: 0.7 # Creativity level (0.0-1.0)
max_tokens: 1500 # Maximum response length
workflow:
steps:
# Define your workflow steps here
- Environment Variables: API keys are loaded from
.env
file (not committed to version control) - File Operations: Limited to
output/
directory by convention - Input Validation: User inputs are validated before processing
⚠️ Important: The system useseval()
for condition evaluation (line 224 in ConsoleAgent.php) - exercise caution in production environments
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes
- Run tests:
composer test
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation for significant changes
- Use semantic commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Documentation: See example agents in
agents/
directory - Email: [email protected]
- OpenAI for providing the AI capabilities
- Laravel Prompts for the beautiful console interface
- Pest PHP for the elegant testing framework
- The PHP community for excellent packages and tools
Made with ❤️ by MWGuerra