Find answers from the community

s
F
Y
a
P
Updated last month

I am using ReACT agent and I am trying to set a variable mapping like this:agent = ReAct

I am using ReACT agent and I am trying to set a variable mapping like this:

agent = ReActAgent.from_tools(tools=[ask_followup_question_tool],llm=llm, verbose=True)
react_system_header_str = """

You have access to the following tools to ask a question:
{tool_desc}

You have access to the following attributes and values to guide your questions:
{unique_attributes}
"""
template_var_mappings = {str(unique_attributes): "unique_attributes"}
react_system_prompt = PromptTemplate(react_system_header_str, template_var_mappings=template_var_mappings)
agent.update_prompts({"agent_worker:system_prompt": react_system_prompt})
agent.reset()

response = agent.chat("bike")

--------
unique_attributes is string but I am getting this error when I use agent.chat: ---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/Users/hasnain/Desktop/workspace/Embedding Finetuning/Advisor_Debugger.ipynb Cell 70 line 1
----> 1 response = agent.chat("A blue bike")
KeyError: 'unique_attributes'
k
H
7 comments
Please stand by @HK as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
The error you're encountering is due to the fact that the unique_attributes key is not found in the context when you're trying to use agent.chat. This could be because the unique_attributes variable is not defined or not passed correctly.

In the code you provided, you're trying to create a PromptTemplate with a variable mapping for unique_attributes. However, it's not clear where unique_attributes is defined or what its value should be.

The PromptTemplate is used to format the system prompt for the ReAct agent. The template_var_mappings parameter is a dictionary that maps template variable names (as strings) to their corresponding values. In your case, you're mapping the string "unique_attributes" to the value of unique_attributes. If unique_attributes is not defined or not in the correct format, you'll get a KeyError when the template tries to format the prompt.

To fix this issue, you need to ensure that unique_attributes is defined and correctly passed to the PromptTemplate. Here's an example of how you might do this:

Plain Text
unique_attributes = "your unique attributes here"
template_var_mappings = {"unique_attributes": unique_attributes}
react_system_prompt = PromptTemplate(react_system_header_str, template_var_mappings=template_var_mappings)


In this example, unique_attributes is a string that contains your unique attributes. You then pass this string to the PromptTemplate through the template_var_mappings parameter.

Please note that the code snippets provided are based on the information available in the knowledge sources and may need to be adjusted based on your specific use case and the actual state of your code.
For more information, you can refer to the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
I am already doing this but it is giving me an error
@kapa.ai I am already doing this but it is giving me an error
Let me check the knowledge base for you. One moment! :books:
----------------------
I'm sorry to hear that you're still encountering issues. Based on the information provided in the knowledge sources, it's difficult to pinpoint the exact cause of the error. However, here are a few things you could check:

  1. Ensure that unique_attributes is defined before it's used in template_var_mappings. If it's not defined, or if it's defined after it's used, you'll get a KeyError.
  1. Check the type of unique_attributes. In your template_var_mappings, you're mapping the string "unique_attributes" to the value of unique_attributes. If unique_attributes is not a string, you might encounter issues.
  1. Make sure that unique_attributes is in the correct format. If it's a string, it should be properly formatted. If it's a list or another data structure, you might need to convert it to a string before using it in template_var_mappings.
  1. Check the rest of your code for errors. The KeyError might be caused by another part of your code, not just the template_var_mappings.
If you're still encountering issues, I would recommend referring to the LlamaIndex documentation () or reaching out to the LlamaIndex support team for further assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord