Skip to content
docsv0.2.0

IntelligenceContext

Context object passed to Intelligence Providers. Carries all information needed to generate intelligent suggestions: - Tool name and arguments - Execution result (for post-execution providers) - Entity information (type, instance, ID) - Applied business rules

IntelligenceContext::__construct()

public function __construct(string $toolName, array $args = [], ?Milpa\ToolRuntime\ToolResult $result = null, ?string $entityType = null, ?object $entity = null, string|int|null $entityId = null, array $appliedRules = [], array $extra = []):

Parameters

Parameters of __construct()
NameTypeDescription
$toolNamestringName of the tool being executed
$argsarray<string, mixed>Arguments passed to the tool
$result(ToolResult | null)Execution result (null for pre-execution)
$entityType(string | null)Type of entity involved (Note, User, etc.)
$entity(object | null)The actual entity instance
$entityId(int | string | null)Entity identifier
$appliedRulesarray<array{rule: string, effect?: string}>Rules that were applied
$extraarray<string, mixed>Additional context data

IntelligenceContext::preExecution()

public static function preExecution(string $toolName, array $args = [], array $extra = []): self

Create context for pre-execution phase (before tool runs).

Parameters

Parameters of preExecution()
NameTypeDescription
$toolNamestring
$argsarray<string, mixed>
$extraarray<string, mixed>

IntelligenceContext::postExecution()

public static function postExecution(string $toolName, array $args, Milpa\ToolRuntime\ToolResult $result, ?string $entityType = null, ?object $entity = null, string|int|null $entityId = null, array $appliedRules = [], array $extra = []): self

Create context for post-execution phase (after tool runs).

Parameters

Parameters of postExecution()
NameTypeDescription
$toolNamestring
$argsarray<string, mixed>
$resultToolResult
$entityType(string | null)
$entity(object | null)
$entityId(int | string | null)
$appliedRulesarray<array{rule: string, effect?: string}>
$extraarray<string, mixed>

IntelligenceContext::withResult()

public function withResult(Milpa\ToolRuntime\ToolResult $result): self

Add execution result to create post-execution context.

Parameters

Parameters of withResult()
NameTypeDescription
$resultMilpa\ToolRuntime\ToolResult

IntelligenceContext::withEntity()

public function withEntity(string $type, ?object $entity, string|int|null $id = null): self

Add entity information.

Parameters

Parameters of withEntity()
NameTypeDescription
$typestring
$entity?object
$idstring|int|null

IntelligenceContext::withAppliedRules()

public function withAppliedRules(array $rules): self

Add applied business rules.

Parameters

Parameters of withAppliedRules()
NameTypeDescription
$rulesarray<array{rule: string, effect?: string}>

IntelligenceContext::withExtra()

public function withExtra(array $extra): self

Add extra context data.

Parameters

Parameters of withExtra()
NameTypeDescription
$extraarray<string, mixed>

IntelligenceContext::getToolName()

public function getToolName(): string

IntelligenceContext::getArgs()

public function getArgs(): array

IntelligenceContext::getArg()

public function getArg(string $key, ?mixed $default = null): ?mixed

Get a specific argument value.

Parameters

Parameters of getArg()
NameTypeDescription
$keystring
$default?mixed

IntelligenceContext::getResult()

public function getResult(): ?Milpa\ToolRuntime\ToolResult

IntelligenceContext::hasResult()

public function hasResult(): bool

Check whether an execution result has been attached (i.e. this is a post-execution context).

IntelligenceContext::isSuccessful()

public function isSuccessful(): bool

Check whether the attached execution result succeeded; false when no result is attached yet.

IntelligenceContext::getEntityType()

public function getEntityType(): ?string

IntelligenceContext::getEntity()

public function getEntity(): ?object

IntelligenceContext::getEntityId()

public function getEntityId(): string|int|null

IntelligenceContext::hasEntity()

public function hasEntity(): bool

Check whether entity information (an instance, or at least a type) has been attached.

IntelligenceContext::getAppliedRules()

public function getAppliedRules(): array

IntelligenceContext::getExtra()

public function getExtra(): array

IntelligenceContext::getExtraValue()

public function getExtraValue(string $key, ?mixed $default = null): ?mixed

Get a specific extra value.

Parameters

Parameters of getExtraValue()
NameTypeDescription
$keystring
$default?mixed

IntelligenceContext::isCreateOperation()

public function isCreateOperation(): bool

Check if this is a create operation.

IntelligenceContext::isUpdateOperation()

public function isUpdateOperation(): bool

Check if this is an update operation.

IntelligenceContext::isDeleteOperation()

public function isDeleteOperation(): bool

Check if this is a delete operation.

IntelligenceContext::isReadOperation()

public function isReadOperation(): bool

Check if this is a read/list operation.

IntelligenceContext::isMutation()

public function isMutation(): bool

Check if this is a mutation (create, update, delete).

IntelligenceContext::getOperationType()

public function getOperationType(): string

Get the operation type.

IntelligenceContext::inferEntityTypeFromTool()

public function inferEntityTypeFromTool(): ?string

Get the entity type from tool name (e.g., create_note -> Note).