Find answers from the community

Updated 3 months ago

i keep having an issue with the

i keep having an issue with the reactiveagent suddenly...it just keeps saying : An error occurred: 'doc_agent' to any possible query in the prompt, its triggered only after agent.chat is called, but i am providing the tools correctly:
Plain Text
query_engine_tools_step = [
    QueryEngineTool(
        query_engine=myqueryengine.as_query_engine(similarity_top_k=5),
        metadata=ToolMetadata(
            name="doc_agent",
            description="Useful for getting documentation."),
    )
]
agent = ReActAgent.from_tools(query_engine_tools_step, llm=llm, verbose=True, context_window=2000, max_iterations=100)
react_system_prompt = PromptTemplate(react_system_header_str)
agent.update_prompts({"agent_worker:system_prompt": react_system_prompt})

and in my prompt i reference the tool:

Plain Text
react_system_header_str = """ ## Tools
        You are responsible for using the tools in any sequence you deem appropriate to complete the task at hand.
        You have access to the following tools, all of which takes a simple string query as an argument: 
  
        {doc_agent}
 """ 


i removed some of the react_system_header_str since its quite long
L
R
10 comments
do you have the full traceback? Or any other info?
will see what information i can get, i was using streamlit so immediately all i see is the error i posted
Plain Text
llama_index/core/instrumentation/dispatcher.py", line 274, in wrapper
    result = func(*args, **kwargs)

llama_index/core/agent/react/formatter.py", line 74, in format
    fmt_sys_header = self.system_header.format(**format_args)
   
llama_index/core/agent/react/step.py", line 532, in _run_step
    input_chat = self._react_chat_formatter.format(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'doc_agent'
the debugger hits here in the llama_index code:

Plain Text
    def format(
        self,
        tools: Sequence[BaseTool],
        chat_history: List[ChatMessage],
        current_reasoning: Optional[List[BaseReasoningStep]] = None,
    ) -> List[ChatMessage]:
        """Format chat history into list of ChatMessage."""
        current_reasoning = current_reasoning or []

        format_args = {
            "tool_desc": "\n".join(get_react_tool_descriptions(tools)),
            "tool_names": ", ".join([tool.metadata.get_name() for tool in tools]),
        }
        if self.context:
            format_args["context"] = self.context

        fmt_sys_header = self.system_header.format(**format_args)
in fromatter.py so seems its missing the values it wants to format
oh yea, the template you are trying to insert should not have doc_agent string variable
not sure i understood, here : https://docs.llamaindex.ai/en/stable/examples/agent/react_agent/ it shows the custom template having a variable inside for tools
oh wait, you mean {tool_desc} is just the default place-holder and llamaindex replaces automatically with programmatic ones?
Its a string variable, used for python string formatting

i.e. prompt.format(tool_desc=tool_desc, ...) gets called under the hood
ah great yes youre correct, just replaced it with original and its all working, thanks for the help!
Add a reply
Sign up and join the conversation on Discord