Property Lost in an Agent Chain
Labels: name: area: agent, name: auto:bug, name: auto:question

### Issue you'd like to raise.

I want to create an ADMET properties prediction tool in an agent. But the result is not so good. 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)
        return 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"])

I got the output like this:

> 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.


As you can see it, the property of "SMILES" has been lost, although I have made it clear that the properties in the tool should be kept as they are originally.

So what happend? How should I revise the code to make it work?


### Suggestion:

_No response_