Skip to content

Proposal: Example Notebook for Async ADK Task Orchestration via GenAI #715

@andycandy

Description

@andycandy

Description of the feature request:

I'd like to propose adding a new example notebook to the examples/google-adk/ directory (assuming #709 is planned). This notebook would demonstrate a more advanced integration pattern, showcasing how to manage asynchronous background tasks using Google ADK, triggered and monitored through a conversational interface powered by the google-genai SDK.

What problem are you trying to solve with this feature?

Currently, standard function calling with google-genai is synchronous. Many real-world applications require initiating long-running background processes without blocking the main user conversation. Users expect to continue interacting with the assistant while these tasks are completed and potentially query their status later. This example would provide a clear pattern for achieving this responsiveness using ADK for the task orchestration layer.

Any other information you'd like to share?

Proposed Scenario & Workflow

Image

The notebook would implement the "Asynchronous Query Handling Process" (similar to the diagram discussed/provided):

  1. User Interaction: A user interacts with a primary assistant interface built using the google-genai SDK.
  2. Task Initiation: The user asks the assistant to perform a long-running task (e.g., "Find details about X in the database").
  3. GenAI Interpretation & ADK Trigger: The google-genai assistant interprets the command and calls a synchronous ADK FunctionTool (start_long_query).
  4. ADK Tool Action (Initiate & Return): This ADK tool executes quickly:
    • Generates a unique job_id.
    • Uses asyncio.create_task() to schedule the actual long-running async function (run_actual_query_async) to execute concurrently in the background. This background function will contain the simulated work (e.g., await asyncio.sleep()) and logic to update a shared state store.
    • Immediately records the initial 'PENDING' status for the job_id in a simulated Shared State Store (e.g., a Python dictionary).
    • Immediately returns {'status': 'success', 'job_id': 'job_id'} back to the google-genai assistant.
  5. User Confirmation: The google-genai assistant confirms task initiation ("Okay, I've started job job-123...") and is immediately ready for the next user message.
  6. Background Processing (Asyncio Task): The asyncio task (run_actual_query_async) runs independently: updates status to 'RUNNING' in the state store, performs simulated work, updates status to 'COMPLETED'/'FAILED', and stores results/errors in the state store.
  7. Ongoing Interaction: User can continue chatting or initiate new background tasks (each creating its own asyncio task).
  8. Status Check: User asks for the status of job-123.
  9. GenAI Interpretation & ADK Query: Assistant calls a second synchronous ADK FunctionTool (check_query_status).
  10. ADK Tool Action (Query): This tool queries the simulated Shared State Store for the status/results of the job_id.
  11. Report Status: The google-genai assistant relays the retrieved status/results to the user.

Benefits:

  • Provides a practical pattern for responsive, long-running task initiation via chat.
  • Shows how ADK tools can integrate with Python's asyncio for background processing.
  • Demonstrates synergy between google-genai and google-adk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions