----------------------
To use
PromptTemplate
to pass input as variables with
ReActAgent
, you need to follow these steps:
- Import the
PromptTemplate
from llama_index.core
.
from llama_index.core import PromptTemplate
- Define your prompt string. This string can contain placeholders for variables that you want to pass in later.
react_system_header_str = """\
You are designed to help with a variety of tasks, from answering questions
to providing summaries to other types of analyses.
- Create a
PromptTemplate
object using the string you defined.
react_system_prompt = PromptTemplate(react_system_header_str)
- Use the
get_prompts()
method of the ReActAgent
to get the current prompts.
- Update the prompts using the
update_prompts()
method of the ReActAgent
. Pass in a dictionary where the key is the name of the prompt you want to update and the value is the PromptTemplate
object you created.
agent.update_prompts({"agent_worker:system_prompt": react_system_prompt})
Here is the complete code:
from llama_index.core import PromptTemplate
react_system_header_str = """\
You are designed to help with a variety of tasks, from answering questions
to providing summaries to other types of analyses.
react_system_prompt = PromptTemplate(react_system_header_str)
agent.get_prompts()
agent.update_prompts({"agent_worker:system_prompt": react_system_prompt})
Please note that the placeholders in your prompt string should match the keys in the dictionary you pass to
update_prompts()
.