LarAgent v0.4 to v0.5 upgrade guide

The latest upgrade includes several breaking changes, so we have decided to write an upgrade guide to ensure a seamless experience for you. Below you will find what to check and how to change it to make compatible.
Usage keys
Usage object stored in the message metadata and therefore sometimes stored in chat histories (if $storeMeta
is set to true) has changed the case of keys from camelCase to snake_case to make it compatible with the OpenAI API returned usage object.
For example, promptTokens
becomes prompt_tokens
, completionTokens
-> completion_tokens
, totalTokens
-> total_tokens
and etc.
This array is returned by $message->toArrayWithMeta(),
so please check if you use this method or access keys mentioned above, update them to the new array:

Model name in the chat session ID
Before v0.5, the chat session ID was constructed as "AgentName_ModelName_ChatKey" (Instead of ChatKey, there is UserID if forUser
method is used) by default.
As we found out from LarAgent developers that there is a need to change models without updating the chat history, we decided to disable adding ModelName by default in chat history names (ChatSessionId), instead the agent will add this info automatically in message's metadata before sending it to LLM.
Important:
To keep your agents chat histories stored before v0.5 accessible, add the protected $includeModelInChatSessionId = true;
to your Agent classes, which will ensure the behaviour stays the same (ModelName will be used as it was) for certain agents, and they will be able to still continue conversations from their stored chat histories.
Check the documentation here
Conclusion
We are sorry to introduce the breaking changes. We hope this guide will help you feel confident about upgrading the LarAgent version.
We are excited to get your feedback about the new features ❤️
And as always, happy coding! 🚀