'object', 'properties' => [ 'query' => [ 'type' => 'string', 'description' => 'Natural language search query (max 2,000 characters)', 'maxLength' => 2000, ], 'top_k' => [ 'type' => 'integer', 'description' => 'Number of results to return (default: 5, max: 20)', 'minimum' => 1, 'maximum' => 20, 'default' => 5, ], 'filter' => [ 'type' => 'object', 'description' => 'Optional filters to narrow results', 'properties' => [ 'project' => [ 'type' => 'string', 'description' => 'Filter by project scope', ], 'type' => [ 'oneOf' => [ ['type' => 'string', 'enum' => BrainMemory::VALID_TYPES], [ 'type' => 'array', 'items' => ['type' => 'string', 'enum' => BrainMemory::VALID_TYPES], ], ], 'description' => 'Filter by memory type (single or array)', ], 'agent_id' => [ 'type' => 'string', 'description' => 'Filter by originating agent', ], 'min_confidence' => [ 'type' => 'number', 'description' => 'Minimum confidence threshold (0.0-1.0)', 'minimum' => 0.0, 'maximum' => 1.0, ], ], ], ], 'required' => ['query'], ]; } public function handle(array $args, array $context = []): array { $workspaceId = $context['workspace_id'] ?? null; if ($workspaceId === null) { return $this->error('workspace_id is required. Ensure you have authenticated with a valid API key. See: https://host.uk.com/ai'); } $query = $args['query'] ?? ''; $topK = $this->optionalInt($args, 'top_k', 5, 1, 20); $filter = $this->optional($args, 'filter', []); if (! is_array($filter)) { return $this->error('filter must be an object'); } return $this->withCircuitBreaker('brain', function () use ($query, $workspaceId, $filter, $topK) { $result = RecallKnowledge::run($query, (int) $workspaceId, $filter, $topK); return $this->success([ 'count' => $result['count'], 'memories' => $result['memories'], 'scores' => $result['scores'], ]); }, fn () => $this->error('Brain service temporarily unavailable. Recall failed.', 'service_unavailable')); } }