Intermitend problem with PostgresTools

I’m using

from agno.tools.postgres import PostgresTools

and sometimes it works perfectly, and others it doesn’t, mainly when I try to INSERT new data.

I already tried with supabase, and now I’m triyng with local postgres. Simmiliar error.

I’m using to declare database:

postgres_tools = PostgresTools(
    host="localhost",
    port=5432,
    db_name="vistoria_db",
    user="postgres",
    password=os.getenv("POSTGRES_DB_PASSWORD")
)

and in the agent I’m using:

tools=[ler_imagem, postgres_tools],

Is Preformatted text readonly?
Sometimes I can INSERT data, and sometimes not. Very strange.

Anyone could help me?

Hey @maubaum
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

Hey @maubaum, I’m sorry this is not working at expected, let’s dive into it!
Any chance you can share the error logs or traces you see when the insert fails? Checking how you are setting and calling your Agent could also help.

Also, I’m understanding that the tool itself sometimes doesn’t work - or did you mean that the Agent sometimes doesn’t trigger the tool call when expected?

Hi Manu,

Thanks for your reply.

Clarifying your last question: The agent is calling the tool perfectly. The problem is that the agent answer that can’t write in the database.
It’s strange because some time the agent successfully insert data on it. That’s why I consider it an intermittent problem.

Below the way I call the agent:

response = agent.run(str(dados_json), user_id=clean_number(from_number), session_id=session_id)

I send the response to twilio to print it on user’s whatsapp.

Below the most frequent error that I received from the tool (que tool received it from the database because I checked the log in postgre): (error in Portuguese, sorry)
“não é possível executar INSERT em uma transação de leitura-apenas”

Please let me know if you need more info.

Thanks,
Mauricio

ps: I changed the tool from PostgresTools to SQLTools (and corresponding code) and worked flawlessly with the same database connection parameters. The only drawback is that it is not showing the SQL query in the terminal CLI anymore - even with show_tool_calls=True in the agent. (but this is topic for another post)

Mauricio.

Hey @maubaum

The error sounds like a transaction in read-only but we are trying to INSERT using the same transaction. It may be a problem with how the agent calls the tool or a bug with our PostgresTools. Sadly I am being unable to recreate it.

If you are still experiencing this, can you share how the agent is being called, or ideally the SQL statement that ends up raising this error?

I also hear you expect to see the run SQL statements when using SQLTools. I will make sure we adjust the code so it’s possible, makes total sense to me.

Thanks for using Agno!