Metadata-Version: 2.1
Name: odoo-addon-ai_tool
Version: 16.0.1.0.0.2
Summary: We want to generate some specific AI Tools that might be used in other places, like MCP or native.
Home-page: https://github.com/OCA/ai
Author: Dixmit,Odoo Community Association (OCA)
Author-email: support@odoo-community.org
License: AGPL-3
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 16.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Requires-Python: >=3.10
Requires-Dist: odoo<16.1dev,>=16.0a

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

=======
Ai Tool
=======

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:b0dec31c213cecc194ff875e340eb11844acb3ee0e5147864575a90b02f288bf
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
    :target: https://odoo-community.org/page/development-status
    :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fai-lightgray.png?logo=github
    :target: https://github.com/OCA/ai/tree/16.0/ai_tool
    :alt: OCA/ai
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
    :target: https://translation.odoo-community.org/projects/ai-16-0/ai-16-0-ai_tool
    :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
    :target: https://runboat.odoo-community.org/builds?repo=OCA/ai&target_branch=16.0
    :alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This technical module provides the base infrastructure for defining AI
tools in Odoo. It allows other modules to register callable functions as
AI tools, which can then be used by MCP servers, automation flows, or
any AI-native integration.

**Table of contents**

.. contents::
   :local:

Usage
=====

This module is technical, however, it adds some specific functions that
might be used in glue modules.

For example, if we want to add on sales a functionality to find the
sales on a period, we should do:

.. code:: xml

   <odoo>
       <record model="ai.tool" id="total_sale_order_tool">
           <field name="name">total_sale_order</field>
           <field
               name="description"
           >Calculate the total amount of sale orders within a date range and optionally for a specific customer.</field>
           <field name="model_id" ref="model_sale_order" />
           <field name="function_name">_mcp_total_sale_order</field>
       </record>
   </odoo>

.. code:: python

   from odoo.addons.ai_tool import aitool

   class SaleOrder(models.Model):
       _inherit = "sale.order"

       @aitool(
           input_schema={
               "start_date": {"type": "date"},
               "end_date": {"type": "date"},
               "customer_id": {"type": "integer"},
           },
           required_inputs=["start_date", "end_date"],
           output_schema={
               "amount_total": {"type": "number"},
           },
       )
       def _mcp_total_sale_order(self, start_date, end_date, customer_id=None):
           domain = [("date_order", ">=", start_date), ("date_order", "<=", end_date)]
           if customer_id:
               domain.append(("partner_id", "=", customer_id))
           orders = self.read_group(domain, ["amount_total"], [])
           return {
               "amount_total": (orders[0]["amount_total"] or 0) if orders else 0,
           }

Be aware that this kind of elements must allways return a dict. All the
elements will be defined in output_schema.

Also, for the signature of the functions, all fields must be in the
inputs with the exception of record. This argument is protected and is
used to define integrations with automation. This argument is required
in ``generic_model`` and ``record`` tools.

On ``generic_model``\ s we are expecting this value because we want to
do a specific action with the model.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/ai/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/ai/issues/new?body=module:%20ai_tool%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Dixmit

Contributors
------------

- `Dixmit <https://www.dixmit.com>`__

  - Enric Tobella

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/ai <https://github.com/OCA/ai/tree/16.0/ai_tool>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
