Wednesday, July 10, 2024

What is Agent scratchpad in python

This is driven by a LLMChain. The prompt in the LLMChain MUST include a variable called “agent_scratchpad” where the agent can put its intermediary work.

In the context of the LangChain framework, agent_scratchpad is a function that formats the intermediate steps of the agent's actions and observations into a string. This function is used to keep track of the agent's thoughts or actions during the execution of the program. Here is the code that supports this explanation:

The agent_scratchpad has two methods available:

_format_docs(docs): This method takes a list of documents as input and formats them into a string. Each document is wrapped in <item> and <page_content> tags, with an index attribute for the item tag.


format_agent_scratchpad(intermediate_steps): This method takes a list of intermediate steps as input. Each step is a tuple containing an action and an observation. The method concatenates the log of each action and the formatted observation into a string, which it then returns.

references:

https://github.com/langchain-ai/langchain/discussions/16311


No comments:

Post a Comment