feat(samples): Add backend blocking poll pattern for HITL workflows#3224
feat(samples): Add backend blocking poll pattern for HITL workflows#3224jpantsjoha wants to merge 1 commit intogoogle:mainfrom
Conversation
63a01c3 to
411d3c4
Compare
|
Hi @jpantsjoha, Thank you for your contribution! |
b68a62a to
33e9027
Compare
|
✅ Merge conflicts resolved! Hi @DeanChensj and @ryanaiagent, I've successfully resolved the merge conflicts that were blocking this PR. Here's what was completed: 🔧 Conflict Resolution Summary
📝 Changes IntegratedThe conflicts arose because this PR included enhanced error messages that have since been refactored into a shared utility function ( ✅ Status
The PR is now ready for your review. Thank you for your patience during the conflict resolution process! Note: The core HITL blocking poll pattern functionality remains unchanged - only the error message handling has been updated to align with the latest main branch. |
33e9027 to
b82668a
Compare
|
Hi team, just checking in on this. The merge conflicts were resolved on Nov 24. Is there anything else needed for review? |
Implements backend blocking poll pattern as an alternative to LongRunningFunctionTool for human-in-the-loop approval workflows. Pattern Benefits: - Simpler integration (no FunctionResponse injection) - Seamless UX (agent waits automatically) - 93% reduction in LLM API calls vs agent-level polling - Works with poll-only systems (Jira, ServiceNow, dashboards) Implementation: - Synchronous version for standalone agents - Asynchronous version for production multi-agent systems - Mock approval API with HTML dashboard for testing - Comprehensive test suite (20 tests, 100% pass rate) - Decision matrix comparing with LongRunningFunctionTool Addresses: - google#3184: Parent agent pause bug (directly solved) - google#1797: HITL event support (alternative for poll-only systems) Production Validated: - Tested in multi-agent RFQ approval system - 10-minute average approval duration handled gracefully - No manual intervention required
06bc838 to
0f40d41
Compare
|
Hi @ryanaiagent @DeanChensj @Jacksunwei, Rebased against latest Quick recap of what this PR adds:
Issues addressed:
Key benefit: 93% reduction in LLM API calls vs agent-level polling, with no This has been open since October — would really appreciate a review when you get a chance. Happy to make any changes needed. Thanks! |
Summary
This PR adds a backend blocking poll pattern for human-in-the-loop (HITL) approval workflows as an alternative to the existing
LongRunningFunctionToolpattern.Pattern Overview
The backend blocking poll pattern handles polling internally within the tool, allowing the agent to call the approval tool once and receive the final decision without manual intervention.
Key Benefits:
FunctionResponseinjection requiredGitHub Issues Addressed
This pattern directly addresses:
Issue #3184: Parent agent doesn't pause properly for sub-agent approvals
Direct Solution: This pattern eliminates the need for parent agents to pause and resume. The approval tool blocks internally while polling, and the agent naturally waits for the final decision.
Issue #1797: Need HITL event support
Alternative Provided: For systems that don't support webhooks (poll-only systems like Jira, ServiceNow), this pattern provides a simple alternative to webhook-based
LongRunningFunctionTool.Files Added
All files in
contributing/samples/human_in_loop_blocking_poll/:Core Implementation
blocking_poll_approval_example.py- Synchronous version (standalone agents, low concurrency)blocking_poll_approval_example_async.py- Asynchronous version (production, high concurrency)Testing Infrastructure
mock_approval_api.py- FastAPI-based mock approval server with HTML dashboardtest_standalone.py- Standalone sync integration test (no ADK dependencies)test_standalone_async.py- Standalone async integration testtest_blocking_poll_core.py- Unit tests with pytest (12 tests)Documentation
README.md- Comprehensive documentation (359 lines) including:Test Results
100% Pass Rate (20 tests total):
Integration Tests
Unit Tests
All tests validated locally before submission.
Production Validation
This pattern has been validated in a production multi-agent RFQ approval system:
Real-World Use Case:
When to Use This Pattern
✅ Use Backend Blocking Poll When:
FunctionResponsemanagement)Design Decisions
Why Async + Sync Versions?
Why Mock API?
Provides complete testing infrastructure without external dependencies, allowing developers to validate the pattern locally.
Why Comprehensive Documentation?
The 359-line README includes:
LongRunningFunctionToolto clarify differencesChecklist
Reviewer Notes
This contribution complements the existing
human_in_loopsample by providing an alternative pattern for poll-only systems. It does not replaceLongRunningFunctionToolbut offers a simpler option when webhooks are not available.Related Samples:
contributing/samples/human_in_loop/- Existing LongRunningFunctionTool patterncontributing/samples/a2a_human_in_loop/- A2A human-in-the-loop exampleProduction Impact: