Chat history stores conversations between users and agents, enabling context-aware interactions across multiple sessions.
$reinjectInstructionsPer
property defines when to reinject these instructions to ensure the agent stays on track. By default, it’s set to 0
(disabled).
false
(disabled). If you want to include model name in chat session id, set it to true
.
AgentName_ModelName_UserId
.
To keep old code compatible set it to true
in your agent classes.getMetadata()
method or store it in chat history automatically by setting storeMeta
property to true
in your agent class.
Check Storing usage data section for more information.
ChatHistoryInterface
.
addMessage(MessageInterface $message)
method adds a new message to the
chat history instance, which will be saved automatically by the agent class if
you are using it in agent context. In other case, you can save it manually
using writeToMemory()
method.ChatHistoryInterface
and extending the LarAgent\Core\Abstractions\ChatHistory
abstract class.
Check example implementations in src/History
There are two ways to register your custom chat history into an agent. If you use standard constructor only with $name
parameter, you can define it by class in $history
property or provider configuration:
Agent Class
$name
, you can override createChatHistory()
method:
store_meta
config or $storeMeta
property to true
:
toArrayWithMeta()
method to get array with metadata:
promptTokens
(camelCase) instead of prompt_tokens
(snake_case), so make sure to update your code if you were using it.afterResponse
hooks in your agent class: