Python: ADR: Support for chat history and scratchpads in YAML prompts #5437
Labels
python
Pull requests for the Python Semantic Kernel
sk team issue
A tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)
stale
Issue is stale because it has been open for 90 days with no activity
Note
The following code samples below are for communication purposes only. As part of the ADR, the correct names, syntax, and more should be defined.
In LangChain, there is a concept of placeholders for chat history and agent scratchpads within prompts. This issue is to capture the work necessary to provide similar functionality.
Chat History placeholder
With the chat history placeholder, prompt engineers to easily inject chat history into a prompt without needing to iterate through the chat history and generating it themselves while also being able to decorate the beginning and end with system messages. For example...
This placeholder can also be used for examples that are expressed within a
ChatHistory
object.In the YAML prompt the variables should be expressed as inputs with type
ChatHistory
Agent scratchpad placeholder
In addition to providing read only context within a prompt, there also needs to be a placeholder for any tool calls / results that are
automatically added to the chat history during automatic function calling. In LangChain, these are expressed as the agent's scratchpad. In LangChain, the developer needs to manually wire up the message placeholder with the scratchpad of the agent using LCEL, but in Semantic Kernel, we have an opportunity to simplify this.
The scratchpad should then be made available as an output variable and/or metadata of the semantic function.
Note
I'm not the biggest fan of this (multiple outputs seems challenging to handle), so I'm open for additional proposals on how to handle the scratchpad.
Once the developer has the output, they can then append it to the chat history object (if they want).
Filtering placeholders
Because the placeholders take in a
ChatHistory
object, prompt engineers should be able to manipulate it withKernelFunction
s. For example, there may be a simple filter that takes the top N messages...The text was updated successfully, but these errors were encountered: