diff --git a/Mcp/Tools/Agent/Brain/BrainForget.php b/Mcp/Tools/Agent/Brain/BrainForget.php index 45fb97d..8cb1d7e 100644 --- a/Mcp/Tools/Agent/Brain/BrainForget.php +++ b/Mcp/Tools/Agent/Brain/BrainForget.php @@ -73,19 +73,18 @@ class BrainForget extends AgentTool } $reason = $this->optionalString($args, 'reason', null, 500); - - // Verify memory exists and belongs to this workspace - $memory = BrainMemory::where('id', $id) - ->where('workspace_id', $workspaceId) - ->first(); - - if (! $memory) { - return $this->error("Memory '{$id}' not found in this workspace"); - } - $agentId = $context['agent_id'] ?? $context['session_id'] ?? 'anonymous'; - return $this->withCircuitBreaker('brain', function () use ($id, $memory, $reason, $agentId) { + return $this->withCircuitBreaker('brain', function () use ($id, $workspaceId, $reason, $agentId) { + // Verify memory exists and belongs to this workspace + $memory = BrainMemory::where('id', $id) + ->where('workspace_id', $workspaceId) + ->first(); + + if (! $memory) { + return $this->error("Memory '{$id}' not found in this workspace"); + } + Log::info('OpenBrain: memory forgotten', [ 'id' => $id, 'type' => $memory->type, diff --git a/Migrations/0001_01_01_000008_create_brain_memories_table.php b/Migrations/0001_01_01_000008_create_brain_memories_table.php index 5cb976f..d134840 100644 --- a/Migrations/0001_01_01_000008_create_brain_memories_table.php +++ b/Migrations/0001_01_01_000008_create_brain_memories_table.php @@ -27,7 +27,7 @@ return new class extends Migration $table->text('content'); $table->json('tags')->nullable(); $table->string('project', 128)->nullable()->index(); - $table->float('confidence')->default(1.0); + $table->float('confidence')->default(0.8); $table->uuid('supersedes_id')->nullable(); $table->timestamp('expires_at')->nullable(); $table->timestamps(); diff --git a/Services/BrainService.php b/Services/BrainService.php index 0340a01..da27181 100644 --- a/Services/BrainService.php +++ b/Services/BrainService.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Core\Mod\Agentic\Services; use Core\Mod\Agentic\Models\BrainMemory; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -63,12 +64,14 @@ class BrainService ]); $payload['vector'] = $vector; - $this->qdrantUpsert([$payload]); + DB::transaction(function () use ($payload, $memory) { + $this->qdrantUpsert([$payload]); - if ($memory->supersedes_id) { - $this->qdrantDelete([$memory->supersedes_id]); - BrainMemory::where('id', $memory->supersedes_id)->delete(); - } + if ($memory->supersedes_id) { + BrainMemory::where('id', $memory->supersedes_id)->delete(); + $this->qdrantDelete([$memory->supersedes_id]); + } + }); } /** @@ -139,13 +142,18 @@ class BrainService ->get("{$this->qdrantUrl}/collections/{$this->collection}"); if ($response->status() === 404) { - Http::timeout(10) + $createResponse = Http::timeout(10) ->put("{$this->qdrantUrl}/collections/{$this->collection}", [ 'vectors' => [ 'size' => self::VECTOR_DIMENSION, 'distance' => 'Cosine', ], ]); + + if (! $createResponse->successful()) { + throw new \RuntimeException("Qdrant collection creation failed: {$createResponse->status()}"); + } + Log::info("OpenBrain: created Qdrant collection '{$this->collection}'"); } }