Skip to content

AI Models API Package

nautobot_ai_models.api

REST API module for nautobot_ai_models app.

serializers

API serializers for nautobot_ai_models.

The MCP tool serializer carries the whole advertised definition, both schemas included.

AIAgentSerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin

AI Agent Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AIAgentSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):  # pylint: disable=too-many-ancestors
    """AI Agent Serializer."""

    is_available = drf_serializers.BooleanField(read_only=True)
    tool_count = drf_serializers.SerializerMethodField()

    class Meta:
        """Meta attributes."""

        model = models.AIAgent
        fields = "__all__"

    def get_tool_count(self, obj) -> int:
        """How many tools this agent may call.

        This method reads the annotation the viewset adds, and falls back to a count, so a queryset
        without the annotation still serialises.

        Args:
            obj (AIAgent): The agent to render.

        Returns:
            The viewset's annotation, or a count when the object did not come from that queryset.
        """
        count = getattr(obj, "tool_count", None)
        return obj.tool_bindings.count() if count is None else count
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIAgent
    fields = "__all__"
get_tool_count(obj)

How many tools this agent may call.

This method reads the annotation the viewset adds, and falls back to a count, so a queryset without the annotation still serialises.

Parameters:

Name Type Description Default
obj AIAgent

The agent to render.

required

Returns:

Type Description
int

The viewset's annotation, or a count when the object did not come from that queryset.

Source code in nautobot_ai_models/api/serializers.py
def get_tool_count(self, obj) -> int:
    """How many tools this agent may call.

    This method reads the annotation the viewset adds, and falls back to a count, so a queryset
    without the annotation still serialises.

    Args:
        obj (AIAgent): The agent to render.

    Returns:
        The viewset's annotation, or a count when the object did not come from that queryset.
    """
    count = getattr(obj, "tool_count", None)
    return obj.tool_bindings.count() if count is None else count

AIAgentSkillSerializer

Bases: NautobotModelSerializer

AI Agent Skill Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AIAgentSkillSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Agent Skill Serializer."""

    class Meta:
        """Meta attributes."""

        model = models.AIAgentSkill
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIAgentSkill
    fields = "__all__"

AIAgentSubagentSerializer

Bases: NautobotModelSerializer

AI Agent Subagent Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AIAgentSubagentSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Agent Subagent Serializer."""

    wire_name = drf_serializers.CharField(read_only=True)
    wire_description = drf_serializers.CharField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AIAgentSubagent
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIAgentSubagent
    fields = "__all__"

AIAgentThreadSerializer

Bases: NautobotModelSerializer

AI Agent Thread Serializer.

thread_id is neither read-only nor writable here. The column is editable=False, so the server allocates the value and returns it. A consuming app reads it back from the response and checkpoints under it.

Source code in nautobot_ai_models/api/serializers.py
class AIAgentThreadSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Agent Thread Serializer.

    `thread_id` is neither read-only nor writable here. The column is ``editable=False``, so the
    server allocates the value and returns it. A consuming app reads it back from the response and
    checkpoints under it.
    """

    is_live = drf_serializers.BooleanField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AIAgentThread
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIAgentThread
    fields = "__all__"

AIAgentToolSerializer

Bases: NautobotModelSerializer

AI Agent Tool Serializer.

The four resolved fields are what the model is told. They come from the binding and its target, so they are read-only, and they are worth a return: a client that checks what an agent offers must not have to work them out again.

Source code in nautobot_ai_models/api/serializers.py
class AIAgentToolSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Agent Tool Serializer.

    The four resolved fields are what the model is told. They come from the binding and its
    target, so they are read-only, and they are worth a return: a client that checks what an agent
    offers must not have to work them out again.
    """

    wire_name = drf_serializers.CharField(read_only=True)
    wire_description = drf_serializers.CharField(read_only=True)
    writable = drf_serializers.BooleanField(read_only=True)
    fingerprint = drf_serializers.CharField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AIAgentTool
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIAgentTool
    fields = "__all__"

AIModelSerializer

Bases: NautobotModelSerializer

AI Model Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AIModelSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Model Serializer."""

    is_available = drf_serializers.BooleanField(read_only=True)
    resolved_parameters = drf_serializers.JSONField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AIModel
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIModel
    fields = "__all__"

AIProviderSerializer

Bases: NautobotModelSerializer

AI Provider Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AIProviderSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Provider Serializer."""

    class Meta:
        """Meta attributes."""

        model = models.AIProvider
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AIProvider
    fields = "__all__"

AISkillSerializer

Bases: NautobotModelSerializer

AI Skill Serializer.

Source code in nautobot_ai_models/api/serializers.py
class AISkillSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Skill Serializer."""

    is_available = drf_serializers.BooleanField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AISkill
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AISkill
    fields = "__all__"

AIToolSerializer

Bases: NautobotModelSerializer

AI Tool Serializer.

What discovery wrote about the tool is read-only, because the next Sync AI Tools Job run would overwrite a change to it. The rest stays writable: a Job tool is an operator's decision, not a discovery, and AITool.clean() refuses a row that names nothing real.

Source code in nautobot_ai_models/api/serializers.py
class AIToolSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """AI Tool Serializer.

    What discovery wrote about the tool is read-only, because the next Sync AI Tools Job run would
    overwrite a change to it. The rest stays writable: a Job tool is an operator's decision, not a
    discovery, and `AITool.clean()` refuses a row that names nothing real.
    """

    is_available = drf_serializers.BooleanField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.AITool
        fields = "__all__"
        read_only_fields = ["advertised_read_only", "definition_fingerprint", "last_seen_at"]
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.AITool
    fields = "__all__"
    read_only_fields = ["advertised_read_only", "definition_fingerprint", "last_seen_at"]

MCPServerSerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin

MCPServer Serializer.

Source code in nautobot_ai_models/api/serializers.py
class MCPServerSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):  # pylint: disable=too-many-ancestors
    """MCPServer Serializer."""

    tool_count = drf_serializers.SerializerMethodField()

    class Meta:
        """Meta attributes."""

        model = models.MCPServer
        fields = "__all__"

        read_only_fields = list(MCP_SERVER_DISCOVERED_FIELDS)

    def get_tool_count(self, obj) -> int:
        """Return how many tools this server offers.

        Args:
            obj (MCPServer): The server being rendered.

        Returns:
            The viewset's annotation, or a count when the object did not come from that queryset.
        """
        count = getattr(obj, "tool_count", None)
        return obj.tools.count() if count is None else count
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.MCPServer
    fields = "__all__"

    read_only_fields = list(MCP_SERVER_DISCOVERED_FIELDS)
get_tool_count(obj)

Return how many tools this server offers.

Parameters:

Name Type Description Default
obj MCPServer

The server being rendered.

required

Returns:

Type Description
int

The viewset's annotation, or a count when the object did not come from that queryset.

Source code in nautobot_ai_models/api/serializers.py
def get_tool_count(self, obj) -> int:
    """Return how many tools this server offers.

    Args:
        obj (MCPServer): The server being rendered.

    Returns:
        The viewset's annotation, or a count when the object did not come from that queryset.
    """
    count = getattr(obj, "tool_count", None)
    return obj.tools.count() if count is None else count

MCPToolSerializer

Bases: NautobotModelSerializer

MCPTool Serializer.

Source code in nautobot_ai_models/api/serializers.py
class MCPToolSerializer(NautobotModelSerializer):  # pylint: disable=too-many-ancestors
    """MCPTool Serializer."""

    is_available = drf_serializers.BooleanField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.MCPTool
        fields = "__all__"

        read_only_fields = [
            "definition_fingerprint",
            "last_seen_at",
        ]
Meta

Meta attributes.

Source code in nautobot_ai_models/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.MCPTool
    fields = "__all__"

    read_only_fields = [
        "definition_fingerprint",
        "last_seen_at",
    ]

urls

Django API urlpatterns declaration for nautobot_ai_models app.

views

API views for nautobot_ai_models.

AIAgentSkillViewSet

Bases: NautobotModelViewSet

AI Agent Skill viewset.

Source code in nautobot_ai_models/api/views.py
class AIAgentSkillViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Agent Skill viewset."""

    queryset = models.AIAgentSkill.objects.select_related("agent", "skill")
    serializer_class = serializers.AIAgentSkillSerializer
    filterset_class = filters.AIAgentSkillFilterSet

AIAgentSubagentViewSet

Bases: NautobotModelViewSet

AI Agent Subagent viewset.

Source code in nautobot_ai_models/api/views.py
class AIAgentSubagentViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Agent Subagent viewset."""

    queryset = models.AIAgentSubagent.objects.select_related("parent", "subagent")
    serializer_class = serializers.AIAgentSubagentSerializer
    filterset_class = filters.AIAgentSubagentFilterSet

AIAgentThreadViewSet

Bases: NautobotModelViewSet

AI Agent Thread viewset.

Source code in nautobot_ai_models/api/views.py
class AIAgentThreadViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Agent Thread viewset."""

    queryset = models.AIAgentThread.objects.select_related("agent")
    serializer_class = serializers.AIAgentThreadSerializer
    filterset_class = filters.AIAgentThreadFilterSet

AIAgentToolViewSet

Bases: NautobotModelViewSet

AI Agent Tool viewset.

Source code in nautobot_ai_models/api/views.py
class AIAgentToolViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Agent Tool viewset."""

    queryset = models.AIAgentTool.objects.select_related("agent", "mcp_tool__mcp_server", "ai_tool")
    serializer_class = serializers.AIAgentToolSerializer
    filterset_class = filters.AIAgentToolFilterSet

AIAgentViewSet

Bases: NautobotModelViewSet

AI Agent viewset.

Source code in nautobot_ai_models/api/views.py
class AIAgentViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Agent viewset."""

    queryset = models.AIAgent.objects.select_related("model__provider", "tenant").annotate(
        tool_count=count_related(models.AIAgentTool, "agent")
    )
    serializer_class = serializers.AIAgentSerializer
    filterset_class = filters.AIAgentFilterSet

AIModelViewSet

Bases: NautobotModelViewSet

AI Model viewset.

Source code in nautobot_ai_models/api/views.py
class AIModelViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Model viewset."""

    queryset = models.AIModel.objects.select_related("provider")
    serializer_class = serializers.AIModelSerializer
    filterset_class = filters.AIModelFilterSet

AIProviderViewSet

Bases: NautobotModelViewSet

AI Provider viewset.

Source code in nautobot_ai_models/api/views.py
class AIProviderViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Provider viewset."""

    queryset = models.AIProvider.objects.select_related("external_integration")
    serializer_class = serializers.AIProviderSerializer
    filterset_class = filters.AIProviderFilterSet

AISkillViewSet

Bases: NautobotModelViewSet

AI Skill viewset.

Source code in nautobot_ai_models/api/views.py
class AISkillViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Skill viewset."""

    queryset = models.AISkill.objects.all()
    serializer_class = serializers.AISkillSerializer
    filterset_class = filters.AISkillFilterSet

AIToolViewSet

Bases: NautobotModelViewSet

AI Tool viewset.

Source code in nautobot_ai_models/api/views.py
class AIToolViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """AI Tool viewset."""

    queryset = models.AITool.objects.select_related("job", "git_repository")
    serializer_class = serializers.AIToolSerializer
    filterset_class = filters.AIToolFilterSet

MCPServerViewSet

Bases: NautobotModelViewSet

MCPServer viewset.

Source code in nautobot_ai_models/api/views.py
class MCPServerViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """MCPServer viewset."""

    queryset = models.MCPServer.objects.select_related("external_integration", "tenant").annotate(
        tool_count=count_related(models.MCPTool, "mcp_server")
    )
    serializer_class = serializers.MCPServerSerializer
    filterset_class = filters.MCPServerFilterSet

MCPToolViewSet

Bases: NautobotModelViewSet

MCPTool viewset.

Source code in nautobot_ai_models/api/views.py
class MCPToolViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """MCPTool viewset."""

    queryset = models.MCPTool.objects.select_related("mcp_server")
    serializer_class = serializers.MCPToolSerializer
    filterset_class = filters.MCPToolFilterSet