cheshire-cat-ai / core

Production ready AI agent framework
https://cheshirecat.ai
GNU General Public License v3.0
2.14k stars 282 forks source link

[BUG] Hooks with same priority collide #830

Closed pieroit closed 1 month ago

pieroit commented 1 month ago

(to be verified)

When there are two hooks with same name and same priority, one gets overridden.

Probably a bug in MadHatter's hooks cache

jacopopalumbo01 commented 1 month ago

I've tried with two dummies plugin like follows:

PLUGIN 1:

from cat.mad_hatter.decorators import hook
from cat.log import log

@hook(priority=3)
def before_cat_sends_message(final_output, cat):
    # You can perform operations with the cat (modify working memory, access LLM, etc.)
    log.debug("TEST ONE")
    log.debug(final_output.content)

    final_output.content += "TESTONE"
    # You can return a new value that will be used instead of Cat calculated value
    return final_output

PLUGIN 2:

from cat.mad_hatter.decorators import hook
from cat.log import log

@hook(priority=3)
def before_cat_sends_message(final_output, cat):
    # You can perform operations with the cat (modify working memory, access LLM, etc.)
    log.debug("TEST TWO")
    log.debug(final_output.content)

    final_output.content += "TESTTWO"
    # You can return a new value that will be used instead of Cat calculated value
    return final_output

and it seems to work correctly. The agent responds always with a message of the type: "GENERATED_TEXTTESTONETESTTWO". Maybe the bug that they exposed during the last dev meeting is only related to some hooks.

Did they provide more infos about it?

pieroit commented 1 month ago

@jacopopalumbo01 same for me, could not manage to replicate the bug

@valentimarco do you have some hint?

valentimarco commented 1 month ago

The example of @jacopopalumbo01 is what i did with 2 plugins so idk...