-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eadd395
Showing
22 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
/vendor | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) llm-agents-php <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Symfony C | ||
|
||
[![PHP](https://img.shields.io/packagist/php-v/llm-agents/agent-symfony-console.svg?style=flat-square)](https://packagist.org/packages/llm-agents/agent-symfony-console) | ||
[![Latest Version on Packagist](https://img.shields.io/packagist/v/llm-agents/agent-symfony-console.svg?style=flat-square)](https://packagist.org/packages/llm-agents/agent-symfony-console) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/llm-agents/agent-symfony-console.svg?style=flat-square)](https://packagist.org/packages/llm-agents/agent-symfony-console) | ||
|
||
### Installation | ||
|
||
First things first, let's get this package installed: | ||
|
||
```bash | ||
composer require llm-agents/agent-symfony-console | ||
``` | ||
|
||
### Setup in Spiral Framework | ||
|
||
To get the Site Status Checker Agent up and running in your Spiral Framework project, you need to register its | ||
bootloader. | ||
|
||
**Here's how:** | ||
|
||
1. Open up your `app/src/Application/Kernel.php` file. | ||
2. Add the bootloader like this: | ||
```php | ||
public function defineBootloaders(): array | ||
{ | ||
return [ | ||
// ... other bootloaders ... | ||
\LLM\Agents\Agent\SymfonyConsole\Integrations\Spiral\SymfonyConsoleBootloader::class, | ||
]; | ||
} | ||
``` | ||
|
||
And that's it! Your Spiral app is now ready to use the agent. | ||
|
||
## Want to help out? 🤝 | ||
|
||
We love contributions! If you've got ideas to make this agent even cooler, here's how you can chip in: | ||
|
||
1. Fork the repo | ||
2. Make your changes | ||
3. Create a new Pull Request | ||
|
||
Just make sure your code is clean, well-commented, and follows PSR-12 coding standards. | ||
|
||
## License 📄 | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
|
||
--- | ||
|
||
That's all, folks! If you've got any questions or run into any trouble, don't hesitate to open an issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "llm-agents/agent-symfony-console", | ||
"description": "Simple agent that can handle Symfony Console commands based on user input", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^8.3", | ||
"llm-agents/agents": "^1.0", | ||
"llm-agents/json-schema-mapper": "^1.0", | ||
"symfony/console": "^6.0||^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^11.3", | ||
"spiral/boot": "^3.13", | ||
"illuminate/support": "^11.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LLM\\Agents\\Agent\\SymfonyConsole\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"LLM\\Agents\\Agent\\SymfonyConsole\\Tests\\": "tests/src" | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use Spiral\JsonSchemaGenerator\Attribute\Field; | ||
|
||
final readonly class Argument | ||
{ | ||
public function __construct( | ||
#[Field(title: 'Key', description: 'The key of the argument')] | ||
public string $key, | ||
|
||
#[Field(title: 'Value', description: 'The value of the argument')] | ||
public string $value, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
interface CommandManagerInterface | ||
{ | ||
public function getCommandHelp(string $command): string; | ||
|
||
/** | ||
* @return array<non-empty-string, Command> | ||
*/ | ||
public function getCommands(): array; | ||
|
||
/** | ||
* Run a console command by name. | ||
* | ||
* @return int The command exit code | ||
*/ | ||
public function call( | ||
string|\Stringable $command, | ||
array $parameters = [], | ||
?OutputInterface $output = null, | ||
): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use Spiral\JsonSchemaGenerator\Attribute\Field; | ||
|
||
final readonly class ExecuteCommandInput | ||
{ | ||
public function __construct( | ||
#[Field(title: 'Command', description: 'The name of the command to execute')] | ||
public string $command, | ||
|
||
/** @var array<Argument> */ | ||
#[Field(title: 'Arguments', description: 'Command arguments')] | ||
public array $arguments, | ||
|
||
/** @var array<Option> */ | ||
#[Field(title: 'Options', description: 'Command options')] | ||
public array $options, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use LLM\Agents\Tool\Tool; | ||
use LLM\Agents\Tool\ToolLanguage; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
|
||
final class ExecuteCommandTool extends Tool | ||
{ | ||
public const NAME = 'execute_command'; | ||
|
||
public function __construct( | ||
private readonly CommandManagerInterface $application, | ||
) { | ||
parent::__construct( | ||
name: self::NAME, | ||
inputSchema: ExecuteCommandInput::class, | ||
description: 'This tool executes a console command with the provided arguments and options.', | ||
); | ||
} | ||
|
||
public function getLanguage(): ToolLanguage | ||
{ | ||
return ToolLanguage::PHP; | ||
} | ||
|
||
public function execute(object $input): string | ||
{ | ||
$arguments = []; | ||
|
||
foreach ($input->arguments as $argument) { | ||
$arguments[$argument->key] = $argument->value; | ||
} | ||
|
||
foreach ($input->options as $option) { | ||
$arguments[$option->key] = $option->value; | ||
} | ||
|
||
$output = new BufferedOutput(); | ||
|
||
try { | ||
$exitCode = $this->application->call($input->command, $arguments, $output); | ||
$result = [ | ||
'success' => $exitCode === 0, | ||
'output' => $output->fetch(), | ||
'exit_code' => $exitCode, | ||
]; | ||
} catch (\Exception $e) { | ||
$result = [ | ||
'success' => false, | ||
'error' => $e->getMessage(), | ||
]; | ||
} | ||
|
||
return \json_encode($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use Spiral\JsonSchemaGenerator\Attribute\Field; | ||
|
||
final readonly class GetCommandDetailsInput | ||
{ | ||
public function __construct( | ||
#[Field(title: 'Command', description: 'The name of the command to get details for')] | ||
public string $command, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use LLM\Agents\Tool\Tool; | ||
use LLM\Agents\Tool\ToolLanguage; | ||
|
||
final class GetCommandDetailsTool extends Tool | ||
{ | ||
public const NAME = 'get_command_details'; | ||
|
||
public function __construct( | ||
private readonly CommandManagerInterface $application, | ||
) { | ||
parent::__construct( | ||
name: self::NAME, | ||
inputSchema: GetCommandDetailsInput::class, | ||
description: 'Retrieves detailed information about a specific console command, including usage, arguments, and options.', | ||
); | ||
} | ||
|
||
public function getLanguage(): ToolLanguage | ||
{ | ||
return ToolLanguage::PHP; | ||
} | ||
|
||
public function execute(object $input): string | ||
{ | ||
$details = $this->application->getCommandHelp($input->command); | ||
|
||
return \json_encode([ | ||
'help' => $details, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use Spiral\JsonSchemaGenerator\Attribute\Field; | ||
|
||
final readonly class GetCommandsListInput | ||
{ | ||
public function __construct( | ||
#[Field(title: 'Namespace', description: 'Optional namespace to filter commands. Empty string to retrieve all commands')] | ||
public string $namespace, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\Agent\SymfonyConsole; | ||
|
||
use LLM\Agents\Tool\Tool; | ||
use LLM\Agents\Tool\ToolLanguage; | ||
|
||
final class GetCommandsListTool extends Tool | ||
{ | ||
public const NAME = 'get_commands_list'; | ||
|
||
public function __construct( | ||
private readonly CommandManagerInterface $application, | ||
) { | ||
parent::__construct( | ||
name: self::NAME, | ||
inputSchema: GetCommandsListInput::class, | ||
description: 'Retrieves a list of available console commands with their descriptions.', | ||
); | ||
} | ||
|
||
public function getLanguage(): ToolLanguage | ||
{ | ||
return ToolLanguage::PHP; | ||
} | ||
|
||
public function execute(object $input): string | ||
{ | ||
$commands = $this->application->getCommands(); | ||
$result = []; | ||
|
||
foreach ($commands as $name => $command) { | ||
$result[] = [ | ||
'name' => $name, | ||
'description' => $command->getDescription(), | ||
]; | ||
} | ||
|
||
return \json_encode($result); | ||
} | ||
} |
Oops, something went wrong.