[Python] Autogen Agent is not extracting data from postgres db, only displays simulated results

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to extract data from a local postgres database using an llm API. The query is generated correctly and I am able to extract the query correctly using MS autogen agents. The problem is when it comes to execution. The executing agent does not execute the query. It only shows simulated results. I have included the execution query in the function map.

    Connection to the database is established, and table definitions are derived to form the prompt.

    This is the code executioner.

    senior_data_analyst = autogen.AssistantAgent(
    name="Senior Data Analyst",
    system_message=senior_data_analyst_prompt,
    llm_config=llm_config,
    code_execution_config=False, # Prevents arbitrary code execution, except code in the function map.
    human_input_mode="NEVER", # asks for a human input each time a message is received.
    is_termination_msg=is_termination_msg,
    function_map=function_map,
    )


    The Function map is as follows.

    function_map = {
    "run_sql": db.run_sql,
    }


    Here is the db.run_sql function.

    def run_sql(self, sql) -> str:
    print("In run_sql: NO ERRORS IN DB.")
    self.cur.execute(sql)
    columns = [desc[0] for desc in self.cur.description]
    res = self.cur.fetchall()
    list_of_dicts = [dict(zip(columns, row)) for row in res]
    json_result = json.dumps(list_of_dicts, indent=4, default=self.datetime_handler)
    return json_result


    I downloaded autogen using the command, about a week ago. Not sure if it is a version issue.

    pip install autogen-agentchat~=0.2


    I have tried changing my prompt but didn't get any results. Only thing that changes is the dummy output. I even tried a to print something in the run_sql funtion.

    But it seems that the problems is the db.run_sql() function is not called by the agent. Code runs normally, without errors. How can I make this agent to call the run_sql() and to pass the derived sql statement to it?

    Thank you in advance.

    Continue reading...

Compartilhe esta Página