← Code Exchange

Durable Stateful Agents with Mistral + Temporal + MCP

Long-running LLM agent workflows can be subjected to failures, network issues, and third-party API exceptions. In many situations, manual intervention is needed to identify issues and debug them. For production systems, this can be prohibitively expensive. This is the main reason many companies rely on Temporal for orchestrating agents in production.

The other challenge that can arise is agent status management and short memory for conversational agents.

To address these challenges, I extended my previous durable agents with Temporal project with:

  • Stateful agents – Mistral manages agent definitions and conversation history server-side (beta feature)
  • Enhanced retries – HTTP retry mechanism distinguishes retriable vs. terminal failures
  • API gateway – FastAPI server triggers workflows and polls results for frontend clients
  • Full observability – Logfire traces capture MCP/FastAPI server transactions, agent status, token usage, and retry behavior
  • MCP tools – Dedicated MCP server with Yahoo Finance integration
  • Architecture

Core Stack:

  • Mistral AI Agent API – Server-side stateful agents. Register agents on Mistral's infrastructure, update their configurations, and run multi-turn conversations with persistent state managed by Mistral.
  • Temporal Workflows – Durable orchestration. Activities automatically retry on failure; workflows resume from last checkpoint.
  • MCP Server – Exposes tools and prompts over HTTP/SSE. Agents discover capabilities at runtime.
  • Logfire (optional) – OpenTelemetry-native observability. Auto-instruments FastAPI endpoints and Mistral agent calls with full request/response traces.

Key Design Decisions:

  • Mistral hosts agent state server-side – Unlike traditional stateless LLM APIs, Mistral's Agent API maintains agent definitions and conversation history on their servers. You register agents once, then interact via agent_id.
  • Temporal workflows orchestrate agent interactions – Workflow state persists locally while Mistral manages agent and conversation state remotely. Workflows survive crashes and coordinate multi-step agent tasks.
  • Prompt and tools access via MCP server – Temporal activities create agents with instructions fetched from a local MCP server. Instruction prompts are separated from code. Agents can run available tools server side.
  • FastAPI orchestrates requests – Receives user queries, triggers Temporal workflows, and polls workflow results using Temporal query handles.
  • Logfire instruments the entire request path – Captures FastAPI route traces, Mistral API calls with token usage, and correlates them in a unified trace view.

Language

Python
💖 Community AIMCP

About the Author

amri369

Dr. Mohamed Amri