3.1.7
Access the messages list for the current session
Before this release, when the agent runs you are only able to get the last message generated by the model to answer your prompt. But internally the agent can performs many tool call iterations before coming up with the final answer.
Now the agent state stores the list of all messages between the agent and the provider for the current session, rather than only the final answer. So you can access the list of messages with the getSteps() method on the agent state:
$state = MyAgent::make()
->chat(new UserMessage("Who are you?"))
->run();
// Access the list of steps during the execution
foreach($state->getSteps() as $message) {
echo "- ".$message::class."\n";
}
// The final answer
echo $state->getMessage()->getContent();