๊ฐ€์ž… ํ›„ ์ดˆ๋Œ€ ๋งํฌ๋ฅผ ๊ณต์œ ํ•˜๋ฉด ๋™์˜์ƒ ์žฌ์ƒ ๋ฐ ์ดˆ๋Œ€ ๋ณด์ƒ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
๊ฐ€์ž… May 2026
258 ํŒ”๋กœ์ž‰ ์ค‘    228 ํŒฌ
# Useful but Little-Known Features of ADK 2.0 ๐ŸŒ What if you could safely cancel a running agent mid-execution while preserving everything it has already accomplished? ADK 2.0's cancellation feature uses the AbortController/AbortSignal pattern to gracefully interrupt agent execution. The cancel signal propagates through Runner, LlmAgent, Models, and Tools, while committed events are preserved. ๐Ÿ“Œ Title: Cancelling Agent Execution ๐Ÿ”— URL: ๐Ÿงฉ Overview Agent cancellation follows the AbortController/AbortSignal pattern. When a signal is issued from an AbortController, it propagates through the stack: Runner โ†’ LlmAgent โ†’ Models โ†’ Tools. Crucially, events that have already been committed are preserved, and the process completes gracefully without throwing exceptions. AbortSignal.timeout() enables automatic timeout-based cancellation, and AbortSignal.any() lets you combine multiple signals. ๐Ÿ›  How to use it Create an AbortController and pass its signal to the Runner. ```python from adk import App, AbortController, AbortSignal app = App(agent=my_agent) # Manual cancellation controller = AbortController() task = "long task", signal=controller.signal) # Cancel when needed controller.abort() # Timeout-based auto-cancel (2 seconds) signal = AbortSignal.timeout(2000) result = await "time-limited task", signal=signal) # Combining multiple signals combined = AbortSignal.any([ AbortSignal.timeout(5000), user_cancel_signal ]) result = await "task", signal=combined) ``` ๐Ÿ— Building it into production ใƒปWire AbortController to user actions (cancel buttons) to enable UI-driven cancellation ใƒปUse AbortSignal.timeout() to cap maximum execution time for API calls and prevent resource waste ใƒปCombine user cancellation and timeout signals with AbortSignal.any() ใƒปDesign workflows to return partial results from committed events after cancellation ๐Ÿ’ก Use cases โฑ Set timeouts on LLM calls to auto-cancel when responses are slow ๐Ÿ–ฑ Instantly interrupt agent execution when a user clicks a cancel button in the UI ๐Ÿ”€ Run multiple agents in parallel and cancel all but the first to complete ๐Ÿ’ฐ Cut off LLM calls when a cost budget is reached โš ๏ธ Watch out Cancellation completes gracefully, meaning the agent does not stop the instant abort() is called. There may be a slight delay while the current operation (LLM inference, tool execution) finishes. Since committed events are preserved, design your workflows with cancellation points in mind to avoid inconsistent intermediate states. Implementing signal-aware early returns inside tools is also an effective practice. โœจ The cancellation feature gives you safe control over the agent execution lifecycle. Combined with timeouts, it dramatically improves predictability in production environments. #ADK# #AIAgent#
๋” ๋ณด๊ธฐ