Skip to content

Commit eadd395

Browse files
committed
Init project
0 parents  commit eadd395

22 files changed

+884
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
/vendor
3+
/.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) llm-agents-php <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Symfony C
2+
3+
[![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)
4+
[![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)
5+
[![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)
6+
7+
### Installation
8+
9+
First things first, let's get this package installed:
10+
11+
```bash
12+
composer require llm-agents/agent-symfony-console
13+
```
14+
15+
### Setup in Spiral Framework
16+
17+
To get the Site Status Checker Agent up and running in your Spiral Framework project, you need to register its
18+
bootloader.
19+
20+
**Here's how:**
21+
22+
1. Open up your `app/src/Application/Kernel.php` file.
23+
2. Add the bootloader like this:
24+
```php
25+
public function defineBootloaders(): array
26+
{
27+
return [
28+
// ... other bootloaders ...
29+
\LLM\Agents\Agent\SymfonyConsole\Integrations\Spiral\SymfonyConsoleBootloader::class,
30+
];
31+
}
32+
```
33+
34+
And that's it! Your Spiral app is now ready to use the agent.
35+
36+
## Want to help out? 🤝
37+
38+
We love contributions! If you've got ideas to make this agent even cooler, here's how you can chip in:
39+
40+
1. Fork the repo
41+
2. Make your changes
42+
3. Create a new Pull Request
43+
44+
Just make sure your code is clean, well-commented, and follows PSR-12 coding standards.
45+
46+
## License 📄
47+
48+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
49+
50+
---
51+
52+
That's all, folks! If you've got any questions or run into any trouble, don't hesitate to open an issue.

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "llm-agents/agent-symfony-console",
3+
"description": "Simple agent that can handle Symfony Console commands based on user input",
4+
"license": "MIT",
5+
"require": {
6+
"php": "^8.3",
7+
"llm-agents/agents": "^1.0",
8+
"llm-agents/json-schema-mapper": "^1.0",
9+
"symfony/console": "^6.0||^7.0"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^11.3",
13+
"spiral/boot": "^3.13",
14+
"illuminate/support": "^11.0"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"LLM\\Agents\\Agent\\SymfonyConsole\\": "src"
19+
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"LLM\\Agents\\Agent\\SymfonyConsole\\Tests\\": "tests/src"
24+
}
25+
},
26+
"config": {
27+
"sort-packages": true
28+
},
29+
"minimum-stability": "dev",
30+
"prefer-stable": true
31+
}

src/Argument.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use Spiral\JsonSchemaGenerator\Attribute\Field;
8+
9+
final readonly class Argument
10+
{
11+
public function __construct(
12+
#[Field(title: 'Key', description: 'The key of the argument')]
13+
public string $key,
14+
15+
#[Field(title: 'Value', description: 'The value of the argument')]
16+
public string $value,
17+
) {}
18+
}

src/CommandManagerInterface.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
interface CommandManagerInterface
11+
{
12+
public function getCommandHelp(string $command): string;
13+
14+
/**
15+
* @return array<non-empty-string, Command>
16+
*/
17+
public function getCommands(): array;
18+
19+
/**
20+
* Run a console command by name.
21+
*
22+
* @return int The command exit code
23+
*/
24+
public function call(
25+
string|\Stringable $command,
26+
array $parameters = [],
27+
?OutputInterface $output = null,
28+
): int;
29+
}

src/ExecuteCommandInput.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use Spiral\JsonSchemaGenerator\Attribute\Field;
8+
9+
final readonly class ExecuteCommandInput
10+
{
11+
public function __construct(
12+
#[Field(title: 'Command', description: 'The name of the command to execute')]
13+
public string $command,
14+
15+
/** @var array<Argument> */
16+
#[Field(title: 'Arguments', description: 'Command arguments')]
17+
public array $arguments,
18+
19+
/** @var array<Option> */
20+
#[Field(title: 'Options', description: 'Command options')]
21+
public array $options,
22+
) {}
23+
}

src/ExecuteCommandTool.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use LLM\Agents\Tool\Tool;
8+
use LLM\Agents\Tool\ToolLanguage;
9+
use Symfony\Component\Console\Output\BufferedOutput;
10+
11+
final class ExecuteCommandTool extends Tool
12+
{
13+
public const NAME = 'execute_command';
14+
15+
public function __construct(
16+
private readonly CommandManagerInterface $application,
17+
) {
18+
parent::__construct(
19+
name: self::NAME,
20+
inputSchema: ExecuteCommandInput::class,
21+
description: 'This tool executes a console command with the provided arguments and options.',
22+
);
23+
}
24+
25+
public function getLanguage(): ToolLanguage
26+
{
27+
return ToolLanguage::PHP;
28+
}
29+
30+
public function execute(object $input): string
31+
{
32+
$arguments = [];
33+
34+
foreach ($input->arguments as $argument) {
35+
$arguments[$argument->key] = $argument->value;
36+
}
37+
38+
foreach ($input->options as $option) {
39+
$arguments[$option->key] = $option->value;
40+
}
41+
42+
$output = new BufferedOutput();
43+
44+
try {
45+
$exitCode = $this->application->call($input->command, $arguments, $output);
46+
$result = [
47+
'success' => $exitCode === 0,
48+
'output' => $output->fetch(),
49+
'exit_code' => $exitCode,
50+
];
51+
} catch (\Exception $e) {
52+
$result = [
53+
'success' => false,
54+
'error' => $e->getMessage(),
55+
];
56+
}
57+
58+
return \json_encode($result);
59+
}
60+
}

src/GetCommandDetailsInput.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use Spiral\JsonSchemaGenerator\Attribute\Field;
8+
9+
final readonly class GetCommandDetailsInput
10+
{
11+
public function __construct(
12+
#[Field(title: 'Command', description: 'The name of the command to get details for')]
13+
public string $command,
14+
) {}
15+
}

src/GetCommandDetailsTool.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use LLM\Agents\Tool\Tool;
8+
use LLM\Agents\Tool\ToolLanguage;
9+
10+
final class GetCommandDetailsTool extends Tool
11+
{
12+
public const NAME = 'get_command_details';
13+
14+
public function __construct(
15+
private readonly CommandManagerInterface $application,
16+
) {
17+
parent::__construct(
18+
name: self::NAME,
19+
inputSchema: GetCommandDetailsInput::class,
20+
description: 'Retrieves detailed information about a specific console command, including usage, arguments, and options.',
21+
);
22+
}
23+
24+
public function getLanguage(): ToolLanguage
25+
{
26+
return ToolLanguage::PHP;
27+
}
28+
29+
public function execute(object $input): string
30+
{
31+
$details = $this->application->getCommandHelp($input->command);
32+
33+
return \json_encode([
34+
'help' => $details,
35+
]);
36+
}
37+
}

src/GetCommandsListInput.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use Spiral\JsonSchemaGenerator\Attribute\Field;
8+
9+
final readonly class GetCommandsListInput
10+
{
11+
public function __construct(
12+
#[Field(title: 'Namespace', description: 'Optional namespace to filter commands. Empty string to retrieve all commands')]
13+
public string $namespace,
14+
) {}
15+
}

src/GetCommandsListTool.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent\SymfonyConsole;
6+
7+
use LLM\Agents\Tool\Tool;
8+
use LLM\Agents\Tool\ToolLanguage;
9+
10+
final class GetCommandsListTool extends Tool
11+
{
12+
public const NAME = 'get_commands_list';
13+
14+
public function __construct(
15+
private readonly CommandManagerInterface $application,
16+
) {
17+
parent::__construct(
18+
name: self::NAME,
19+
inputSchema: GetCommandsListInput::class,
20+
description: 'Retrieves a list of available console commands with their descriptions.',
21+
);
22+
}
23+
24+
public function getLanguage(): ToolLanguage
25+
{
26+
return ToolLanguage::PHP;
27+
}
28+
29+
public function execute(object $input): string
30+
{
31+
$commands = $this->application->getCommands();
32+
$result = [];
33+
34+
foreach ($commands as $name => $command) {
35+
$result[] = [
36+
'name' => $name,
37+
'description' => $command->getDescription(),
38+
];
39+
}
40+
41+
return \json_encode($result);
42+
}
43+
}

0 commit comments

Comments
 (0)