mistralM

Docs

Interface des outils

Affichez des composants d’interface enrichis dans le chat de Vibe Work et montrez ce que font les outils de votre workflow grâce aux états d’interface d’outils de type fichier, commande et générique.

Affichez des composants d’interface enrichis et interactifs dans l’interface de chat de Vibe Work et visualisez l’exécution des outils avec un retour de statut structuré. Utilisez les composants d’interface pour la mise en page et la visualisation ; utilisez les états d’interface d’outils pour montrer en temps réel ce que font vos outils.

Composants d’interface enrichis

Les workflows peuvent afficher des composants d’interface enrichis et interactifs dans l’interface de chat de Vibe Work à l’aide de la bibliothèque de composants du design system. Les composants sont définis sous forme d’objets Python et envoyés en tant que ressources UIComponentResource.

Utilisation de base

import mistralai.workflows as workflows
import mistralai.workflows.plugins.mistralai as workflows_mistralai
from mistralai.workflows.plugins.mistralai.conversational_ui_components import (
    Badge,
    Card,
    Column,
    Markdown,
    Row,
)

@workflows.workflow.define(
    name="report-workflow",
    workflow_display_name="Report",
    workflow_description="Generate a rich UI report",
)
class ReportWorkflow:
    @workflows.workflow.entrypoint
    async def run(self) -> workflows_mistralai.ChatAssistantWorkflowOutput:
        report = Card(
            title="Summary",
            children=[
                Row(
                    children=[
                        Markdown(content="**Score:** 0.82"),
                        Badge(variant="success", children="Pass"),
                    ],
                ),
            ],
        )

        await workflows_mistralai.send_assistant_message(
            [
                workflows_mistralai.TextOutput(text="Here is your report:"),
                workflows_mistralai.ResourceOutput(
                    resource=workflows_mistralai.UIComponentResource(component=report),
                ),
            ]
        )

        return workflows_mistralai.ChatAssistantWorkflowOutput(
            content=[
                workflows_mistralai.ResourceOutput(
                    resource=workflows_mistralai.UIComponentResource(component=report),
                ),
            ],
        )

A rich UI component rendered in Vibe Work, showing a card with a score and a success badge. Rich UI component in Vibe Work.

Composants disponibles

Tous les composants sont importés depuis mistralai.workflows.plugins.mistralai.conversational_ui_components.

Component

Description

Props principales

AlertMessages importants avec niveaux de gravitétitle, variant (info/warning/error/success), children
AvatarImage d’avatar de l’utilisateursrc, alt, text, size
BadgePetite étiquette pour les indicateurs de statutvariant (default/primary/success/warning/error), size, children
ButtonLinkLien stylisé en boutonhref, variant, size, external, children
CardConteneur avec titre et description facultatifstitle, description, padding, children
ChartGraphique en courbes ou en barresvariant (line/bar), data, xAxis, yAxis, title
ColumnConteneur de mise en page verticalalignment, distribution, gap, children
ImageAffichage d’imagesrc, alt, size
MarkdownTexte au format Markdowncontent
PieChartGraphique en secteurs avec segments étiquetésdata, title
RowConteneur de mise en page horizontalalignment, distribution, gap, wrap, children
TooltipInformations supplémentaires au survoltrigger, children

Imbriquer des composants

Les composants qui acceptent children peuvent contenir d’autres composants, ce qui vous permet de créer des mises en page complexes :

from mistralai.workflows.plugins.mistralai.conversational_ui_components import (
    Card,
    Chart,
    Column,
    Row,
)

layout = Row(
    children=[
        Card(
            title="Revenue",
            children=[
                Chart(
                    variant="line",
                    xAxis="month",
                    yAxis=["actual", "target"],
                    data=[
                        {"month": "Jan", "actual": 100, "target": 120},
                        {"month": "Feb", "actual": 140, "target": 130},
                        {"month": "Mar", "actual": 160, "target": 140},
                    ],
                ),
            ],
        ),
        Card(
            title="Distribution",
            children=[
                Chart(
                    variant="bar",
                    xAxis="category",
                    yAxis="count",
                    data=[
                        {"category": "A", "count": 42},
                        {"category": "B", "count": 28},
                        {"category": "C", "count": 15},
                    ],
                ),
            ],
        ),
    ],
)

Nested rich UI components rendered in Vibe Work, showing two cards each containing a chart. Nested components with charts in Vibe Work.

États d’interface des outils

Les états d’interface des outils fournissent des représentations visuelles facultatives de l’exécution des outils dans l’interface de chat de Vibe Work. Associés à ChatAssistantWorkingTask, ils permettent un retour visuel spécialisé selon les types d’opérations d’outils, ce qui permet aux workflows d’afficher le statut et les résultats des appels d’outils de manière structurée et conviviale.

Types d’états d’interface des outils

Il existe trois types d’états d’interface des outils :

État d’interface d’outil de fichier

Représente des opérations sur des fichiers, comme la création, le remplacement ou la suppression de fichiers :

from mistralai.workflows.conversational import (
    FileToolUIState,
    CreateFileOperation,
    ReplaceFileOperation,
    DeleteFileOperation,
)

# Create a file
create_state = FileToolUIState(
    toolCallId="tc-1",
    operations=[
        CreateFileOperation(
            uri="file:///workspace/new.py",
            content="print('Hello World')"
        )
    ],
)

# Replace file content
replace_state = FileToolUIState(
    toolCallId="tc-2",
    operations=[
        ReplaceFileOperation(
            uri="file:///workspace/main.py",
            fileContentBefore="old content",
            blocks=[SearchReplaceBlock(search="old", replace="new")],
        )
    ],
)

# Delete a file
delete_state = FileToolUIState(
    toolCallId="tc-3",
    operations=[
        DeleteFileOperation(uri="file:///workspace/old.py")
    ],
)

A file tool UI state rendered in Vibe Work, showing file operation feedback. File tool UI state in Vibe Work.

État d’interface d’outil générique

Représente l’exécution d’un outil générique avec différents états de statut :

from mistralai.workflows.conversational import (
    GenericToolUIState,
    ToolResultRunning,
    ToolResultSuccess,
    ToolResultFailed,
)

# Tool is running
running_state = GenericToolUIState(
    toolCallId="tc-1",
    name="bash",
    arguments={"command": "ls -la"},
    result=ToolResultRunning(),
)

# Tool completed successfully
success_state = GenericToolUIState(
    toolCallId="tc-2",
    name="grep",
    arguments={"pattern": "TODO"},
    result=ToolResultSuccess(value={"matches": ["line1", "line2"]}),
)

# Tool failed
failed_state = GenericToolUIState(
    toolCallId="tc-3",
    name="bash",
    arguments={"command": "false"},
    result=ToolResultFailed(error="exit code 1"),
)

A generic tool UI state rendered in Vibe Work, showing tool execution status. Generic tool UI state in Vibe Work.

État d’interface d’outil de commande

Représente l’exécution d’une commande avec les états running/success/failed :

from mistralai.workflows.conversational import (
    CommandToolUIState,
    CommandResultRunning,
    CommandResultSuccess,
    CommandResultFailed,
)

# Command is running
running_state = CommandToolUIState(
    toolCallId="tc-1",
    command="npm install",
    result=CommandResultRunning(),
)

# Command completed successfully
success_state = CommandToolUIState(
    toolCallId="tc-2",
    command="pytest",
    result=CommandResultSuccess(output="All tests passed"),
)

# Command failed
failed_state = CommandToolUIState(
    toolCallId="tc-3",
    command="invalid-command",
    result=CommandResultFailed(error="Command not found"),
)

A command tool UI state rendered in Vibe Work, showing command execution status. Command tool UI state in Vibe Work.

Utiliser les états d’interface des outils dans les tâches en cours

Les états d’interface des outils peuvent être associés à ChatAssistantWorkingTask pour fournir un retour visuel pendant l’exécution des outils :

from mistralai.workflows.conversational import ChatAssistantWorkingTask

# Show a working task with file operations
task = ChatAssistantWorkingTask(
    title="Creating file",
    content="Generating new.py",
    toolUIState=FileToolUIState(
        toolCallId="tc-1",
        operations=[CreateFileOperation(uri="file:///workspace/new.py", content="print('hi')")],
    ),
)

# Show a working task with command execution
command_task = ChatAssistantWorkingTask(
    title="Running tests",
    content="Executing pytest",
    toolUIState=CommandToolUIState(
        toolCallId="tc-2",
        command="pytest",
        result=CommandResultRunning(),
    ),
)