Skip to content

AI Tool

One tool that an agent may call that did not come from an MCP server. A Python function that an app registered in code, or a Nautobot Job.

This model has the same shape as MCP Tool, field for field where it can. The approval gate of a consuming app asks each tool three questions: is it offered, does it need a person, and did its definition move. If a second tool source could not answer them, its tools would bypass the gate. An MCP tool cannot bypass it.

Records are written by a Job

Do not create a row by hand. A consuming app declares a tool in code:

from nautobot_ai_models.tools import register_ai_tool


@register_ai_tool(writable=False)
def lookup_device(hostname: str) -> str:
    """Look up one device by hostname. Returns vendor, site, and platform."""

The Sync AI Tools Job then reads what the code declared and writes the record. The name comes from the function. The description comes from the docstring. The argument schema comes from the type hints.

The repository sync writes a tool that a Git repository declares, and the Job leaves it alone. Both write the record the same way.

The app refuses to save a row of kind registered whose name nothing registered. The row is a claim that code exists under that name.

NOTE: The registry stores a name. It never stores a Python import path, and it never imports a module that a database row named.

There is no add view, no import view and no rename view in the user interface, because none of them could write a usable row. A person can only read the list and the detail page. The edit page offers the two flags that a person owns, enabled and writable, and nothing else. The Sync AI Tools Job writes every other field and overwrites it on its next run.

A tool of kind git comes from a Git repository instead of an installed app. The repository declares it the same way, in an ai_tools module that it carries, and the repository sync writes the record. See Tools from a Git Repository.

Get the user

A tool can show only the objects that the user can view. Pass takes_user=True, and add a keyword-only parameter user:

from nautobot.dcim.models import Device

from nautobot_ai_models.tools import register_ai_tool


@register_ai_tool(writable=False, takes_user=True)
def count_devices(site: str, *, user) -> str:
    """Count the devices at one site that you can view. Send the site name."""
    devices = Device.objects.restrict(user, "view").filter(location__name=site)
    return f"{devices.count()} devices at {site}"
  • The tool gets the user that the consuming app gave to build_agent(..., user=...).
  • The argument schema does not show user, so the model cannot send it. The tool drops a user value from the model, and each argument that is not in the schema.
  • A build with no user raises AgentBuildError.
  • Registration raises ValueError if user is not a keyword-only parameter, or if a type hint cannot be read.

A tool without takes_user keeps its schema and its digest.

Fields

Field Type Required Description
name String Yes Unique. The name the tool is called by.
description Text No What the model reads to decide whether to call this.
argument_schema JSON No The parameters, as JSON Schema.
kind Choice Yes registered, git, or job.
module String No Where the callable was found.
git_repository Git Repository No The repository the tool was synced from.
job Job No The Job that a job tool starts.
enabled Boolean Yes The app does not offer a disabled tool.
writable Boolean Yes Whether a call to this tool changes something.
advertised_read_only Boolean No What the tool said about itself.
definition_fingerprint String No A digest of the name, description, and schema.
last_seen_at Datetime No When the Sync AI Tools Job last found this tool.

Two flags, not one

The same rule that MCP Tool follows.

  • writable is the decision of a person. It defaults to True. A wrong guess this way costs a review. A wrong guess the other way tells a consuming app that a tool is safe when it is not.
  • advertised_read_only is what the decorator declared. The Sync AI Tools Job writes it on every run. It decides nothing.

A Job tool starts a Job

WARNING: A Nautobot Job runs through Celery and produces a Job Result. A tool of kind job starts the Job and returns immediately with the Job Result identifier and a link. It does not wait, and it does not read the result. An agent loop is bounded, and a queue can outlast it.

The Job runs as the user that the consuming app named when it built the agent, and that user needs the permission to run it. JobResult.enqueue_job is the raw execution primitive and checks nothing, so the tool checks before it calls: it refuses a Job that is disabled or not installed, a user without extras.run_job on that Job, a Job that takes sensitive variables, and a Job with an approval workflow. The tool returns each refusal to the model as text, so the agent reports it and does not fail.

WARNING: A model decides when to call a tool. Somebody else can write what a model reads, for example a syslog line, a ticket, or an answer from an MCP server. A Job tool on an agent is therefore not the same as an operator who presses Run. Bind only Jobs you would let that text start. The agent runs as a user. Keep the extras.run_job permission of that user as narrow as the work needs.

You cannot change the Job of a tool after the record exists. A new Job would change what an approved tool does, while its name, its description, and so its digest stay the same.