Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/geremyjampiersalasgarcia-eng/Caso_Practico_Semillero_IA/llms.txt

Use this file to discover all available pages before exploring further.

The Multimodal Agent (agente_multimodal) extends the standard RAG pattern with a two-stage vision pipeline. When a user attaches a product image, the agent first passes the base64-encoded image to Gemini’s multimodal capabilities to visually identify and describe the product, then queries the col_catalogo ChromaDB collection with the resulting description to retrieve pricing, availability, and any other catalog data. The final response integrates both the visual analysis and the catalog context into a single coherent answer.

When it triggers

The multimodal agent is invoked automatically whenever the image field is present in the ChatRequest payload. The intent classifier returns multimodal with confidence = 1.0 the moment an image is detected — regardless of the text question — so no additional routing configuration is required.

Agent properties

PropertyValue
nameagente_multimodal
collection_namecol_catalogo
system_prompt_pathbackend/app/prompts/multimodal_prompt.md
Knowledge baseShares col_catalogo with agente_catalogo
Intent triggermultimodal (auto-detected when image field is present)

Source class

from app.agents.base_agent import BaseAgent
from app.schemas.agent import AgentResult
from typing import Optional
import os


class MultimodalAgent(BaseAgent):
    """
    Agente Multimodal de Imagen.
    Analiza imágenes de productos usando la capacidad de visión de Google Gemini,
    identifica el producto y lo relaciona con el catálogo de Patito S.A.
    """

    @property
    def name(self) -> str:
        return "agente_multimodal"

    @property
    def description(self) -> str:
        return (
            "Analiza imágenes de productos usando visión de Gemini, "
            "identifica el producto y consulta precio y disponibilidad en el catálogo."
        )

    @property
    def collection_name(self) -> str:
        return "col_catalogo"  # Cruza con el catálogo para obtener precios

    @property
    def system_prompt_path(self) -> str:
        return os.path.join(
            os.path.dirname(__file__), "..", "prompts", "multimodal_prompt.md"
        )

    def process_query(
        self, question: str, image_data: Optional[str] = None
    ) -> AgentResult:
        """
        Flujo del agente multimodal:
        1. Recibe la imagen (base64) y la pregunta
        2. Usa Gemini Vision para analizar la imagen
        3. Busca en el catálogo (RAG) para complementar
        4. Retorna respuesta con producto, precio y disponibilidad
        """
        ...
        # Agregar la imagen como contenido multimodal
        if image_data.startswith("data:"):
            # Ya tiene el prefijo data:image/...;base64,
            image_url = image_data
        else:
            # Solo es base64 crudo, agregar prefijo
            image_url = f"data:image/jpeg;base64,{image_data}"

        message_content.append(
            {"type": "image_url", "image_url": {"url": image_url}}
        )
        message_content.append(
            {
                "type": "text",
                "text": "Describe detalladamente el producto que ves en la imagen e intenta identificar su nombre según los productos conocidos de Patito S.A."
            }
        )
Unlike the other four agents, MultimodalAgent overrides process_query to accept the optional image_data: Optional[str] parameter and implement the two-stage pipeline described below.

Sending an image

Include the image field in the POST /api/v1/chat request body as a base64 data URI:
{
  "question": "¿Qué producto es este y cuánto cuesta?",
  "conversation_id": null,
  "image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA..."
}
The question field is still required and provides the user’s intent (e.g., identifying the product, asking for its price, checking availability). The image field drives routing to agente_multimodal automatically.

Test images

The repository ships with two sample product images you can use immediately to verify the agent end-to-end:
docs/images/producto.webp
docs/images/artículo2.jpg
To test from the web UI, click the attach icon (📎), select one of the files above, and type a question such as:
“¿Qué producto es este? ¿Está en el catálogo y cuánto cuesta?”

How it works

The multimodal pipeline runs in two sequential Gemini calls: Step 1 — Vision analysis. The base64 image and the multimodal system prompt are sent together to ChatGoogleGenerativeAI as a multimodal HumanMessage with type: "image_url" and type: "text" content parts. Gemini Vision describes the item visible in the image and attempts to match it against the known Patito S.A. product lines (Pro, Lite, and accessories). Step 2 — Catalog cross-reference. The textual description produced in Step 1 is used as the query string for a retrieve_context() call against col_catalogo. The most relevant catalog chunks are retrieved and injected into a consolidation prompt alongside the visual analysis and the user’s original question. Step 3 — Response consolidation. A second LLM call combines the image description and catalog context to produce the final response: identified product, list price, availability status, and any other relevant catalog information. A 2-second sleep between calls prevents hitting Gemini’s free-tier rate limit (15 RPM). If the image cannot be matched to a known product, the agent states this clearly rather than guessing.
Images must be sent as base64 data URIs — either with the full data:image/jpeg;base64,... prefix or as raw base64 (the agent automatically prepends the prefix). File paths, URLs, and multipart/form-data uploads are not supported by this endpoint. Encode your image client-side before including it in the JSON body.

Build docs developers (and LLMs) love