Skip to content

[16.0][ADD] ai_tool_read: generic read tools with per-field AI opt-out - #122

Merged
OCA-git-bot merged 4 commits into
OCA:16.0from
qrtl:16.0-add-ai_tool_read
Oct 21, 2026
Merged

OCA-git-bot merged 4 commits into
OCA:16.0from
qrtl:16.0-add-ai_tool_read

Conversation

@nobuQuartile

@nobuQuartile nobuQuartile commented Oct 6, 2026 •

Copy link
Copy Markdown

This module adds generic ai_tool tools that let an AI agent read any model and field it is allowed to access, while keeping personal or otherwise sensitive fields out of the results.

Three tools are provided:

  • list_models: lists the models the current user is allowed to read.
  • get_fields: describes a model's readable fields (label, type, help, selection options and relation target), and reports the fields forbidden to AI under hidden.
  • search_read: searches and reads records of a model, excluding forbidden and binary fields.

The tools run with the calling user's own access rights (no sudo on the data), so ACLs, record rules and field groups still apply.

A per-field flag AI Read Forbidden (ai_no_read) is added to ir.model.fields. A flagged field is never returned nor described, and neither are the fields exposing its value through their definition (related fields, fields delegated through _inherits, and computed fields depending on it). The flag can be set on base fields as well as custom ones. It keeps values out of the results, not out of the searches an agent runs: filtering or sorting on a forbidden field is not prevented (see Known issues in the README).

Assisted-by: Claude Opus 5.5

@qrtl
QT6693

@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch from 61c1536 to d765eb0 Compare October 6, 2026 03:33
@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch 2 times, most recently from 6819645 to 965ee23 Compare October 6, 2026 04:39
nobuQuartile added a commit to qrtl/axls-oca that referenced this pull request Oct 6, 2026
Lets an AI agent read any model and field the calling user can access,
with a per-field "AI Read Forbidden" flag to keep personal or sensitive
fields out of reach. Copied verbatim from OCA/ai#122, which is still open,
so the source is the PR head rather than a branch: re-sync from the 16.0
branch once the PR merges.

Vendored from OCA/ai@965ee23 (refs/pull/122/head)

Assisted-by: Claude Opus 5.5
@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch from ebcf9cf to 8d315d7 Compare October 6, 2026 05:00
nobuQuartile added a commit to qrtl/axls-oca that referenced this pull request Oct 6, 2026
Lets an AI agent read any model and field the calling user can access,
with a per-field "AI Read Forbidden" flag to keep personal or sensitive
fields out of reach. Copied verbatim from OCA/ai#122, which is still open,
so the source is the PR head rather than a branch: re-sync from the 16.0
branch once the PR merges.

Vendored from OCA/ai@8d315d7 (refs/pull/122/head)

Assisted-by: Claude Opus 5.5
@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch from 8d315d7 to 0b05d55 Compare October 6, 2026 08:04
nobuQuartile added a commit to qrtl/axls-oca that referenced this pull request Oct 6, 2026
Lets an AI agent read any model and field the calling user can access,
with a per-field "AI Read Forbidden" flag to keep personal or sensitive
fields out of reach. Copied verbatim from OCA/ai#122, which is still open,
so the source is the PR head rather than a branch: re-sync from the 16.0
branch once the PR merges.

Vendored from OCA/ai@0b05d55 (refs/pull/122/head)

Assisted-by: Claude Opus 5.5
@nobuQuartile
nobuQuartile marked this pull request as ready for review October 6, 2026 10:11
ai_tool lets modules expose tools to AI agents, but each one has to be
written for a specific model. This module adds three generic tools,
list_models, get_fields and search_read, so that an agent can read any
model the calling user is allowed to read, with the user's own access
rights (ACLs, record rules and field groups still apply).

Personal or otherwise sensitive data can be kept out of the results with
a new "AI Read Forbidden" flag on ir.model.fields. A flagged field is
never returned nor described, and neither is any field exposing its
value: related fields, _inherits included, and computed fields depending
on it, as the registry reports them. Many2one values are returned as
plain IDs, and display names computed on the fly are left out, as both
come from name_get, which may show another record's forbidden field.

Searches are not restricted, so an agent probing on purpose can still
find records by a forbidden value; the README lists those cases.

search_read returns the stored fields unless a field list is given, pages
its results with limit, offset and has_more, and does not fail as a whole
because of one field or record the user may not read.

Assisted-by: Claude Opus 5.5
@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch from 0b05d55 to 1e4cac3 Compare October 6, 2026 10:12
dreispt added a commit to dreispt/ai that referenced this pull request Oct 7, 2026
Port ai_tool_read from OCA#122 to 19.0.

- Manifest version bump.
- user_has_groups() removed: use res.users.has_groups().
- check_access_rights() deprecated since 18.0: use has_access() /
  check_access().
- View xpath targets use <list> instead of <tree>.
- display_name is never stored in 19.0, so it is excluded everywhere;
  adjust test_display_name_hidden.
- Replace setup/ symlink dir with the whool pyproject.toml convention.

Requires the ai_tool fixes from OCA#125, cherry-picked in the
preceding commits (ir.model is not readable by internal users in 19.0).

Assisted-by: Devin:SWE-2 High

@dreispt dreispt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
A few minor improvements were implement in f7da4c3 (#127) and could be cherry picked here.

dreispt added a commit to dreispt/ai that referenced this pull request Oct 7, 2026
Port ai_tool_read from OCA#122 to 19.0.

- Manifest version bump.
- user_has_groups() removed: use res.users.has_groups().
- check_access_rights() deprecated since 18.0: use has_access() /
  check_access().
- View xpath targets use <list> instead of <tree>.
- display_name is never stored in 19.0, so it is excluded everywhere;
  adjust test_display_name_hidden.
- Replace setup/ symlink dir with the whool pyproject.toml convention.

Requires the ai_tool fixes from OCA#125, cherry-picked in the
preceding commits (ir.model is not readable by internal users in 19.0).

Assisted-by: Devin:SWE-2 High
@nobuQuartile

Copy link
Copy Markdown
Author

@dreispt
Thank you!! I'll check it!

- _ai_jsonify: note that isinstance(date) also covers datetime.
- _ai_get_fields: document that reporting forbidden fields under
  "hidden" is deliberate, unlike group-restricted fields which are not
  disclosed.
- _ai_forbidden_fields: return early when no field is flagged.
- _ai_search_read: an explicit empty fields list now returns ids only;
  previously it fell back to the stored-fields default, same as no
  fields argument at all.

Assisted-by: Devin:SWE-2 High
Add a USAGE section covering how the registered ai.tool records are
consumed (e.g. via ai_oca_mcp), the list_models / get_fields /
search_read agent workflow, and the search_read arguments with an
example. Drop the "This module" opening from the description.

Assisted-by: Devin:SWE-2 High
@nobuQuartile
nobuQuartile force-pushed the 16.0-add-ai_tool_read branch from 210c87b to 609e40b Compare October 13, 2026 01:47
- The help of "AI Read Forbidden" still said that flagged fields are
  kept out of domains and orderings. They are not since the tools stopped
  rejecting them (see Known issues): say that the flag keeps values out of
  the results only, so that an administrator does not rely on it against
  filtering.
- A negative offset reached PostgreSQL and failed the call with a SQL
  error. Treat it as 0, next to the limit guard.
- The tool descriptions kept the leading newline and indentation of the
  XML text, shown as is in the form view and sent to MCP clients. Write
  each one as a single paragraph.
- CONFIGURE.md: start the list items with a capital letter.

Assisted-by: Claude Opus 5.5
@nobuQuartile

Copy link
Copy Markdown
Author

@dreispt Thanks again. I've updated the branch:

  • Cherry-picked your two commits from [MIG] ai_tool_read: Migration to 19.0 #127, the review follow-ups and the documentation revamp (README regenerated for 16.0).
  • Added 425e42a with a few fixes, which would apply to [MIG] ai_tool_read: Migration to 19.0 #127 as well:
    • The help of AI Read Forbidden no longer says that flagged fields are kept out of domains and orderings: the flag keeps values out of the results only (see Known issues).
    • A negative offset is treated as 0 instead of failing with a PostgreSQL error.
    • The tool descriptions are written as a single paragraph, without the leading newline and indentation that showed in the form view and were sent to MCP clients.
    • CONFIGURE.md: list items start with a capital letter.

The PR description is corrected accordingly, and CI is green.

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and functional review: LGTM

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@nobuQuartile

Copy link
Copy Markdown
Author

@etobella, this ADD PR is ready for you to review.
This module adds generic ai_tool tools that let an AI agent read any model and the fields it is allowed to access, while keeping personal or otherwise sensitive fields out of the results.
It's a versatile module, so please give it a try!

Thanks in advance for taking the time to review this PR! I really appreciate your feedback and support!

@nobuQuartile

Copy link
Copy Markdown
Author

@dreispt, could you merge this PR when you have time?
You had already reviewed it, and the PR has 2 approvals.
Thank you for your contribution.

@etobella etobella left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I get the idea of the tools

  1. You can access only models that the accessing user has access to. It implies that I cannot say that it only has access to products and not sale.orders and another MCP viceversa.
  2. Safety for me is correct

Let's merge it as there is no problems with the code

/ocabot merge nobump

@nobuQuartile

Copy link
Copy Markdown
Author

Thank you for checking this PR!

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-122-by-etobella-bump-nobump, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@etobella The merge process could not be finalized, because command twine upload --disable-progress-bar --non-interactive --repository-url https://upload.pypi.org/legacy/ -u __token__ odoo_addon_ai_tool_read-16.0.1.0.0.5-py3-none-any.whl failed with output:

Uploading distributions to https://upload.pypi.org/legacy/
Uploading odoo_addon_ai_tool_read-16.0.1.0.0.5-py3-none-any.whl
�[33mWARNING �[0m Error during upload. Retry with the --verbose option for more details. 
�[31mERROR   �[0m HTTPError: 429 Too Many Requests from https://upload.pypi.org/legacy/  
         Too Many Requests                                                      

@etobella

Copy link
Copy Markdown
Member

@OCA/pypi-support 🙏

@sebalix

sebalix commented Oct 21, 2026

Copy link
Copy Markdown

@etobella name reserved

@etobella

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-122-by-etobella-bump-nobump, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 7d4cf1c into OCA:16.0 Oct 21, 2026
8 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 6ec93fa. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants