---
title: "Long-Running Tools: Managing Asynchronous Jobs and Polling Patterns"
date: "2026-11-28T09:45:00+07:00"
description: "Handle jobs that outlive a turn with LongRunningFunctionTool — pause semantics, event.long_running_tool_ids, resuming with FunctionResponse, and when to poll instead."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/adk-long-running-tools-polling-patterns.jpg"
alt: "Clockwork gears and progress bars feeding into an automated workflow"
tags: ['google-adk', 'adk-tools', 'async-jobs', 'polling', 'human-in-the-loop']
---

Some operations do not fit inside a model turn: a report export takes four minutes, a manager's approval takes a day, a third-party job runs on someone else's schedule. Blocking the tool until it finishes burns your [execution deadline](/blog/adk-global-timeouts-execution-deadlines); returning a fake "done" lies to the model. ADK's answer is `LongRunningFunctionTool`: the tool *starts* the work, returns an initial result, and the framework deliberately pauses the agent run so your client can wait, poll, and later send the outcome back as a new message.

This tutorial covers the pause/resume mechanics, how the client detects pending calls through `event.long_running_tool_ids`, the exact shape of the resume message, and how to choose between a long-running tool, an async tool, and an external job you poll.

## The contract: start, don't wait

```python
from typing import Any
from google.adk.tools import LongRunningFunctionTool

def submit_export(report_id: str, format: str) -> dict[str, Any]:
    """Submit an asynchronous report export job.

    Args:
        report_id (str): Report to export, format 'R-12345'.
        format (str): Output format, 'csv' or 'pdf'.

    Returns:
        dict with 'status' ('pending' while running) and 'job_id'.
    """
    job_id = jobs.create(report_id=report_id, format=format)
    return {"status": "pending", "job_id": job_id,
            "summary": f"Export {job_id} started for report {report_id}."}

export_tool = LongRunningFunctionTool(func=submit_export)
```

Wrap semantics: your function starts the operation and returns immediately with an **initial result** — typically an operation ID and `status: 'pending'`. The framework packages that into a `FunctionResponse`, delivers it to the model so it can tell the user "export started, id X", and then **the agent run ends/pauses**. Nothing is left running inside the runner.

The docs are blunt about the boundary: this tool is for *starting and managing* long tasks, not *performing* them. The actual work belongs in a separate worker, queue, or service.

## Detecting the pause in your client

Events carry a `long_running_tool_ids` set — the IDs of function calls awaiting an external response. Your client captures the call, does the waiting (polling the job API, watching a queue, waiting for a human), and ships the result back:

```python
async def run_turn(query: str):
    content = types.Content(role="user", parts=[types.Part(text=query)])
    pending_call, pending_response = None, None

    async for event in runner.run_async(
        session_id=session.id, user_id=USER_ID, new_message=content
    ):
        if event.long_running_tool_ids and event.content and event.content.parts:
            for part in event.content.parts:
                if part.function_call and part.function_call.id in event.long_running_tool_ids:
                    pending_call = part.function_call
        if pending_call and event.content and event.content.parts:
            for part in event.content.parts:
                if part.function_response and part.function_response.id == pending_call.id:
                    pending_response = part.function_response
        if event.is_final_response() and event.content:
            print(event.content.parts[0].text)   # "Export started, id job_91"

    if pending_response:
        job_id = pending_response.response["job_id"]
        result = await poll_until_done(job_id)    # your own polling loop

        updated = pending_response.model_copy(deep=True)
        updated.response = {"status": "completed", "artifact_url": result.url}

        async for event in runner.run_async(
            session_id=session.id, user_id=USER_ID,
            new_message=types.Content(
                role="user",
                parts=[types.Part(function_response=updated)],
            ),
        ):
            if event.content and event.content.parts:
                print(event.content.parts[0].text)   # "Export ready: ..."
```

The resume message is a `FunctionResponse` part replayed as a user-turn message with the **same function-call ID** — that's what stitches it to the original call. Sending an intermediate response (`status: 'running', progress: 0.4`) lets the agent announce progress before the final one.

If the agent uses the **Resume** feature, the long-running response must also carry the `invocation_id` of the invocation that made the request — otherwise the system treats it as a new invocation entirely.

## Three patterns compared

| | Async function tool | `LongRunningFunctionTool` | External job + polling tool |
|---|---|---|---|
| Where work runs | Inside the turn, awaited | Started by tool, completed outside | Fully outside; tool only queries |
| Turn behaviour | Blocks until all parallel calls finish | Pauses after the initial result | Completes every turn with a status |
| Duration ceiling | Turn/deadline limits | Unbounded — waits are your client's business | Unbounded |
| Progress reporting | Only at the end | Intermediate `FunctionResponse` updates | Every poll can report |
| Client responsibility | None | Must capture `long_running_tool_ids` and resume | Must poll and decide when to stop |
| Fits | I/O-bound lookups, fan-out | Approval flows, exports, provisioning | Continuous pipelines, external CI |

Choose by *who owns the wait*: parallel I/O belongs in [async function tools](/blog/sync-vs-async-tools-adk); human or system waits belong in the long-running tool; continuous background work belongs outside the agent where you [run headless jobs](/blog/adk-headless-background-agents-async-queues).

## Polling design rules

When your client owns the wait, it owns the failure modes too:

- **Bound the loop.** Cap attempts *and* wall-clock time; a stuck job must reach a terminal `status: 'error'` response rather than polling forever ([timeouts and deadlines](/blog/adk-global-timeouts-execution-deadlines)).
- **Back off.** Exponential backoff with jitter — fixed-interval polling hammers the job API and gets you rate-limited ([429 handling](/blog/adk-rate-limits-429-exponential-backoff)).
- **Store the job ID in session state** (`tool_context.state["pending_export"] = job_id`) so a fresh turn or a second process can find it, rather than threading it through conversation text.
- **Be idempotent.** Resumes can be replayed; a job-status query must be safe to run twice.
- **Distinguish `pending` from `failed`.** An intermediate update saying "still running" and a final one saying "failed: report deleted" are different messages — encode that in the status field the way [error contracts](/blog/adk-tool-errors-recoverable-exceptions) dictate.

## Keeping the user informed

While the run is paused, the model has said nothing more — your UI is the channel. Show the pending call and its ID immediately, surface each intermediate `FunctionResponse` as a progress update, and only re-enter the agent loop when you have something worth narrating. Sessions persist events, so a resumed run's history is auditable: the initial call, each progress response, and the final outcome are all events in the session.

## Takeaways

- `LongRunningFunctionTool` starts work and returns an initial result; the framework pauses the run and your client decides when to resume — it never executes the long task itself.
- Detect pending calls via `event.long_running_tool_ids`, match responses by function-call ID, and resume by sending a `FunctionResponse` part (plus `invocation_id` when using Resume).
- Intermediate responses are progress updates; the final response closes the loop and lets the agent produce the user-facing answer.
- Pick the pattern by who owns the wait: async tool for in-turn I/O, long-running tool for waits your client controls, external jobs for continuous work.
- Bound every poll: deadline, backoff, idempotent status reads, and the job ID in session state.

## Further reading

- [Synchronous vs asynchronous tool implementations](/blog/sync-vs-async-tools-adk)
- [Handling tool errors and recoverable exceptions](/blog/adk-tool-errors-recoverable-exceptions)
- [Global timeouts and execution deadlines](/blog/adk-global-timeouts-execution-deadlines)
- [Streaming vs polling for async agent clients](/blog/streaming-vs-polling-async-agent-clients)
- [Pagination, timeouts, and long-running tool responses](/blog/pagination-timeouts-long-running-tool-responses)
- [ADK: Long running function tools](https://adk.dev/tools-custom/function-tools/)
