history[] = $message; } public function getMessages(): array { return $this->history; } public function setHistory(array $history): void { $this->history = $history; } public function clearHistory(): void { $this->history = []; } public function getForApi(): array { $history = []; foreach ($this->history as $h) { $a = [ 'role' => $h->role->value, 'content' => $h->content, ]; if (isset($h->tool_calls)) { $a['tool_calls'] = $h->tool_calls; } $history[] = $a; } return $history; } }