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
| Name | Type | Description |
|---|---|---|
| $toolName | string | Name of the tool being executed |
| $args | array<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 |
| $appliedRules | array<array{rule: string, effect?: string}> | Rules that were applied |
| $extra | array<string, mixed> | Additional context data |
IntelligenceContext::preExecution()
public static function preExecution(string $toolName, array $args = [], array $extra = []): selfCreate context for pre-execution phase (before tool runs).
Parameters
| Name | Type | Description |
|---|---|---|
| $toolName | string | |
| $args | array<string, mixed> | |
| $extra | array<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 = []): selfCreate context for post-execution phase (after tool runs).
Parameters
| Name | Type | Description |
|---|---|---|
| $toolName | string | |
| $args | array<string, mixed> | |
| $result | ToolResult | |
| $entityType | (string | null) | |
| $entity | (object | null) | |
| $entityId | (int | string | null) | |
| $appliedRules | array<array{rule: string, effect?: string}> | |
| $extra | array<string, mixed> |
IntelligenceContext::withResult()
public function withResult(Milpa\ToolRuntime\ToolResult $result): selfAdd execution result to create post-execution context.
Parameters
| Name | Type | Description |
|---|---|---|
| $result | Milpa\ToolRuntime\ToolResult |
IntelligenceContext::withEntity()
public function withEntity(string $type, ?object $entity, string|int|null $id = null): selfAdd entity information.
Parameters
| Name | Type | Description |
|---|---|---|
| $type | string | |
| $entity | ?object | |
| $id | string|int|null |
IntelligenceContext::withAppliedRules()
public function withAppliedRules(array $rules): selfAdd applied business rules.
Parameters
| Name | Type | Description |
|---|---|---|
| $rules | array<array{rule: string, effect?: string}> |
IntelligenceContext::withExtra()
public function withExtra(array $extra): selfAdd extra context data.
Parameters
| Name | Type | Description |
|---|---|---|
| $extra | array<string, mixed> |
IntelligenceContext::getToolName()
public function getToolName(): stringIntelligenceContext::getArgs()
public function getArgs(): arrayIntelligenceContext::getArg()
public function getArg(string $key, ?mixed $default = null): ?mixedGet a specific argument value.
Parameters
| Name | Type | Description |
|---|---|---|
| $key | string | |
| $default | ?mixed |
IntelligenceContext::getResult()
public function getResult(): ?Milpa\ToolRuntime\ToolResultIntelligenceContext::hasResult()
public function hasResult(): boolCheck whether an execution result has been attached (i.e. this is a post-execution context).
IntelligenceContext::isSuccessful()
public function isSuccessful(): boolCheck whether the attached execution result succeeded; false when no result is attached yet.
IntelligenceContext::getEntityType()
public function getEntityType(): ?stringIntelligenceContext::getEntity()
public function getEntity(): ?objectIntelligenceContext::getEntityId()
public function getEntityId(): string|int|nullIntelligenceContext::hasEntity()
public function hasEntity(): boolCheck whether entity information (an instance, or at least a type) has been attached.
IntelligenceContext::getAppliedRules()
public function getAppliedRules(): arrayIntelligenceContext::getExtra()
public function getExtra(): arrayIntelligenceContext::getExtraValue()
public function getExtraValue(string $key, ?mixed $default = null): ?mixedGet a specific extra value.
Parameters
| Name | Type | Description |
|---|---|---|
| $key | string | |
| $default | ?mixed |
IntelligenceContext::isCreateOperation()
public function isCreateOperation(): boolCheck if this is a create operation.
IntelligenceContext::isUpdateOperation()
public function isUpdateOperation(): boolCheck if this is an update operation.
IntelligenceContext::isDeleteOperation()
public function isDeleteOperation(): boolCheck if this is a delete operation.
IntelligenceContext::isReadOperation()
public function isReadOperation(): boolCheck if this is a read/list operation.
IntelligenceContext::isMutation()
public function isMutation(): boolCheck if this is a mutation (create, update, delete).
IntelligenceContext::getOperationType()
public function getOperationType(): stringGet the operation type.
IntelligenceContext::inferEntityTypeFromTool()
public function inferEntityTypeFromTool(): ?stringGet the entity type from tool name (e.g., create_note -> Note).