From c21dfc8f6cacd43aa89b53f927b68ad05b9aec66 Mon Sep 17 00:00:00 2001 From: Pavel Buchnev Date: Sun, 15 Sep 2024 22:42:45 +0400 Subject: [PATCH] Adds MetadataAwareInterface interface --- src/Agent/AgentAggregate.php | 32 ++++++++++++++++++---------- src/Agent/MetadataAwareInterface.php | 14 ++++++++++++ src/Solution/Solution.php | 10 ++++++--- 3 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 src/Agent/MetadataAwareInterface.php diff --git a/src/Agent/AgentAggregate.php b/src/Agent/AgentAggregate.php index 6c4655d..9a9240e 100644 --- a/src/Agent/AgentAggregate.php +++ b/src/Agent/AgentAggregate.php @@ -22,11 +22,10 @@ class AgentAggregate implements AgentInterface, HasLinkedAgentsInterface, HasLinkedToolsInterface, - HasLinkedContextSourcesInterface + HasLinkedContextSourcesInterface, + MetadataAwareInterface { - /** - * @var array - */ + /** @var array */ private array $associations = []; public function __construct( @@ -92,7 +91,7 @@ public function getMemory(): array { return \array_values( \array_filter( - $this->agent->getMetadata(), + $this->getMetadata(), static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Memory, ), ); @@ -102,7 +101,7 @@ public function getPrompts(): array { return \array_values( \array_filter( - $this->agent->getMetadata(), + $this->getMetadata(), static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Prompt, ), ); @@ -115,7 +114,7 @@ public function getConfiguration(): array { return \array_values( \array_filter( - $this->agent->getMetadata(), + $this->getMetadata(), static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Configuration, ), ); @@ -128,11 +127,9 @@ public function addAssociation(Solution $association): void $this->associations[] = $association; } - public function addMetadata(SolutionMetadata ...$metadatum): void + public function addMetadata(SolutionMetadata ...$metadata): void { - foreach ($metadatum as $metadata) { - $this->agent->addMetadata($metadata); - } + $this->agent->addMetadata(...$metadata); } private function validateDependency(Solution $association): void @@ -145,4 +142,17 @@ private function validateDependency(Solution $association): void } } } + + public function getMetadata(): array + { + $metadata = $this->agent->getMetadata(); + + foreach ($this->associations as $association) { + if ($association instanceof MetadataAwareInterface) { + $metadata = \array_merge($metadata, $association->getMetadata()); + } + } + + return $metadata; + } } diff --git a/src/Agent/MetadataAwareInterface.php b/src/Agent/MetadataAwareInterface.php new file mode 100644 index 0000000..f466b61 --- /dev/null +++ b/src/Agent/MetadataAwareInterface.php @@ -0,0 +1,14 @@ + @@ -17,9 +19,11 @@ public function __construct( public readonly ?string $description = null, ) {} - public function addMetadata(SolutionMetadata $metadata): void + public function addMetadata(SolutionMetadata ...$metadata): void { - $this->metadata[] = $metadata; + foreach ($metadata as $meta) { + $this->metadata[] = $meta; + } } public function getMetadata(): array