Register and share your invite link to earn from video plays and referrals.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
Joined May 2026
258 Following    228 Followers
# Practical and Useful Patterns with ADK โšก Turn Python functions into tools, wrap agents as tools, and run long tasks without blocking โ€” ADK's Function Tools maximize flexibility in tool definitions. ๐Ÿ“Œ Title: Function Tools โ€” Functions, Agents, and Async Tasks as Tools ๐Ÿ”— URL: ๐Ÿงฉ Overview ADK's Function Tools let you use Python/TypeScript functions directly as agent tools. AgentTool wraps an entire agent as a tool accessible to other agents. Long Running Function Tools handle time-consuming tasks like video encoding and batch jobs without blocking the agent's execution flow. ๐Ÿ›  Usage Basic function tool definitions and AgentTool usage. Import `Agent` and `AgentTool` from `google.adk`. Define a simple function tool `calculate_price` that takes `base_price` (float), `quantity` (int), and `discount_percent` (float, default 0), computes the total with the discount applied, and returns a dict with `total` and `currency`. For wrapping an agent as a tool, create an `analysis_agent` with `name="data_analyst"` and `tools=[query_database]`. Then define `main_agent` with `tools=[calculate_price, AgentTool(agent=analysis_agent)]`, allowing the main agent to call both the pricing function and the data analysis agent as tools. Using Long Running Function Tools. Import `LongRunningFunctionTool` from `google.adk`. Define an async function `encode_video` that takes `video_url` (str) and `format` (str, default "mp4"), starts an encoding job via `start_encoding_job`, and returns the job ID with a processing status. Wrap it with `LongRunningFunctionTool(func=encode_video)` to create `video_tool`, then pass it to an `Agent`'s `tools` list so the agent can trigger long-running tasks without blocking. ๐Ÿ— Practical Patterns **Modularization with AgentTool**: Encapsulate complex logic as specialized agents and expose them via AgentTool. This keeps the main agent's instructions simple while each specialist agent maintains its own tools and prompts -- achieving clean separation of concerns. Define a `summarizer` agent (for 3-line summaries) and a `translator` agent (for Japanese translation) as separate `Agent` instances. Then create a `content_manager` agent with `tools=[AgentTool(agent=summarizer), AgentTool(agent=translator)]`, allowing the main agent to invoke these specialists as tools for content management tasks. **When to Use Long Running Tools**: Ideal for batch processing, external API polling, file conversion โ€” anything taking seconds to minutes. The agent receives a job ID and can proceed with other tasks in parallel. **Type Annotations Matter**: Clear parameter types and return types help the LLM call tools accurately. Docstrings serve as tool descriptions, so keep them concise and clear. ๐Ÿ’ก Use Cases ๐Ÿงฎ Calculation and conversion functions as tools (pricing, unit conversion) ๐Ÿค– Reusable specialist agents via AgentTool ๐ŸŽฌ Async video encoding and image processing ๐Ÿ“Š Non-blocking batch data processing โš ๏ธ Caveats - Function docstrings become tool descriptions. Write LLM-friendly descriptions โ€” missing docstrings make tool purposes unclear. - Agents called via AgentTool run in a separate session from the parent. Be careful about state sharing. - Long Running Function Tools require a separate completion notification mechanism. Consider polling or webhook-based notifications. โœจ Function Tools let you integrate existing code assets directly into agents, and AgentTool enables seamless agent reuse. A massive boost to development productivity! #ADK# #AIAgent#
Show more