Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of agent_input and only rely on working memory #917

Open
AlessandroSpallina opened this issue Sep 18, 2024 · 4 comments
Open

Get rid of agent_input and only rely on working memory #917

AlessandroSpallina opened this issue Sep 18, 2024 · 4 comments
Labels
mad hatter Related to the plugin system V2

Comments

@AlessandroSpallina
Copy link
Member

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:

@hook
def before_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 string
    
    agent_input['chat_history'] = "\n".join([line for line in agent_input["chat_history"].splitlines() if '✨ _Generated' not in line])
   
    return agent_input

Instead, acting on cat.working_memory.history is the right way to modify the conversation history. The following code is working properly

@hook
def before_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 string

    if len(cat.working_memory.history) >= 2:
        cat.working_memory.history[-2]['message'] = "\n".join([line for line in cat.working_memory.history[-2]['message'].splitlines() if '✨ _Generated' not in line])

    return agent_input
@pieroit
Copy link
Member

pieroit commented Sep 18, 2024

Nasty bug, I'll see to it thanks

@matteocacciola
Copy link

matteocacciola commented Oct 18, 2024

Maybe I am still missing something about how CheshireCat works, but here

@hook
def before_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 string
    
    agent_input['chat_history'] = "\n".join([line for line in agent_input["chat_history"].splitlines() if '✨ _Generated' not in line])
   
    return agent_input

I see that you are trying to modify the chat_history of the agent_input (variable of type AgentInput), whilst here

@hook
def before_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 string

    if len(cat.working_memory.history) >= 2:
        cat.working_memory.history[-2]['message'] = "\n".join([line for line in cat.working_memory.history[-2]['message'].splitlines() if '✨ _Generated' not in line])

    return agent_input

you are trying to modify the history of the working memory of the Stray, which is a different object. Am I missing something?

@alfredotoselli
Copy link

https://discord.com/channels/1092359754917089350/1092360210351398963/1288557418820800514

Probably this issue could be closed

@pieroit 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
Copy link
Member

pieroit commented Oct 18, 2024

Thanks @AlessandroSpallina @alfredotoselli @matteocacciola for checking this out

Please put and take stateful info from / to working memory

Changed the name of the issue so we remember when and why ;)

@pieroit pieroit added mad hatter Related to the plugin system V2 labels Oct 21, 2024
@pieroit 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mad hatter Related to the plugin system V2
Projects
None yet
Development

No branches or pull requests

4 participants