google-adk-agent-patterns
Define, compose, and wire Google ADK agents with function tools and multi-agent orchestration. Use when writing agent definitions, adding Python function tools, building pipelines with SequentialAgent/LoopAgent/ParallelAgent, or designing router/delegation patterns. Trigger on: adk agent, LlmAgent, SequentialAgent, LoopAgent, ParallelAgent, AgentTool, function tool, output_key, output_schema, agent routing.
- License 许可
- Unlicense
- 所属仓库
- saski/arnesto
- 最近更新
- 2026-11-12
- Stars
- ★ 6
- Forks
- 0
01 前言 Front Matter
- name
- google-adk-agent-patterns
- description
- Define, compose, and wire Google ADK agents with function tools and multi-agent orchestration. Use when writing agent definitions, adding Python function tools, building pipelines with SequentialAgent/LoopAgent/ParallelAgent, or designing router/delegation patterns. Trigger on: adk agent, LlmAgent, SequentialAgent, LoopAgent, ParallelAgent, AgentTool, function tool, output_key, output_schema, agent routing.
02 资源文件 2
- 参考文档references/multi-agent-patterns.md3.7 KB
- 参考文档references/tool-patterns.md1.8 KB
03 SKILL.md 正文
Google ADK Agent Patterns
When to Use / When Not to Use
Use this skill when:
- Defining or modifying an
Agent(LlmAgent) with model, instructions, or tools. - Writing Python function tools registered in
tools=[...]. - Composing multi-agent pipelines (sequential, loop, parallel, router).
- Passing state between agents using
output_key/{var}injection.
Do not use this skill when:
- Setting up a new ADK project from scratch (use
google-adk-setup). - Deploying to Cloud Run (covered in
google-adk-setupreferences).
Agent Configuration (LlmAgent / Agent)
from google.adk.agents.llm_agent import Agent
root_agent = Agent(
name="my_agent",
model="gemini-2.5-flash",
description="One-sentence description used by other agents for routing.",
instruction="You are a helpful assistant. Answer: {topic?}",
tools=[my_tool],
)
Key parameters:
| Parameter | Purpose |
|---|---|
name |
Unique identifier for the agent |
model |
Gemini model string (e.g. gemini-2.5-flash) |
description |
Used by orchestrators for routing — be precise |
instruction |
System prompt; supports {var} (required) and {var?} (optional) state injection |
tools |
List of Python functions or AgentTool instances |
output_schema |
Pydantic model for structured output |
output_key |
Writes agent output to shared session state under this key |
include_contents |
Controls which conversation history is passed |
generate_content_config |
Fine-grained generation parameters |
Critical constraint: output_schema and tools cannot both be set on most models. Choose one.
Function Tools
See references/tool-patterns.md for full examples.
Minimal function tool
def get_weather(city: str) -> dict:
"""Return current weather for the given city name.
Args:
city: The city name to look up.
"""
return {"status": "success", "temperature_c": 22}
agent = Agent(model="gemini-2.5-flash", name="weather_agent", tools=[get_weather])
Rules for function tools
- The docstring is the tool description the LLM reads — write it precisely.
- Always return a
dictwith a"status"key:"success","error", or"pending". - Non-dict returns are auto-wrapped as
{"result": value}. - Minimize parameters; use only simple, serializable types.
*argsand**kwargsare ignored in schema generation — never use them.- Long-running operations: wrap with
LongRunningFunctionTool(func=my_func).
Multi-Agent Patterns
See references/multi-agent-patterns.md for full examples.
SequentialAgent (pipeline)
from google.adk.agents import SequentialAgent
pipeline = SequentialAgent(
name="research_pipeline",
sub_agents=[researcher, writer, reviewer],
)
- Each agent runs in order.
- Use
output_key="my_key"on an agent to write its result to shared state. - Downstream agents read it via
{my_key}in theirinstruction.
LoopAgent (iterative refinement)
from google.adk.agents import LoopAgent
loop = LoopAgent(
name="refinement_loop",
sub_agents=[drafter, critic],
max_iterations=5,
)
- Runs sub-agents repeatedly until a termination condition is met.
ParallelAgent (concurrent)
from google.adk.agents import ParallelAgent
parallel = ParallelAgent(
name="parallel_research",
sub_agents=[topic_a_agent, topic_b_agent],
)
- Runs all sub-agents concurrently; results aggregate into shared session state.
AgentTool (delegation)
from google.adk.agents import AgentTool
dispatcher = Agent(
name="dispatcher",
model="gemini-2.5-flash",
tools=[AgentTool(agent=specialist)],
)
- Wraps an agent as a callable tool for the parent agent.
- The
descriptionon the wrapped agent controls when it is invoked.
State Injection in Instructions
# Required variable (errors if missing from state)
instruction = "Summarize this text: {raw_text}"
# Optional variable (silently ignored if missing)
instruction = "Context: {context?}\n\nAnswer the user's question."
State is populated by prior agents' output_key values or session initialization.
04 同仓库更多 Skills
visualize
Use /visualize for creating compact charts, diagrams, or other visuals inline as part of the conversation itself. It chooses among Markdown tables, Mermaid, inline HTML, and other supported in-transcript forms. Use Canvas for durable artifacts outside the transcript that users may revisit, refine, or share.
update-cursor-settings
Modify Cursor/VSCode user settings in settings.json. Use when you want to change editor settings, preferences, configuration, themes, font size, tab size, format on save, auto save, keybindings, or any settings.json values.
update-cli-config
View and modify Cursor CLI configuration settings in ~/.cursor/cli-config.json. Use when the user wants to change CLI settings, configure permissions, switch approval mode, enable vim mode, toggle display options, configure sandbox, or manage any CLI preferences.
statusline
Configure a custom status line in the CLI. Use when the user mentions status line, statusline, statusLine, CLI status bar, prompt footer customization, or wants to add session context above the prompt.
split-to-prs
Split current work into small reviewable PRs. Use when the user asks to split a chat, set of changes, branch, or PR.
shell
Runs the rest of a /shell request as a literal shell command. Use only when the user explicitly invokes /shell and wants the following text executed directly in the terminal.