登録して招待リンクを共有すると、動画再生報酬と紹介報酬を獲得できます。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
参加 May 2026
258 フォロー中    228 ファン
# 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#
もっと見る