Add parallel tool execution to the support assistant

Python · LLM apps · advanced · greenfield

Parallelises tool execution in the support assistant: when the model asks for several tools at once — say, a customer lookup and their orders — they run concurrently instead of one after the other, each on its own DB session. Model-produced arguments are validated against the declared schemas before a tool runs, failed tools return their error as a structured tool message so the model can adapt, and provider outages still surface as a clean 502. Exercised the multi-tool path against a seeded database, including a forced warehouse timeout, and the assistant wove the results into a single answer.

Internal support console. Agents look up customers, their orders, and stock levels; when a model response asks for two or three tools at once, parallel execution cuts the wall-clock time for the agent. The tools call separate internal services — a customer DB, an orders service, and a warehouse system — any of which can occasionally time out. `require_support_agent` (in `app/auth.py`, outside this PR) is the existing FastAPI dependency that validates the console's SSO session; `SessionLocal` (in `app/db.py`, outside this PR) is the existing SQLAlchemy `async_sessionmaker`.

Requirements

Files touched

--- app/tools.py
+"""Support assistant tools: schemas and async implementations."""
+
+from __future__ import annotations
+
+from typing import Any
+
+from sqlalchemy import select
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from app.models import Customer, InventoryItem, Order
+
+ORDER_STATUSES = ("placed", "shipped", "delivered", "cancelled")
+
+# ── Tool schemas ──────────────────────────────────────────────────────────
+
+LOOKUP_CUSTOMER_TOOL: dict[str, Any] = {
+    "type": "function",
+    "function": {
+        "name": "lookup_customer",
+        "description": "Look up a customer by exact email address.",
+        "parameters": {
+            "type": "object",
+            "properties": {
+                "email": {
+                    "type": "string",
+                    "minLength": 1,
+                    "description": "The customer's exact email address.",
+                },
+            },

Review this PR

Python practice