This repository has been archived on 2026-03-09. You can view files and clone it, but cannot push or open issues or pull requests.
php-agentic/Actions/Brain/ListKnowledge.php
Snider 8b8a9c26e5
Some checks failed
CI / PHP 8.3 (push) Failing after 2s
CI / PHP 8.4 (push) Failing after 2s
feat: extract Brain operations into CorePHP Actions + API routes
- Create 4 Actions in Actions/Brain/ (RememberKnowledge, RecallKnowledge,
  ForgetKnowledge, ListKnowledge) using the Action trait pattern
- Slim MCP tool handlers to thin wrappers calling Actions
- Add BrainController with REST endpoints (remember, recall, forget, list)
- Add API route file with api.auth + api.scope.enforce middleware
- Wire ApiRoutesRegistering in Boot.php
- Rename routes/ → Routes/ to match CorePHP convention
- Remove empty database/migrations/ (legacy Laravel boilerplate)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-04 12:15:13 +00:00

57 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Actions\Brain;
use Core\Actions\Action;
use Core\Mod\Agentic\Models\BrainMemory;
use Illuminate\Support\Collection;
/**
* List memories in the shared OpenBrain knowledge store.
*
* Pure MariaDB query using model scopes — no vector search.
* Use RecallKnowledge for semantic queries.
*
* Usage:
* $memories = ListKnowledge::run(1, ['type' => 'decision']);
*/
class ListKnowledge
{
use Action;
/**
* @param array{project?: string, type?: string, agent_id?: string, limit?: int} $filter
* @return array{memories: array, count: int}
*/
public function handle(int $workspaceId, array $filter = []): array
{
$limit = min(max((int) ($filter['limit'] ?? 20), 1), 100);
$query = BrainMemory::forWorkspace($workspaceId)
->active()
->latestVersions()
->forProject($filter['project'] ?? null)
->byAgent($filter['agent_id'] ?? null);
$type = $filter['type'] ?? null;
if ($type !== null) {
if (is_string($type) && ! in_array($type, BrainMemory::VALID_TYPES, true)) {
throw new \InvalidArgumentException(
sprintf('type must be one of: %s', implode(', ', BrainMemory::VALID_TYPES))
);
}
$query->ofType($type);
}
$memories = $query->orderByDesc('created_at')
->limit($limit)
->get();
return [
'memories' => $memories->map(fn (BrainMemory $m) => $m->toMcpContext())->all(),
'count' => $memories->count(),
];
}
}