Skip to content

Commit c21dfc8

Browse files
committed
Adds MetadataAwareInterface interface
1 parent 5b9da48 commit c21dfc8

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

src/Agent/AgentAggregate.php

+21-11
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
class AgentAggregate implements AgentInterface,
2323
HasLinkedAgentsInterface,
2424
HasLinkedToolsInterface,
25-
HasLinkedContextSourcesInterface
25+
HasLinkedContextSourcesInterface,
26+
MetadataAwareInterface
2627
{
27-
/**
28-
* @var array<TAssociation>
29-
*/
28+
/** @var array<TAssociation> */
3029
private array $associations = [];
3130

3231
public function __construct(
@@ -92,7 +91,7 @@ public function getMemory(): array
9291
{
9392
return \array_values(
9493
\array_filter(
95-
$this->agent->getMetadata(),
94+
$this->getMetadata(),
9695
static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Memory,
9796
),
9897
);
@@ -102,7 +101,7 @@ public function getPrompts(): array
102101
{
103102
return \array_values(
104103
\array_filter(
105-
$this->agent->getMetadata(),
104+
$this->getMetadata(),
106105
static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Prompt,
107106
),
108107
);
@@ -115,7 +114,7 @@ public function getConfiguration(): array
115114
{
116115
return \array_values(
117116
\array_filter(
118-
$this->agent->getMetadata(),
117+
$this->getMetadata(),
119118
static fn(SolutionMetadata $metadata): bool => $metadata->type === MetadataType::Configuration,
120119
),
121120
);
@@ -128,11 +127,9 @@ public function addAssociation(Solution $association): void
128127
$this->associations[] = $association;
129128
}
130129

131-
public function addMetadata(SolutionMetadata ...$metadatum): void
130+
public function addMetadata(SolutionMetadata ...$metadata): void
132131
{
133-
foreach ($metadatum as $metadata) {
134-
$this->agent->addMetadata($metadata);
135-
}
132+
$this->agent->addMetadata(...$metadata);
136133
}
137134

138135
private function validateDependency(Solution $association): void
@@ -145,4 +142,17 @@ private function validateDependency(Solution $association): void
145142
}
146143
}
147144
}
145+
146+
public function getMetadata(): array
147+
{
148+
$metadata = $this->agent->getMetadata();
149+
150+
foreach ($this->associations as $association) {
151+
if ($association instanceof MetadataAwareInterface) {
152+
$metadata = \array_merge($metadata, $association->getMetadata());
153+
}
154+
}
155+
156+
return $metadata;
157+
}
148158
}

src/Agent/MetadataAwareInterface.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\Agent;
6+
7+
use LLM\Agents\Solution\SolutionMetadata;
8+
9+
interface MetadataAwareInterface
10+
{
11+
public function getMetadata(): array;
12+
13+
public function addMetadata(SolutionMetadata ...$metadata): void;
14+
}

src/Solution/Solution.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace LLM\Agents\Solution;
66

7-
abstract class Solution
7+
use LLM\Agents\Agent\MetadataAwareInterface;
8+
9+
abstract class Solution implements MetadataAwareInterface
810
{
911
/**
1012
* @var array<SolutionMetadata>
@@ -17,9 +19,11 @@ public function __construct(
1719
public readonly ?string $description = null,
1820
) {}
1921

20-
public function addMetadata(SolutionMetadata $metadata): void
22+
public function addMetadata(SolutionMetadata ...$metadata): void
2123
{
22-
$this->metadata[] = $metadata;
24+
foreach ($metadata as $meta) {
25+
$this->metadata[] = $meta;
26+
}
2327
}
2428

2529
public function getMetadata(): array

0 commit comments

Comments
 (0)