feat: add HITL approval gateway for production ADK agent workflows#110
feat: add HITL approval gateway for production ADK agent workflows#110garythomasgeorge wants to merge 3 commits intogoogle:mainfrom
Conversation
- Add ADK 1.x adapter and data models - Add FastAPI backend and SQLite state management routes - Add Streamlit dashboard UI for human reviewers - Add sample credit_agent showcasing the full @hitl_tool integration - Fully formatted under pyink and isort conventions
|
@gemini-cli /review |
|
🤖 Hi @DeanChensj, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
Overall, this is a very solid and well-architected contribution. The decoupling of the HITL state from the agent session is a smart move for production resilience.
I've left a few minor comments regarding:
- Python 3.12+ deprecations (
utcnow). - Configurable API endpoints for production.
- Potential simplifications using Pydantic's built-in ORM support.
- Considerations for polling traffic.
Great work on the sample agent and the Streamlit dashboard as well!
- Replace datetime.utcnow() with datetime.now(timezone.utc) throughout (deprecated in Python 3.12+) - Make API_BASE_URL configurable via ADK_HITL_API_URL env var - Make poll interval configurable via ADK_HITL_POLL_INTERVAL_S env var - Add jitter to polling loop to reduce backend traffic under concurrent load - Simplify _to_pydantic() using Pydantic v2 model_validate() with from_attributes=True and a model_validator to handle JSON strings - Update test_approved_tool_runs assertion to match enriched return dict (action_result + supervisor_decision) - Add README.md with architecture diagram, quick start, and configuration reference
|
@DeanChensj — addressed all four points from the automated review in the latest commit. 38/39 tests passing — the one remaining failure (test_session_state_management) is pre-existing in the Redis session service and fails on main as well [attach screenshot]. Ready for human review when you have a chance. |

Summary
Closes #111
Adds a production-ready Human-in-the-Loop approval gateway for Google ADK agents. This addresses a documented gap where ADK's built-in Tool Confirmation feature explicitly does not support
DatabaseSessionServiceorVertexAiSessionService— the two session backends required for production deployments — making structured human oversight unavailable in any persistent production environment.Problem
ADK's Tool Confirmation (v1.14.0+) is experimental and has three blockers for production use:
DatabaseSessionServiceorVertexAiSessionServiceAgentToolor across A2A boundariesValidated by community issues: #1797, #1851, #2645, #3276, #3567 on
google/adk-python.Solution
A session-agnostic HITL approval gateway that manages approval state in its own persistence layer (SQLite, with a documented path to Postgres), independent of ADK's session service. The agent resumes via ADK's standard REST API after a human decision is submitted.
What's included
Core module (
src/google/adk_community/tools/hitl/)gateway.py—hitl_tooldecorator that wraps any async function before it is passed toFunctionTool. Adding HITL to an existing tool takes ~5 lines.models.py—ApprovalRequestPydantic model, normalised data contract capturing agent context, payload, risk level, and audit metadataadapters/adk1.py— ADK 1.x adapter translatingrequest_confirmation()events intoApprovalRequestobjectsService (
src/google/adk_community/services/hitl_approval/)api.py— FastAPI applicationroutes.py— REST endpoints for approval queue managementstore.py— SQLite persistence with full audit logSample (
contributing/samples/hitl_approval/)credit_agent/agent.py— Credit approval agent demonstrating end-to-end integrationdashboard/app.py— Reference Streamlit approval inbox UIstart_servers.sh— One-command startup for all three servicesrequirements.txt— Sample-only dependenciesArchitecture
Forward compatibility
Built with an adapter pattern so the same approval backend and dashboard work with ADK 1.x today and ADK 2.0's
RequestInputpattern when it reaches stable — without teams needing to rebuild their approval layer on upgrade.Testing
Unit tests
All 11 tests passing:
Manual E2E
Full end-to-end flow verified:
ADK_HITL.Demo.webm
Testing plan
For reviewers wanting to reproduce locally:
cd contributing/samples/hitl_approval uv pip install -r requirements.txt ./start_servers.shThen open:
http://localhost:8080http://localhost:8501http://localhost:8000/docsTrigger an approval by asking the credit agent to process an amount over $500.
Notes for reviewers
adapters/adk2.py) is planned as a follow-up PR once 2.0 moves toward stabletools/hitlfor the gateway and models,services/hitl_approvalfor the FastAPI backend — let me know if you'd prefer a different organisationRelated