u/AreaRight6029

▲ 3 r/Odoo

Hey everyone,

I’ve been working on integrating LLMs deeply into Odoo (not just a text chatbot, but an agent that can navigate the UI and execute logic). I quickly ran into a massive wall: LLM reasoning loops take 15-30+ seconds, which constantly triggered Odoo's limit-time-real and completely froze the WSGI server.

I wanted to share the asynchronous architecture I built to bypass this and get your thoughts on it.

Here is how I structured it to avoid destroying Odoo's performance:

  • Decoupling the AI: I moved the entire LLM orchestrator (Pydantic AI) to an external FastAPI microservice. Odoo now acts simply as a "Headless ERP" and UI provider.
  • The "Hybrid Wait" Pattern: Instead of holding the HTTP connection, Odoo launches a background thread for the AI request and waits a maximum of 10 seconds. If the AI takes longer, Odoo frees up the main thread and the OWL frontend switches to polling (every 3 seconds).
  • Asynchronous UI Navigation: Since the AI is external, if it decides to "open a view" for the user, it sends a payload to an Odoo webhook. Odoo saves this dictionary (like ir.actions.act_window) in a pending_action database field. The OWL frontend detects it via polling and executes it without freezing.
  • Strict ACL Enforcement: Security was a nightmare. To avoid giving the AI "god mode", the FastAPI orchestrator sends the odoo_user_id to the webhook. Odoo then executes sudo().with_user(target_user_id) before running any tool. If the user lacks permissions, the native tool fails safely.
  • Taming LLM Hallucinations: LLMs kept inventing positional arguments for Odoo models. I had to rewrite the AI-facing methods in Odoo to rely heavily on kwargs to tolerate these hallucinations without throwing Python TypeError exceptions.

This approach allowed me to integrate pgvector and handle complex reasoning without Odoo even breaking a sweat.

OdooLM

https://preview.redd.it/3a6wzwgj71zg1.png?width=1919&format=png&auto=webp&s=8e95a8202a4b77bc4e29b1c3a8d697fc23dfedf4

reddit.com
u/AreaRight6029 — 18 days ago