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/ForgetKnowledge.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

62 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Actions\Brain;
use Core\Actions\Action;
use Core\Mod\Agentic\Models\BrainMemory;
use Core\Mod\Agentic\Services\BrainService;
use Illuminate\Support\Facades\Log;
/**
* Remove a memory from the shared OpenBrain knowledge store.
*
* Deletes from both MariaDB and Qdrant. Workspace-scoped.
*
* Usage:
* ForgetKnowledge::run('uuid-here', 1, 'virgil', 'outdated info');
*/
class ForgetKnowledge
{
use Action;
public function __construct(
private BrainService $brain,
) {}
/**
* @return array{forgotten: string, type: string}
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function handle(string $id, int $workspaceId, string $agentId = 'anonymous', ?string $reason = null): array
{
if ($id === '') {
throw new \InvalidArgumentException('id is required');
}
$memory = BrainMemory::where('id', $id)
->where('workspace_id', $workspaceId)
->first();
if (! $memory) {
throw new \InvalidArgumentException("Memory '{$id}' not found in this workspace");
}
Log::info('OpenBrain: memory forgotten', [
'id' => $id,
'type' => $memory->type,
'agent_id' => $agentId,
'reason' => $reason,
]);
$this->brain->forget($id);
return [
'forgotten' => $id,
'type' => $memory->type,
];
}
}