跳到正文
DEV Community· Casper Nielsen·· 2 小時前AI 評分54

Google ADK 智能體要可靠恢復,還需要崩潰偵測機制

A Durable Google ADK Agent Needs Something to Notice the Crash

AI 導讀

Google ADK 的事件歷史可以重播已完成的工具結果,但不會自行偵測程序崩潰或重新啟動任務。把 Agent 放入 Dapr workflow 後,工具呼叫會作為 workflow activity 執行,工作流程日誌會記錄各活動的輸入、輸出及狀態。程序中斷後,工作流程會在健康副本上從最後完成的活動恢復,並避免多個副本同時處理同一任務。

正文

Google ADK goes further on durability than most agent frameworks. Every interaction – user message, LLM response, tool call, tool result, state change – is recorded as an immutable Event. Turn on ResumabilityConfig(is_resumable=True), re-invoke with the original invocation_id, and completed tool results come back from the event history. Only the tool that failed runs again.

The gap is in who starts that replay.

Four minutes in, then a pod eviction
An ADK agent is four minutes into a three-tool task. Two tools have finished and their results are in the event history. The third has started. Then the pod gets evicted, and when it comes back, nothing happens.

Nothing inside ADK notices the crash. From outside, an agent that finished, an agent waiting on a slow tool and an agent whose process was killed look the same. The caller has to work out which one it's looking at and re-invoke with the right ID. If you run several replicas, there's a second problem: ADK has no coordination layer across them, so without external locking two runners can pick up the same task.

What a durable ADK agent needs
I'd list three things. A record of completed steps, which ADK already has. Something that notices a dead run and restarts it without a person or a cron job doing the detecting. And exactly one worker owning each run at a time.

The last two are runtime jobs. You can build them next to ADK – a watcher, a lock, a re-invoke path – or run the agent on something that already does them.

Moving recovery into the runtime

pip install "diagrid[adk]"
dapr init
from google.adk.agents import LlmAgent
from google.adk.tools import FunctionTool
from diagrid.agent.adk import DaprWorkflowAgentRunner

def book_venue(city: str) -> str:
    return f"Venue held in {city}"

def order_catering(headcount: int) -> str:
    return f"Catering ordered for {headcount}"

def send_invites(city: str) -> str:
    return f"Invites sent for {city}"

agent = LlmAgent(
    name="event_planner",
    model="gemini-2.5-flash",
    tools=[FunctionTool(book_venue), FunctionTool(order_catering), FunctionTool(send_invites)],
    instruction="Plan an event by calling the three tools in sequence.",
)

runner = DaprWorkflowAgentRunner(name="event-planner", agent=agent, max_iterations=10)
runner.start()
out = runner.run_sync(user_message="Plan a 40-person meetup in Copenhagen", session_id="cph-meetup")
print(out.final_response)
runner.shutdown()

Run it with dapr run --app-id event-planner -- python planner.py. The agent definition is plain ADK, so it moves over unchanged.

Each tool call now executes as a Dapr workflow activity, and the workflow log stores the activity's input, output and status, separately from ADK's event history. If the process dies, a durable reminder fires because the activity didn't complete, the workflow reactivates on a healthy replica, and it resumes from the last completed activity. Recovery goes through the workflow log instead of ADK's invocation_id replay path, so no caller has to detect anything or remember an ID.

A workflow instance also has a single ID and runs in one place at a time, which takes care of two replicas grabbing the same task.

Where I'd start
Pick the ADK agent with the longest runs, since it has the most finished work to lose, and check who re-invokes it today when a pod goes away. If nobody does, that agent is the first one to wrap. The Google ADK page goes through recovery in more detail: https://www.diagrid.io/learn/google-adk-durable-execution

來源:DEV Community · dev.to