Your First Workflow
We'll walk through creating a simple workflow that executes a single activity.
Prerequisites
Before running your workflow, you'll need to:
- Connect to the Mistral Console with your Mistral account
- Select a workspace and create a new API key
- Keep this API key handy — you'll use it when running
uvx mistralai-workflows-cli setupin the next step
Scaffold your project
The fastest way to get started is with the CLI:
uvx mistralai-workflows-cli setupThis scaffolds a ready-to-run Python project with the Workflows SDK already configured, a minimal example workflow, and helper commands to run your worker and trigger executions.
Alternatively, if you're adding Workflows to an existing project, follow the installation instructions.
Step 1: Define Your Workflow and Worker
Create a file my_workflow.py
import mistralai.workflows as workflows
# Activities are async functions that can take any JSON-serializable types
@workflows.activity()
async def hello_world(name: str) -> dict:
"""Activities are the building blocks of workflows.
1. It's the place where you do the actual work
(e.g. call an API, process data, CPU intensive tasks, etc.)
2. It must be async
3. Parameters can be any JSON-serializable type (str, int, dict, list, etc.)
"""
return {"message": f"Hello, {name}!"}
# Workflows orchestrate activities
@workflows.workflow.define(name="simple_example_workflow")
class SimpleExampleWorkflow:
@workflows.workflow.entrypoint
async def run(self, name: str) -> dict:
"""Workflow entry point.
1. It coordinate multiple activities
2. It may need to wait for external events
"""
return await hello_world(name)
# The Worker runs your workflows and activities
async def main() -> None:
await workflows.run_worker([SimpleExampleWorkflow])
if __name__ == "__main__":
import asyncio
asyncio.run(main())simple_example_workflow WorkflowStep 2: Run Your Worker with the simple_example_workflow Workflow
uv run python my_workflow.pyThe worker will start, connect to the Mistral API, and register your workflow and wait for any task to do. You will need to trigger execution in order to see the workflow running.
Step 3: Trigger execution of Your Workflow
- Visit https://console.mistral.ai/ (make sure you are located in the same workspace than the one you created your API key in)
- Click
Workflowsin the left sidebar - Select
simple_example_workflow - Launch the workflow using the
Start Workflowbutton and the input{"name": <your_name>} - Find your execution in the
Executionstab - Make sure the workflow ran until the end by checking if the output is correct
Multi-Worker Setup
For scaling patterns and running multiple workers, see Core Concepts - Scaling with Multiple Workers.