50000) { throw new \InvalidArgumentException('content must not exceed 50,000 characters'); } $type = $data['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)) ); } $confidence = (float) ($data['confidence'] ?? 0.8); if ($confidence < 0.0 || $confidence > 1.0) { throw new \InvalidArgumentException('confidence must be between 0.0 and 1.0'); } $tags = $data['tags'] ?? null; if (is_array($tags)) { foreach ($tags as $tag) { if (! is_string($tag)) { throw new \InvalidArgumentException('Each tag must be a string'); } } } $supersedes = $data['supersedes'] ?? null; if ($supersedes !== null) { $existing = BrainMemory::where('id', $supersedes) ->where('workspace_id', $workspaceId) ->first(); if (! $existing) { throw new \InvalidArgumentException("Memory '{$supersedes}' not found in this workspace"); } } $expiresIn = isset($data['expires_in']) ? (int) $data['expires_in'] : null; if ($expiresIn !== null && $expiresIn < 1) { throw new \InvalidArgumentException('expires_in must be at least 1 hour'); } return $this->brain->remember([ 'workspace_id' => $workspaceId, 'agent_id' => $agentId, 'type' => $type, 'content' => $content, 'tags' => $tags, 'project' => $data['project'] ?? null, 'confidence' => $confidence, 'supersedes_id' => $supersedes, 'expires_at' => $expiresIn ? now()->addHours($expiresIn) : null, ]); } }