Skip to content

Commit 4111f85

Browse files
krishna-dhulipallacopybara-github
authored andcommitted
docs(adk): fix run_async example and correct ticketId payload key
Merge #3875 # Problem The example in `contributing/samples/human_in_loop/README.md` shows: ```python await runner.run_async(...) ``` However, `run_async` returns an **async generator**, so awaiting it raises: ``` TypeError: object async_generator can't be used in 'await' expression ``` Additionally, the example payload uses `"ticket-id"` while ADK tools and other examples use `"ticketId"`, creating a mismatch that breaks copy/paste usage. # Solution - Updated the snippet to consume the async generator correctly: ```python async for event in runner.run_async(...): ... ``` - Aligned the payload key from `"ticket-id"` → `"ticketId"` for consistency with ADK schema and other examples. These changes make the example runnable and consistent with the API’s actual behavior. # Testing Plan This PR is a **small documentation correction**, so no unit tests are required per contribution guidelines. - Verified the corrected snippet manually to ensure it no longer raises `TypeError`. # Checklist - [x] I have read the CONTRIBUTING.md document. - [x] I have performed a self-review of my own code. - [ ] I have commented my code, particularly in hard-to-understand areas. *(N/A – docs only)* - [ ] I have added tests that prove my fix is effective or that my feature works. *(N/A – docs only)* - [ ] New and existing unit tests pass locally with my changes. *(N/A – docs only)* - [x] I have manually tested my changes end-to-end. - [ ] Any dependent changes have been merged and published in downstream modules. *(N/A)* COPYBARA_INTEGRATE_REVIEW=#3875 from krishna-dhulipalla:docs/fix-adk-run_async-example 83fc5b4 PiperOrigin-RevId: 842952362
1 parent b23deeb commit 4111f85

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

contributing/samples/human_in_loop/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This example demonstrates an agent using a long-running tool (`ask_for_approval`
1818
# Example: After external approval
1919
updated_tool_output_data = {
2020
"status": "approved",
21-
"ticket-id": ticket_id, # from original call
21+
"ticketId": ticket_id, # from original call
2222
# ... other relevant updated data
2323
}
2424

@@ -31,12 +31,13 @@ This example demonstrates an agent using a long-running tool (`ask_for_approval`
3131
)
3232

3333
# Send this back to the agent
34-
await runner.run_async(
34+
async for _ in runner.run_async(
3535
# ... session_id, user_id ...
3636
new_message=types.Content(
3737
parts=[updated_function_response_part], role="user"
3838
),
39-
)
39+
):
40+
pass # exhaust generator (or handle events)
4041
```
4142
6. **Agent Acts on Update**: The agent receives this message containing the `types.FunctionResponse` and, based on its instructions, proceeds with the next steps (e.g., calling another tool like `reimburse`).
4243

0 commit comments

Comments
 (0)