a308848969
Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 962282749
Node as Tool
Overview
Demonstrates wrapping both a regular ADK Node (using the @node decorator) and a Workflow as tools that can be automatically called by a parent Agent.
It also demonstrates how a node-based tool can pause execution for Human-in-the-Loop (HITL) input using RequestInput and resume dynamically.
In this sample:
- The parent agent receives an inquiry about a customer's discount.
- It invokes
customer_lookup_workflow(aWorkflowwrapped as a tool) to retrieve customer status. - It then invokes
calculate_discount(a regularNodewrapped as a tool) using the retrieved status. - If the customer is a VIP,
calculate_discountyields aRequestInputevent to ask for confirmation. The invocation pauses and is resumed once the user provides input.
Sample Inputs
-
What discount does customer c123 get?This is a multi-turn interaction demonstrating Human-in-the-Loop:
- Turn 1: The parent agent invokes
customer_lookup_workflowto verify status, then invokescalculate_discount.calculate_discountyields aRequestInputasking "Apply VIP discount for tier 'Verified VIP Member'?", which pauses the run. - Turn 2: Respond with
yesto resume the run. It calculates the "20% off" discount, and the parent agent summarizes the results.
- Turn 1: The parent agent invokes
Agent Topology Graph
graph TD
customer_service_agent[customer_service_agent] -->|calls| customer_lookup_workflow(customer_lookup_workflow)
customer_service_agent -->|calls| calculate_discount(calculate_discount)
How To
To expose an existing Node or Workflow as a tool callable by an Agent:
- Define your
Node(or@node) orWorkflowand assign both aninput_schemaand adescription. - Pass the node/workflow directly into your parent agent's
toolslist:Agent(..., tools=[my_node, my_workflow]).
Related Guides
- Workflow - Explains building complex multi-step graphs.