- Studio
- What is Mistral Workflows?
Quickstart: build your first workflow
Quickstart: build your first workflow
In this quickstart, you scaffold a workflows project with the Mistral CLI, add a workflow with one activity, run a worker on your machine, and start an execution that returns a greeting. It takes about 15 minutes. For what workflows, activities, and workers are, see Workflows.
Before you begin
- A Mistral API key, exported as MISTRAL_API_KEY. To create one, see Create your first API key.
- The Mistral CLI. To install it and sign in, see Install the Mistral CLI and create a project. Running the worker locally needs Bun, which the CLI installer offers to install.
- macOS or Linux: the CLI installer supports only these operating systems.
- Python 3.12 or newer and Git: Python runs the worker, Git is required to scaffold.
- uv, which runs the Python worker.
1. Create the project
Scaffold a workflows project with mistral workflows init, the same command as mistral init --preset workflow:
mistral workflows init my-workflow
cd my-workflow
If you created my-workflow in the Mistral CLI quickstart, go to that directory instead.
The project contains a Python worker in apps/worker, with the Workflows SDK already configured. Open the generated .env file and set MISTRAL_API_KEY to your API key: the worker reads it to connect to Mistral. Git ignores .env, so the key stays out of the repository.
The scaffold also ships mistral.json, which declares the worker module to the platform, and an agent skill in .agents/skills/capability-workflows/ with the rules a workflow must follow: point your coding agent at it before writing more workflows.
2. Add a workflow
Create apps/worker/src/worker/workflows/hello.py:
from pydantic import BaseModel
import mistralai.workflows as workflows
class HelloInput(BaseModel):
name: str = "World"
@workflows.activity()
async def greet(name: str) -> str:
"""A simple activity that returns a greeting."""
return f"Hello, {name}! Welcome to Mistral Workflows."
@workflows.workflow.define(
name="hello-world",
workflow_display_name="Hello World",
workflow_description="A minimal hello-world workflow.",
)
class HelloWorkflow:
@workflows.workflow.entrypoint
async def run(self, input: HelloInput) -> str:
return await greet(input.name)
The workflow is registered as hello-world and takes a name. Its only step, greet, is an activity: if the worker stops during an execution, the platform resumes from the last completed activity instead of starting over.
You don't need to register the workflow by hand. The worker entrypoint, apps/worker/src/worker/entrypoints/worker.py, discovers every workflow in the workflows package, subpackages included, so a new file needs no other registration:
workflow_classes = workflows.discover_all_workflows_in_package("worker.workflows")
await workflows_client.run_worker(workflow_classes)
3. Start the worker
From the root of the project, start the worker with mistral dev:
mistral dev
The worker connects to Mistral, registers hello-world, and waits for executions. A file watcher restarts it when you change a file in apps/worker/src/. Keep this terminal open: an execution runs only while a worker is running.
4. Start an execution
In a second terminal, start an execution of hello-world. With wait_for_result, the call returns when the execution completes:
curl -X POST https://api.mistral.ai/v1/workflows/hello-world/execute \
-H "Authorization: Bearer $MISTRAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": {"name": "Ada"}, "wait_for_result": true}'
You should see
The response holds the value that the workflow returned:
{
"workflow_name": "hello-world",
"execution_id": "<execution-id>",
"result": {
"result": "Hello, Ada! Welcome to Mistral Workflows."
}
}
In the console, the execution of hello-world appears in the Executions tab with the same result. The worker terminal logs the execution.
If the call waits and then times out, check that the worker from step 3 is still running, in the workspace of your API key.
Clean up
To stop the worker, press Ctrl+C in its terminal. Keep the project if you want to deploy it in the next quickstart.
Going further
Quickstart: deploy a workflow to Mistral
Scaffold a Workflows project with the Mistral CLI, push it to GitHub, and let Mistral Cloud build and run the worker for you.
Quickstart: send your first trace
Instrument a Python script with the Mistral SDK, send a first trace to Studio, and find it in the Trace Explorer.
Start a workflow from a webhook
Start workflows from events in business tools and APIs.
Workflow concepts
Understand workflows as the orchestration layer that coordinates activities, survives failures, and must stay deterministic.