新增現有的代理程式步驟

您可以將現有的 AI 代理新增為工作流程中的步驟,將工作轉移給專責代理。您可以編寫多代理工作流程,在不同代理之間自動調度,每個代理負責處理較大流程的特定部分。

事前準備

使用這項功能前,請先完成下列步驟:

  • 請確認 Gemini Enterprise 管理員已在應用程式的功能管理設定中,啟用 Workflow Builder 功能切換鈕。詳情請參閱「管理網頁應用程式功能」一文。
  • 確認要新增的代理程式可在貴機構中使用。 這項功能支援新增下列代理程式:

新增現有的代理程式步驟

應用程式

  1. 在瀏覽器中開啟 Gemini Enterprise 網頁應用程式。
  2. 前往現有代理程式,或建立新的代理程式
  3. 在流程建構工具中,按一下「新增步驟」
  4. 在「新增步驟」面板中,按一下「現有代理程式」展開該區段。
  5. 瀏覽可用代理程式清單。

  6. 按一下要新增的代理人。

    系統會將現有的代理程式步驟新增至工作流程。選取的代理程式會做為工作流程的一部分執行,接收先前步驟的輸入內容,並將輸出內容傳遞至後續步驟。

  7. 在畫布中,按一下現有的代理程式步驟,開啟設定面板,然後設定下列項目:

    • 提示:輸入用於觸發代理的提示或指令。你可以加入靜態文字,或參照先前步驟的輸出內容 (例如 ${step_name.output})。

代理程式步驟是所選代理程式的動態參照。如果來源代理程式更新或發布新版本,工作流程會自動使用最新版本。

如要進一步瞭解這項功能的限制,請參閱「已知問題和限制」。

釐清問題的運作方式

現有代理程式在工作流程中執行時,如果需要缺少資訊才能完成工作,可以暫停執行並向使用者提出釐清問題。當參照的代理發出 input-required 信號 (A2A) 或 RequestInput 事件 (ADK) 時,系統會原生支援釐清問題。

現有代理程式步驟執行時需要額外資訊:

  1. 暫停執行:工作流程會在現有的代理步驟暫停執行,並啟動人機迴圈 (HITL) 提示。
  2. 使用者回答提示:Gemini Enterprise 網頁應用程式會向使用者顯示 Agent 的釐清問題,以及輸入回覆的文字欄位。
  3. 繼續執行:使用者提交答案後,工作流程會繼續執行現有代理程式,並將使用者的答案傳回給代理程式。
  4. 多輪支援:代理可以在多輪對話中連續提出多個釐清問題,直到收集所有必要資訊並產生最終輸出內容為止。

內容隔離

在釐清問題的過程中,所參照的代理程式只會收到與使用者的互動記錄,以及為節點設定的初始提示。除非在步驟的提示中明確參照,否則工作流程中其他步驟的輸出內容和變數不會自動傳遞至參照的代理程式。

在虛擬服務專員中實作釐清問題

如要支援釐清問題,請將自訂代理程式設定為在需要額外資訊時,發出通訊協定層級的要求輸入信號。

A2A 代理 (原生)

如果代理程式直接實作 Agent2Agent (A2A) 通訊協定,請傳回 input-required 狀態的 task,並提供 TaskUpdater,在訊息酬載中提供釐清問題:

from a2a.server.tasks import TaskUpdater
from a2a.types import Message, Part, Role, TextPart

# Inside your custom agent's task executor class:
async def execute(self, context, event_queue):
    updater = TaskUpdater(event_queue, context.task_id, context.context_id)
    if context.current_task is None:
        await updater.submit()
    await updater.start_work()

    user_input = context.get_user_input()
    if "weather" in user_input and "tokyo" not in user_input.lower():
        await updater.requires_input(
            Message(
                message_id=f"q-{context.task_id}",
                role=Role.agent,
                parts=[Part(root=TextPart(
                    text="Which city would you like the weather for?"))],
                task_id=context.task_id,
                context_id=context.context_id,
            )
        )
        return

    await updater.complete(
        Message(
            message_id=f"a-{context.task_id}",
            role=Role.agent,
            parts=[Part(root=TextPart(
                text="It is sunny and 72°F in Tokyo."))],
            task_id=context.task_id,
            context_id=context.context_id,
        )
    )

系統會將使用者的回覆以 message/send 要求的形式傳回給代理程式,並使用相同的 taskId

A2A 代理 (使用 ADK 建構)

如果您的代理是使用 Agent Development Kit (ADK) 建構,並透過 A2A (使用 to_a2a()) 公開,請將問題詢問函式包裝在 LongRunningFunctionTool 中:

from google.adk.agents import Agent
from google.adk.tools.long_running_tool import LongRunningFunctionTool
from google.adk.a2a.utils.agent_to_a2a import to_a2a

def get_weather(city: str) -> str:
    """Returns weather information for a city."""
    return f"It is sunny and 72°F in {city}."

def ask_clarifying_question(question: str) -> None:
    """Asks the user a question and waits for their reply."""
    return None

root_agent = Agent(
    model="gemini-2.5-flash",
    name="weather_agent",
    instruction=(
        "If the user asks for weather without specifying a city, call "
        "`ask_clarifying_question` and wait. Do not guess."
    ),
    tools=[get_weather, LongRunningFunctionTool(ask_clarifying_question)],
)

a2a_app = to_a2a(root_agent, port=8000)

Agent Engine 中的 ADK 代理

如要為 Agent Engine 上的 reasoning-engine-hosted ADK 代理,在產生器工具或自訂代理步驟中發出 RequestInput 事件:

from google.adk.events import RequestInput

# Inside a generator tool or custom agent step
def ask_for_details():
    """Requests user input during tool or step execution."""
    yield RequestInput(
        interrupt_id="weather_city",
        message="Which city would you like the weather for?",
    )

後續步驟