Output Parser not Work in an Agent Chain
Labels: name: area: agent, name: auto:bug

### Issue you'd like to raise.

I created a tool in an agent to output some data. The data contains ADMET properties and other properties. Although I have made it very clear that all properties should be kept in the tool function as well as in the output parser, I still can not get the non-ADMET properties in the final output. Here is my code:

def Func_Tool_XYZ(parameters):
    print("\n", parameters)
    print("触发Func_Tool_ADMET插件")
    print("........正在解析ADMET属性..........")
    data = {
        "SMILES": "C1=CC=CC=C1C1=C(C2=CC=CC=C2)C=CC=C1",
        "humanIntestinalAbsorption": "HIA+|0.73",
        "caco2Permeability": "None",
        "caco2PermeabilityIi": "Caco2+|0.70",
        "savePath": "/profile/chemicalAppsResult/admetResult/2023/11/10/2567",
        "status": "1",
        "favoriteFlag": "0"
    }

    prompt = f"Properties: {data['SMILES']} {data['humanIntestinalAbsorption']} {data['caco2Permeability']} {data['caco2PermeabilityIi']} {data['savePath']} {data['status']} {data['favoriteFlag']}"

    return {
        'output': data,
        'prompt': prompt
    }

tools = [
    Tool(
        name="Tool XYZ",
        func=Func_Tool_XYZ,
        description="""
            useful when you want to obtain the XYZ data for a molecule.
            like: get the XYZ data for molecule X
            The input to this tool should be a string, representing the smiles_id.
        """
    )
]

class CustomOutputParser(JSONAgentOutputParser):
    def parse(self, llm_output: str):
        print('jdlfjdlfjdlfjsdlfdjld')
        print(llm_output)
        smiles = self.data["SMILES"]
        return f"SMILES: {smiles}, {llm_output}"

output_parser = CustomOutputParser()

llm = OpenAI(temperature=0, max_tokens=2048)
memory = ConversationBufferMemory(memory_key="chat_history", output_key='output')

memory.clear()

agent = initialize_agent(tools,
                         llm,
                         agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
                         verbose=True,
                         memory=memory,
                         return_intermediate_steps=True,
                         output_parser=output_parser
                         )

pdf_id = 1111
Human_prompt = f'provide a document. PDF ID is {pdf_id}. This information helps you to understand this document, but you should use tools to finish following tasks, rather than directly imagine from my description. If you understand, say \"Received\".'
AI_prompt = "Received.  "

memory.save_context({"input": Human_prompt}, {"output": AI_prompt})

answer = agent({"input": "Get the ADMET data for molecule X."})

print(answer["output"])

And here is my output messages:

> Entering new AgentExecutor chain...

Thought: Do I need to use a tool? Yes
Action: Tool XYZ
Action Input: molecule X
 molecule X
触发Func_Tool_ADMET插件
........正在解析ADMET属性..........

Observation: {'output': {'SMILES': 'C1=CC=CC=C1C1=C(C2=CC=CC=C2)C=CC=C1', 'humanIntestinalAbsorption': 'HIA+|0.73', 'caco2Permeability': 'None', 'caco2PermeabilityIi': 'Caco2+|0.70', 'savePath': '/profile/chemicalAppsResult/admetResult/2023/11/10/2567', 'status': '1', 'favoriteFlag': '0'}, 'prompt': 'Properties: C1=CC=CC=C1C1=C(C2=CC=CC=C2)C=CC=C1 HIA+|0.73 None Caco2+|0.70 /profile/chemicalAppsResult/admetResult/2023/11/10/2567 1 0'}
Thought: Do I need to use a tool? No
AI: The ADMET data for molecule X is as follows: Human Intestinal Absorption: HIA+|0.73, Caco2 Permeability: None, Caco2 Permeability II: Caco2+|0.70, Save Path: /profile/chemicalAppsResult/admetResult/2023/11/10/2567, Status: 1, Favorite Flag: 0.

> Finished chain.
The ADMET data for molecule X is as follows: Human Intestinal Absorption: HIA+|0.73, Caco2 Permeability: None, Caco2 Permeability II: Caco2+|0.70, Save Path: /profile/chemicalAppsResult/admetResult/2023/11/10/2567, Status: 1, Favorite Flag: 0.


It seems like the non-ADMET properties have been lost.
And, it may be causing by the output parser not working, becuase if it works fine, I should get something like "jdlfjdlfjdlfjsdlfdjld" which is stated in the output parser.

So how should I do next?

### Suggestion:

_No response_