IntelligenceAggregator
Aggregates intelligence from multiple providers. Manages the lifecycle of Intelligence Providers: - Provider registration - Priority-based sorting - Pre/Post execution gathering - Result merging Usage: ```php $aggregator = new IntelligenceAggregator($logger); $aggregator->registerProvider($myIntelligenceProvider); // any IntelligenceProviderInterface // Pre-execution (before tool runs) $preIntelligence = $aggregator->gatherPre($context); // Post-execution (after tool runs) $postIntelligence = $aggregator->gatherPost($context); // Merge all intelligence $fullIntelligence = $preIntelligence->merge($postIntelligence); ```
IntelligenceAggregator::__construct()
public function __construct(?Psr\Log\LoggerInterface $logger = null):Parameters
| Name | Type | Description |
|---|---|---|
| $logger | ?Psr\Log\LoggerInterface |
IntelligenceAggregator::registerProvider()
public function registerProvider(Milpa\ToolRuntime\Contracts\IntelligenceProviderInterface $provider): selfRegister an intelligence provider.
Parameters
| Name | Type | Description |
|---|---|---|
| $provider | IntelligenceProviderInterface | The provider to register |
Returns
For chaining
IntelligenceAggregator::registerProviders()
public function registerProviders(array $providers): selfRegister multiple providers at once.
Parameters
| Name | Type | Description |
|---|---|---|
| $providers | array<IntelligenceProviderInterface> |
Returns
For chaining
IntelligenceAggregator::removeProvider()
public function removeProvider(string $name): boolRemove a provider by name.
Parameters
| Name | Type | Description |
|---|---|---|
| $name | string | Provider name to remove |
Returns
True if provider was found and removed
IntelligenceAggregator::hasProvider()
public function hasProvider(string $name): boolCheck if a provider is registered.
Parameters
| Name | Type | Description |
|---|---|---|
| $name | string | Provider name to check |
IntelligenceAggregator::getProviderNames()
public function getProviderNames(): arrayGet all registered provider names.
IntelligenceAggregator::gatherPre()
public function gatherPre(Milpa\ToolRuntime\Contracts\IntelligenceContext $context): Milpa\ToolRuntime\Contracts\ToolIntelligenceGather pre-execution intelligence. Called before the tool executes. Returns warnings and would_block info.
Parameters
| Name | Type | Description |
|---|---|---|
| $context | IntelligenceContext | Execution context |
Returns
Aggregated pre-execution intelligence
IntelligenceAggregator::gatherPost()
public function gatherPost(Milpa\ToolRuntime\Contracts\IntelligenceContext $context): Milpa\ToolRuntime\Contracts\ToolIntelligenceGather post-execution intelligence. Called after the tool executes. Returns suggestions, next_actions, context.
Parameters
| Name | Type | Description |
|---|---|---|
| $context | IntelligenceContext | Execution context (with result) |
Returns
Aggregated post-execution intelligence
IntelligenceAggregator::gather()
public function gather(Milpa\ToolRuntime\Contracts\IntelligenceContext $context, string $phase = 'both'): Milpa\ToolRuntime\Contracts\ToolIntelligenceGather intelligence from all applicable providers.
Parameters
| Name | Type | Description |
|---|---|---|
| $context | IntelligenceContext | Execution context |
| $phase | string | "pre", "post", or "both" |
Returns
Aggregated intelligence
IntelligenceAggregator::gatherAll()
public function gatherAll(Milpa\ToolRuntime\Contracts\IntelligenceContext $preContext, Milpa\ToolRuntime\Contracts\IntelligenceContext $postContext): Milpa\ToolRuntime\Contracts\ToolIntelligenceGather all intelligence (pre + post merged). Convenience method that gathers both phases.
Parameters
| Name | Type | Description |
|---|---|---|
| $preContext | IntelligenceContext | Pre-execution context |
| $postContext | IntelligenceContext | Post-execution context |
Returns
Complete aggregated intelligence
IntelligenceAggregator::buildIntelligentResult()
public function buildIntelligentResult(Milpa\ToolRuntime\ToolResult $result, Milpa\ToolRuntime\Contracts\IntelligenceContext $context, string $action, ?string $attempt = null): Milpa\ToolRuntime\IntelligentToolResultBuild an intelligent result from a ToolResult.
Parameters
| Name | Type | Description |
|---|---|---|
| $result | ToolResult | Original result |
| $context | IntelligenceContext | Execution context |
| $action | string | Tool/action name |
| $attempt | (string | null) | Human-readable attempt description (auto-generated if null) |
Returns
Result with intelligence
IntelligenceAggregator::generateAttemptDescription()
public function generateAttemptDescription(string $action, array $args): stringGenerate a human-readable attempt description.
Parameters
| Name | Type | Description |
|---|---|---|
| $action | string | Tool/action name |
| $args | array<string, mixed> | Arguments |
Returns
Human-readable description
IntelligenceAggregator::getProviderCount()
public function getProviderCount(): intGet count of registered providers.
IntelligenceAggregator::clearProviders()
public function clearProviders(): voidClear all registered providers.