ai_agents_test-1.0.0-alpha1/src/Plugin/AgentsParameterTest/IssetTest.php
src/Plugin/AgentsParameterTest/IssetTest.php
<?php
declare(strict_types=1);
namespace Drupal\ai_agents_test\Plugin\AgentsParameterTest;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\ai\Service\FunctionCalling\ExecutableFunctionCallInterface;
use Drupal\ai_agents_test\AgentsParameterTestPluginBase;
use Drupal\ai_agents_test\Attribute\AgentsParameterTest;
/**
* Plugin implementation of the agents_parameter_test.
*/
#[AgentsParameterTest(
id: 'isset',
label: new TranslatableMarkup('Isset'),
description: new TranslatableMarkup('Is the value set.'),
)]
final class IssetTest extends AgentsParameterTestPluginBase {
/**
* {@inheritdoc}
*/
public function runTest(ExecutableFunctionCallInterface $tool, array $values, string $parameter_name, array $rule, string $tool_name): void {
$actual = $values[$parameter_name];
if ($actual === NULL || $actual === '') {
$error_message = sprintf('Parameter %s for tool %s was not set.', $parameter_name, $tool->getToolsId());
$this->errors[] = $error_message;
$this->details[] = $this->createDetailedResultRow(
result: FALSE,
object: "Tool: $tool_name, Parameter: $parameter_name",
type: 'Isset',
expected: 'To be set',
actual: '',
details: $error_message,
);
}
else {
$this->details[] = $this->createDetailedResultRow(
result: TRUE,
object: "Tool: $tool_name, Parameter: $parameter_name",
type: 'Isset',
expected: 'To be set',
actual: (string) $actual,
details: '',
);
}
}
}
