# Run a background tool during a call

Use a background Agent Worker when the caller can continue talking while a slower operation runs. This example requests a public catalog refresh. A queued receipt confirms the handoff. The run receipt reports the outcome.

## Prompt

```text
Let our voice agent request a catalog refresh and keep talking. Rehearse the handoff and show me where to check the final result.
```

## Set up the Agent Worker

1. Connect the owner's tool server with `connect_mcp`, complete its returned approval step and read `get_mcp_connection`. This example provider implements `refresh_public_catalog` with no arguments and returns a boolean `refreshed`. Map the actual tool and response from the remote catalog before use. If the provider changes state, establish how to check the operation before repeating an uncertain request.
2. Create an Agent Worker with the function below, an approved `daily_limit_usd` and `max_call_cost_usd:"0"`. Bind the provider tool under `mcp.catalog`. Include these definition fields, substituting your connection ID.

```json
{"mcp":{"catalog":{"connection_id":"mcpc_00000000000000000000000000000001","tools":["refresh_public_catalog"]}},"tool":{"name":"request_catalog_refresh","description":"Request a refresh of the public catalog when asked.","mode":"background","parameters":{"type":"object","properties":{},"required":[],"additionalProperties":false}}}
```

```js
export default async function (event, ctx) {
  if (event.type !== "call.tool_requested") return { skipped: true };
  const reply = await ctx.mcp.call("catalog", "refresh_public_catalog", {});
  return { refreshed: reply.structuredContent?.refreshed === true };
}
```

3. Run `test_worker` with this event and inspect the result. Then activate the version after the owner approves the limits. Background execution has a 30-second deadline.

```json
{"type":"call.tool_requested","arguments":{},"mcp_fixtures":{"catalog":{"refresh_public_catalog":{"refreshed":true}}}}
```

4. Pass the active `worker_id` in the call's `tools` array. Give the voice agent this instruction: “If the caller requests a refresh and the tool accepts it, say you’ve queued it and continue the conversation.” The immediate receipt contains `thoughtly_worker.status:"pending"` and `run_id`. Inspect that run ID with `get_worker_run` for the final state. A timeout or `outcome_unknown` on a provider write requires checking the provider before retrying. The platform can cancel a live tool when the call ends. Use the [post-call playbook](/recipes/post-call-crm.md) for work that must start after hangup.
