Skip to content
docsv0.2.0

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

Parameters of __construct()
NameTypeDescription
$logger?Psr\Log\LoggerInterface

IntelligenceAggregator::registerProvider()

public function registerProvider(Milpa\ToolRuntime\Contracts\IntelligenceProviderInterface $provider): self

Register an intelligence provider.

Parameters

Parameters of registerProvider()
NameTypeDescription
$providerIntelligenceProviderInterfaceThe provider to register

Returns

For chaining

IntelligenceAggregator::registerProviders()

public function registerProviders(array $providers): self

Register multiple providers at once.

Parameters

Parameters of registerProviders()
NameTypeDescription
$providersarray<IntelligenceProviderInterface>

Returns

For chaining

IntelligenceAggregator::removeProvider()

public function removeProvider(string $name): bool

Remove a provider by name.

Parameters

Parameters of removeProvider()
NameTypeDescription
$namestringProvider name to remove

Returns

True if provider was found and removed

IntelligenceAggregator::hasProvider()

public function hasProvider(string $name): bool

Check if a provider is registered.

Parameters

Parameters of hasProvider()
NameTypeDescription
$namestringProvider name to check

IntelligenceAggregator::getProviderNames()

public function getProviderNames(): array

Get all registered provider names.

IntelligenceAggregator::gatherPre()

public function gatherPre(Milpa\ToolRuntime\Contracts\IntelligenceContext $context): Milpa\ToolRuntime\Contracts\ToolIntelligence

Gather pre-execution intelligence. Called before the tool executes. Returns warnings and would_block info.

Parameters

Parameters of gatherPre()
NameTypeDescription
$contextIntelligenceContextExecution context

Returns

Aggregated pre-execution intelligence

IntelligenceAggregator::gatherPost()

public function gatherPost(Milpa\ToolRuntime\Contracts\IntelligenceContext $context): Milpa\ToolRuntime\Contracts\ToolIntelligence

Gather post-execution intelligence. Called after the tool executes. Returns suggestions, next_actions, context.

Parameters

Parameters of gatherPost()
NameTypeDescription
$contextIntelligenceContextExecution context (with result)

Returns

Aggregated post-execution intelligence

IntelligenceAggregator::gather()

public function gather(Milpa\ToolRuntime\Contracts\IntelligenceContext $context, string $phase = 'both'): Milpa\ToolRuntime\Contracts\ToolIntelligence

Gather intelligence from all applicable providers.

Parameters

Parameters of gather()
NameTypeDescription
$contextIntelligenceContextExecution context
$phasestring"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\ToolIntelligence

Gather all intelligence (pre + post merged). Convenience method that gathers both phases.

Parameters

Parameters of gatherAll()
NameTypeDescription
$preContextIntelligenceContextPre-execution context
$postContextIntelligenceContextPost-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\IntelligentToolResult

Build an intelligent result from a ToolResult.

Parameters

Parameters of buildIntelligentResult()
NameTypeDescription
$resultToolResultOriginal result
$contextIntelligenceContextExecution context
$actionstringTool/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): string

Generate a human-readable attempt description.

Parameters

Parameters of generateAttemptDescription()
NameTypeDescription
$actionstringTool/action name
$argsarray<string, mixed>Arguments

Returns

Human-readable description

IntelligenceAggregator::getProviderCount()

public function getProviderCount(): int

Get count of registered providers.

IntelligenceAggregator::clearProviders()

public function clearProviders(): void

Clear all registered providers.