Skip to content

agent_fast_reply

Shorten the pipeline and return an answer right after the agent execution.

This hook allows for a custom response after memory recall, skipping default agent execution. It's useful for custom agent logic or when you want to use recalled memories, but you want to avoid the main agent.

Info

To skip the agent execution, you should populate fast_reply with an output key storing the reply.

P.S.: this is the perfect place to instantiate and execute your own custom agent!

📄 Arguments

Name Type Description
fast_reply dict An initially empty dict that can be populated with a response.
cat StrayCat Cheshire Cat instance, allows you to use the framework components.

â†Šī¸ Return

Type: None | dict | AgentOutput

If you want to bypass the main agent, return an AgentOutput or a dict with an output key. Return None to continue with normal execution.

✍ Example

The cat has no memory (no uploaded document) about a specific topic:

from cat.mad_hatter.decorators import hook

@hook  # default priority = 1
def agent_fast_reply(fast_reply, cat):
    # answer with predefined sentences if the Cat
    # has no knowledge in the declarative memory
    # (increasing the threshold memory is advisable)
    if len(cat.working_memory.declarative_memories) == 0:
        fast_reply["output"] = "Sorry, I have no memories about that."

    return fast_reply