import json


def print_agent_response(messages: list):
    id_to_expression = dict()
    for i, msg in enumerate(messages):
        print(f"{i + 1} - {str(msg.type).upper()}")
        for tool_call in msg.additional_kwargs.get('tool_calls', []):
            expression = json.loads(tool_call["function"]["arguments"])["expression"]
            print(f'Calling {tool_call["function"]["name"]} with the following query: {expression}')
            id_to_expression[tool_call['id']] = expression

        if str(msg.type) == "tool":
            print(f"Results for expression: {id_to_expression[msg.tool_call_id]}")

        print(msg.content)
        print("\n\n------------------------------------------\n\n")

    print("done")
