## TL;DR
The agent's reply depends on a CRM lookup, the lookup is slow, and the reply times out. The fix is to stop doing fresh lookups in the reply path: cache the customer record at conversation start, refresh it in the background, and let the reply read from cache. A reply should never wait on a network call it could have made earlier.

## The query

```text
agent timed out waiting for CRM lookup mid-reply: caching
```

## Use this when

- Agent replies stall or time out on CRM lookups
- Lookups are slow for some customers but not others
- You're designing agent tool latency budgets


## Not for

- CRM API outages (different problem)
- Lookups returning the wrong record
- Slow reply generation unrelated to tools


## Steps

### 1. Measure the lookup latency distribution

Time the CRM lookup per customer. You'll find a slow tail: big accounts with huge histories take seconds while most answer in milliseconds. The timeout only bites the tail, which is why it looks intermittent.

Expected output: lookup p50 and p95 latencies, with the slow accounts identified.

### 2. Cache the record at conversation start

Fetch the customer record once when the conversation opens and keep it in memory for the session. Every reply reads the cache. Invalidate on explicit updates, not on a timer that expires mid-conversation.

Expected output: replies completing with zero CRM calls in the reply path.

### 3. Refresh slow data in the background

If some fields go stale (recent orders, ticket history), refresh them asynchronously after the reply, not before it. The reply uses the cached snapshot; the background job keeps the next reply fresh.

Expected output: background refreshes with no reply-path blocking.

### 4. Set a hard latency budget for tools

Give every agent tool a deadline: answer in under two seconds or the agent proceeds without it. A tool without a budget is a timeout waiting to happen. Log budget breaches as their own metric.

Expected output: a per-tool latency budget with breach logging.

## Variant phrasings

### ai agent slow crm lookup timeout

Steps 1 and 2: measure the tail, then cache at session start.

### support bot times out on customer data

Step 4's budget bounds every tool, not just the CRM.

## Why it happens

Agents call tools like local functions, but every tool is a network call with a latency distribution. The happy path is fast, so nobody budgets for the tail, and the tail is where enterprise customers live: the accounts with the most history are the slowest to look up and the most important to answer quickly.

## Edge cases

- Stale cache showing wrong data is worse than a slow lookup for money fields. Invalidate on writes.
- Cache per conversation, not globally. Customer data must never leak across sessions.
- Background refreshes need their own error handling. A failed refresh shouldn't break the reply.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_3vjCY2DdkDKm31g69vDeHQ
