You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a plugin developer wants to use the hook before_agent_starts for tasks like modifying the chat history, acting on agent_input.chat_history has no effect.
This code isn't working:
@hookdefbefore_agent_starts(agent_input, cat):
# When the LLM reads the chat history, it will lie generating the string "Generated in x seconds"# this is not an intended behavour, so we delete each occurrence of that stringagent_input['chat_history'] ="\n".join([lineforlineinagent_input["chat_history"].splitlines() if'✨ _Generated'notinline])
returnagent_input
Instead, acting on cat.working_memory.history is the right way to modify the conversation history. The following code is working properly
@hookdefbefore_agent_starts(agent_input, cat):
# When the LLM reads the chat history, it will lie generating the string "Generated in x seconds"# this is not an intended behavour, so we delete each occurrence of that stringiflen(cat.working_memory.history) >=2:
cat.working_memory.history[-2]['message'] ="\n".join([lineforlineincat.working_memory.history[-2]['message'].splitlines() if'✨ _Generated'notinline])
returnagent_input
The text was updated successfully, but these errors were encountered:
pieroit
changed the title
Modifying agent_input.chat_history in before_agent_starts hook has no effect
V2: get rid of agent_input and only rely on working memory
Oct 18, 2024
pieroit
changed the title
V2: get rid of agent_input and only rely on working memory
Get rid of agent_input and only rely on working memory
Oct 21, 2024
When a plugin developer wants to use the hook
before_agent_starts
for tasks like modifying the chat history, acting on agent_input.chat_history has no effect.This code isn't working:
Instead, acting on
cat.working_memory.history
is the right way to modify the conversation history. The following code is working properlyThe text was updated successfully, but these errors were encountered: