Loading repository data…
Loading repository data…
mwguerra / repository
Projeto MWGuerra/ConsoleAgent desenvolvido para a palestra Agentes de IA em PHP: Construindo Assistentes Autônomos no Terminal
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.
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 }}"
| 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
The project includes several example agents:
File: agents/project-documentation.yaml
File: agents/project-analyzer.yaml
File: agents/docs-via-mcp.yaml
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
.env file (not committed to version control)output/ directory by conventioneval() for condition evaluation (line 224 in ConsoleAgent.php) - exercise caution
in production environmentsgit checkout -b feature/amazing-featurecomposer testgit commit -m 'Add amazing feature'git push origin feature/amazing-featureThis project is licensed under the MIT License - see the LICENSE file for details.
agents/ directoryMade with ❤️ by MWGuerra