Skip to main content

We want to generate some specific AI Tools that might be used in other places, like MCP or native.

Project description

Odoo Community Association

Ai Tool

Beta License: AGPL-3 OCA/ai Translate me on Weblate Try me on Runboat

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

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:

<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>
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_models we are expecting this value because we want to do a specific action with the model.

Bug Tracker

Bugs are tracked on GitHub 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.

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

Credits

Authors

  • Dixmit

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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 project on GitHub.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odoo_addon_ai_tool-16.0.1.0.0.2-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file odoo_addon_ai_tool-16.0.1.0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_addon_ai_tool-16.0.1.0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45feb4da465fd494d07c3f515bf41ce3da05a7f722032512a7b4ca4dc3851bdf
MD5 acbcff02f72b3747688113716e4046ee
BLAKE2b-256 9ccc673d776d33ab79b039bf8102e3df34d86d5b8d89fe670c1c83623123a6e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page