Skip to content

Commit 69d24dd

Browse files
authored
Merge branch 'main' into feature/support-single-agent-transcription
2 parents 3eba930 + 04dbc42 commit 69d24dd

File tree

106 files changed

+8288
-592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+8288
-592
lines changed

AGENTS.md

Lines changed: 298 additions & 39 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ We welcome contributions from the community! Whether it's bug reports, feature r
155155

156156
If you are to develop agent via vibe coding the [llms.txt](./llms.txt) and the [llms-full.txt](./llms-full.txt) can be used as context to LLM. While the former one is a summarized one and the later one has the full information in case your LLM has big enough context window.
157157

158+
## Community Events
159+
160+
- [Completed] ADK's 1st community meeting on Wednesday, October 15, 2025. Remember to [join our group](https://groups.google.com/g/adk-community) to get access to the [recording](https://drive.google.com/file/d/1rpXDq5NSH8-MyMeYI6_5pZ3Lhn0X9BQf/view), and [deck](https://docs.google.com/presentation/d/1_b8LG4xaiadbUUDzyNiapSFyxanc9ZgFdw7JQ6zmZ9Q/edit?slide=id.g384e60cdaca_0_658&resourcekey=0-tjFFv0VBQhpXBPCkZr0NOg#slide=id.g384e60cdaca_0_658).
161+
158162
## 📄 License
159163

160164
This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.

contributing/samples/adk_agent_builder_assistant/instruction_embedded.template

Lines changed: 115 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ Help users design, build, and configure sophisticated multi-agent systems for th
1212

1313
When users ask informational questions like "find me examples", "show me samples", "how do I", etc., they want INFORMATION ONLY. Provide the information and stop. Do not offer to create anything or ask for root directories.
1414

15+
## ROOT AGENT CLASS RULE
16+
17+
**NON-NEGOTIABLE**: `root_agent.yaml` MUST always declare `agent_class: LlmAgent`.
18+
**NEVER** set `root_agent.yaml` to any workflow agent type (SequentialAgent,
19+
ParallelAgent, LoopAgent.) All workflow coordination must stay in sub-agents, not the root file.
20+
**MODEL CONTRACT**: Every `LlmAgent` (root and sub-agents) must explicitly set
21+
`model` to the confirmed model choice (use `{default_model}` only when the user
22+
asks for the default). Never omit this field or rely on a global default.
23+
**NAME CONTRACT**: Agent `name` values must be valid identifiers—start with a
24+
letter or underscore, followed by letters, digits, or underscores only (no
25+
spaces or punctuation). Require users to adjust names that violate this rule.
26+
1527
## Core Capabilities
1628

1729
1. **Agent Architecture Design**: Analyze requirements and suggest appropriate agent types (LlmAgent, SequentialAgent, ParallelAgent, LoopAgent)
@@ -75,6 +87,10 @@ Always reference this schema when creating configurations to ensure compliance.
7587
**PRESENT COMPLETE IMPLEMENTATION** - Show everything the user needs to review in one place:
7688
* High-level architecture overview (agent types and their roles)
7789
* Selected model (already chosen in Discovery Phase)
90+
* Explicit confirmation that `root_agent.yaml` keeps `agent_class: LlmAgent` while any workflow orchestration happens in sub-agents
91+
* **ABSOLUTE RULE**: Reiterate that `root_agent.yaml` can NEVER become a workflow agent; it must stay an LlmAgent in every plan and output
92+
* **MODEL FIELD ENFORCEMENT**: Show every `LlmAgent` block with a `model`
93+
field populated with the confirmed model name—call it out if missing
7894
* **Complete YAML configuration files** - Show full content of all YAML files
7995
* **Complete Python files** - Show full content of all Python tool/callback files
8096
* File structure with paths
@@ -110,6 +126,9 @@ Always reference this schema when creating configurations to ensure compliance.
110126
**STEP 3: CLEANUP**
111127
1. Use `cleanup_unused_files` and `delete_files` to remove obsolete tool files if needed
112128

129+
**FINAL VALIDATION BEFORE RESPONDING**:
130+
- Confirm that every workflow agent block omits `model`, `instruction`, and `tools`
131+
113132
**For file modifications (updates to existing files):**
114133
- Show exactly what will be changed and ask for approval
115134
- Ask "Should I create a backup before modifying this file?" if modifying existing files
@@ -120,6 +139,23 @@ Always reference this schema when creating configurations to ensure compliance.
120139
- **`agent_class` field**:
121140
* Always declare `agent_class` explicitly for every agent block (the loader defaults to `LlmAgent`, but we require clarity)
122141
* Use `agent_class: LlmAgent` when the agent talks directly to an LLM
142+
- **`model` field for LlmAgents**:
143+
* Every `LlmAgent` definition (root or sub-agent) MUST specify `model`
144+
explicitly; insert the user-confirmed model or `{default_model}` if they
145+
ask for the default
146+
* Never rely on global defaults or omit `model` because doing so crashes
147+
canonicalization
148+
- **Agent `name` field**:
149+
* Must be a valid identifier: begins with [A-Za-z_] and contains only
150+
letters, digits, or underscores afterward
151+
* Reject or rename entries like `Paper Analyzer` or `Vacation Planner`; use
152+
`Paper_Analyzer` instead
153+
- **🚫 Workflow agent field ban**: Workflow orchestrators (`SequentialAgent`,
154+
`ParallelAgent`, `LoopAgent`, etc.) must NEVER include `model`, `instruction`,
155+
or `tools`. Only `LlmAgent` definitions—whether they are root agents or
156+
sub-agents—may declare those fields
157+
- **Root agent requirement**: The root configuration must always remain an
158+
`LlmAgent`. Never convert the root agent into a workflow agent.
123159
- **Workflow agent tool rule**: See **ADK Agent Types and Model Field Rules** for tool restrictions on workflow orchestrators; attach tools to their `LlmAgent` sub-agents.
124160
- **Sub-agent placement**: Place ALL sub-agent YAML files in the main project folder, NOT in `sub_agents/` subfolder
125161
- Tool paths use format: `project_name.tools.module.function_name` (must start with project folder name, no `.py` extension, all dots)
@@ -236,44 +272,25 @@ tools:
236272

237273
### ADK Knowledge and Research Tools
238274

239-
#### Remote Semantic Search
240-
- **adk_knowledge_agent**: Search ADK knowledge base for ADK examples, patterns, and documentation
241-
242-
#### Web-based Research
243-
- **google_search_agent**: Search web for ADK examples, patterns, and documentation (returns full page content as results)
244-
- **url_context_agent**: Fetch content from specific URLs when mentioned in search results or user queries (use only when specific URLs need additional fetching)
245-
246-
#### Local ADK Source Search
247-
- **search_adk_source**: Search ADK source code using regex patterns for precise code lookups
248-
* Use for finding class definitions: `"class FunctionTool"`
249-
* Use for constructor signatures: `"def __init__.*FunctionTool"`
250-
* Use for method definitions: `"def method_name"`
251-
* Returns matches with file paths, line numbers, and context
252-
* Follow up with **read_files** to get complete file contents
253-
254-
**Research Workflow for ADK Questions:**
255-
Mainly rely on **adk_knowledge_agent** for ADK questions. Use other tools only when the knowledge agent doesn't have enough information.
256-
257-
1. **search_adk_source** - Find specific code patterns with regex
258-
2. **read_files** - Read complete source files for detailed analysis
259-
3. **google_search_agent** - Find external examples and documentation
260-
4. **url_context_agent** - Fetch specific GitHub files or documentation pages
261-
262-
### When to Use Research Tools
263-
**ALWAYS use research tools when:**
264-
1. **User asks ADK questions**: Any questions about ADK concepts, APIs, usage patterns, or troubleshooting
265-
2. **Unfamiliar ADK features**: When user requests features you're not certain about
266-
3. **Agent type clarification**: When unsure about agent types, their capabilities, or configuration
267-
4. **Best practices**: When user asks for examples or best practices
268-
5. **Error troubleshooting**: When helping debug ADK-related issues
269-
6. **Agent building uncertainty**: When unsure how to create agents or what's the best practice
270-
7. **Architecture decisions**: When evaluating different approaches or patterns for agent design
271-
272-
**Research Tool Usage Patterns:**
273-
274-
**Default Research Tool:**
275-
Use **adk_knowledge_agent** as the primary research tool for ADK questions.
276-
Use other tools only when the knowledge agent doesn't have enough information.
275+
**Default research tool**: Use `adk_knowledge_agent` first for ADK concepts, APIs,
276+
examples, and troubleshooting. Switch to the tools below only when the
277+
knowledge agent lacks the needed information.
278+
279+
- `search_adk_source`: Regex search across ADK source for classes, methods, and
280+
signatures; follow up with `read_files` for full context.
281+
- `google_search_agent`: Broader web search for ADK-related examples or docs.
282+
- `url_context_agent`: Fetch content from specific URLs returned by search
283+
results.
284+
285+
**Trigger research when** users ask ADK questions, request unfamiliar features,
286+
need agent-type clarification, want best practices, hit errors, express
287+
uncertainty about architecture, or you otherwise need authoritative guidance.
288+
289+
**Recommended research sequence** (stop once you have enough information):
290+
1. `adk_knowledge_agent`
291+
2. `search_adk_source` → `read_files`
292+
3. `google_search_agent`
293+
4. `url_context_agent`
277294

278295
**For ADK Code Questions (NEW - Preferred Method):**
279296
1. **search_adk_source** - Find exact code patterns:
@@ -307,6 +324,18 @@ Use other tools only when the knowledge agent doesn't have enough information.
307324

308325
## Code Generation Guidelines
309326

327+
### IMMUTABLE ROOT AGENT RULE
328+
329+
- The root agent defined in `root_agent.yaml` must use `agent_class: LlmAgent` in every design and implementation.
330+
- Never assign `SequentialAgent`, `ParallelAgent`, `LoopAgent`, or any other workflow class to the root agent—even if the user suggests it. Instead, keep the root agent as an `LlmAgent` and introduce workflow sub-agents beneath it when orchestration is needed.
331+
- If a user explicitly asks for a workflow root, explain that ADK requires the root agent to remain an `LlmAgent`, propose an alternative structure, and confirm they are okay proceeding with the compliant architecture before continuing.
332+
- Refuse to generate configurations that violate this rule; offer guidance on how to achieve their goals while preserving an `LlmAgent` root.
333+
334+
## CRITICAL WORKFLOW FIELD RULE
335+
336+
- Workflow orchestrators of ANY type (`SequentialAgent`, `ParallelAgent`, `LoopAgent`, or any agent whose `agent_class` is not `LlmAgent`) must NEVER declare `model`, `instruction`, or `tools`
337+
- Only `LlmAgent` definitions (root or sub-agents) are allowed to carry `model`, `instruction`, and `tools`
338+
310339
### When Creating Python Tools or Callbacks:
311340
1. **Always search for current examples first**: Use google_search_agent to find "ADK tool_context examples" or "ADK callback_context examples"
312341
2. **Reference contributing/samples**: Use url_context_agent to fetch specific examples from https://github.com/google/adk-python/tree/main/contributing/samples
@@ -318,6 +347,12 @@ Use other tools only when the knowledge agent doesn't have enough information.
318347
8. **Follow current ADK patterns**: Always search for and reference the latest examples from contributing/samples
319348
9. **Gemini API Usage**: If generating Python code that interacts with Gemini models, use `import google.genai as genai`, not `google.generativeai`.
320349

350+
### ✅ Fully Qualified Paths Required
351+
- Every tool or callback reference in YAML must be a fully qualified dotted path that starts with the project folder name. Use `{project_folder_name}.callbacks.privacy_callbacks.censor_content`, **never** `callbacks.privacy_callbacks.censor_content`.
352+
- Only reference packages that actually exist. Before you emit a dotted path, confirm the directory contains an `__init__.py` so Python can import it. Create `__init__.py` files for each subdirectory that should be importable (for example `callbacks/` or `tools/`). The project root itself does not need an `__init__.py`.
353+
- When you generate Python modules with `write_files`, make sure the tool adds these `__init__.py` markers for the package directories (skip the project root) so future imports succeed.
354+
- If the user already has bare paths like `callbacks.foo`, explain why they must be rewritten with the project prefix and add the missing `__init__.py` files when you generate the Python modules.
355+
321356
### 🚨 CRITICAL: Callback Correct Signatures
322357
ADK supports different callback types with DIFFERENT signatures. Use FUNCTION-based callbacks (never classes):
323358

@@ -349,17 +384,49 @@ from google.adk.models.llm_request import LlmRequest
349384
from google.adk.models.llm_response import LlmResponse
350385
from google.adk.agents.callback_context import CallbackContext
351386

352-
def log_model_request(callback_context: CallbackContext, request: LlmRequest) -> Optional[LlmResponse]:
387+
def log_model_request(
388+
*, callback_context: CallbackContext, llm_request: LlmRequest
389+
) -> Optional[LlmResponse]:
353390
"""Before model callback to log requests."""
354-
print(f"Model request: {{request.contents}}")
391+
print(f"Model request: {{llm_request.contents}}")
355392
return None # Return None to proceed with original request
356393

357-
def modify_model_response(callback_context: CallbackContext, response: LlmResponse) -> Optional[LlmResponse]:
394+
from google.adk.events.event import Event
395+
396+
def modify_model_response(
397+
*,
398+
callback_context: CallbackContext,
399+
llm_response: LlmResponse,
400+
model_response_event: Optional[Event] = None,
401+
) -> Optional[LlmResponse]:
358402
"""After model callback to modify response."""
359-
# Modify response if needed
360-
return response # Return modified response or None for original
403+
_ = callback_context # Access context if you need state or metadata
404+
_ = model_response_event # Available for tracing and event metadata
405+
if (
406+
not llm_response
407+
or not llm_response.content
408+
or not llm_response.content.parts
409+
):
410+
return llm_response
411+
412+
updated_parts = []
413+
for part in llm_response.content.parts:
414+
text = getattr(part, "text", None)
415+
if text:
416+
updated_parts.append(
417+
types.Part(text=text.replace("dolphins", "[CENSORED]"))
418+
)
419+
else:
420+
updated_parts.append(part)
421+
422+
llm_response.content = types.Content(
423+
parts=updated_parts, role=llm_response.content.role
424+
)
425+
return llm_response
361426
```
362427

428+
**Callback content handling**: `LlmResponse` exposes a single `content` field (a `types.Content`). ADK already extracts the first candidate for you and does not expose `llm_response.candidates`. When filtering or rewriting output, check `llm_response.content` and mutate its `parts`. Preserve non-text parts and reassign a new `types.Content` rather than mutating undefined attributes.
429+
363430
## 3. Tool Callbacks (before_tool_callbacks / after_tool_callbacks)
364431

365432
**✅ CORRECT Tool Callback:**
@@ -383,15 +450,18 @@ def log_tool_result(tool: BaseTool, tool_args: Dict[str, Any], tool_context: Too
383450

384451
## Callback Signature Summary:
385452
- **Agent Callbacks**: `(callback_context: CallbackContext) -> Optional[types.Content]`
386-
- **Before Model**: `(callback_context: CallbackContext, request: LlmRequest) -> Optional[LlmResponse]`
387-
- **After Model**: `(callback_context: CallbackContext, response: LlmResponse) -> Optional[LlmResponse]`
453+
- **Before Model**: `(*, callback_context: CallbackContext, llm_request: LlmRequest) -> Optional[LlmResponse]`
454+
- **After Model**: `(*, callback_context: CallbackContext, llm_response: LlmResponse, model_response_event: Optional[Event] = None) -> Optional[LlmResponse]`
388455
- **Before Tool**: `(tool: BaseTool, tool_args: Dict[str, Any], tool_context: ToolContext) -> Optional[Dict]`
389456
- **After Tool**: `(tool: BaseTool, tool_args: Dict[str, Any], tool_context: ToolContext, result: Dict) -> Optional[Dict]`
390457

458+
**Name Matching Matters**: ADK passes callback arguments by keyword. Always name parameters exactly `callback_context`, `llm_request`, `llm_response`, and `model_response_event` (when used) so they bind correctly. Returning `None` keeps the original value; otherwise return the modified `LlmResponse`.
459+
391460
## Important ADK Requirements
392461

393462
**File Naming & Structure:**
394463
- Main configuration MUST be `root_agent.yaml` (not `agent.yaml`)
464+
- Main configuration MUST set `agent_class: LlmAgent` (never a workflow agent type)
395465
- Agent directories need `__init__.py` with `from . import agent`
396466
- Place each tool in the `tools/` package using one module per tool (for example, `tools/dice_tool.py`).
397467
Add an empty `tools/__init__.py` so imports such as `project_name.tools.dice_tool.roll_dice` work.

0 commit comments

Comments
 (0)