chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
# Workflow Loop Config Sample
|
||||
|
||||
## Overview
|
||||
|
||||
This sample demonstrates how to define a workflow with a feedback loop using a YAML configuration file. It mirrors the `workflow_samples/loop` sample, but uses YAML to define the workflow structure instead of Python.
|
||||
|
||||
## Sample Inputs
|
||||
|
||||
- `Python programming`
|
||||
|
||||
- `Baking cookies`
|
||||
|
||||
## Graph
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
START --> process_input[process_input]
|
||||
process_input --> generate_headline[generate_headline.yaml]
|
||||
generate_headline --> evaluate_headline[evaluate_headline.yaml]
|
||||
evaluate_headline --> route_headline[route_headline]
|
||||
route_headline -->|unrelated| generate_headline
|
||||
```
|
||||
|
||||
## How To
|
||||
|
||||
This sample uses some special syntax in `root_agent.yaml` to support dynamic resolution and graph construction:
|
||||
|
||||
### 1. `_code` Suffix
|
||||
|
||||
Fields ending with `_code` (like `output_schema_code` in `evaluate_headline.yaml`) tell the ADK YAML mapper to resolve the value as a Python code reference rather than treating it as a plain string.
|
||||
|
||||
- If it starts with `.`, it resolves relative to the current agent directory's Python package path.
|
||||
- Example: `output_schema_code: .agent.Feedback` resolves to the `Feedback` Pydantic model in `agent.py` in the same directory.
|
||||
|
||||
### 2. Function References in Edges
|
||||
|
||||
If a string in the edge list does not end with `.yaml` and is not `'START'`, it is treated as a function reference.
|
||||
|
||||
- If it starts with `.`, it resolves relative to the current agent directory's Python package path.
|
||||
- Example: `.agent.process_input` resolves to the `process_input` function in `agent.py`.
|
||||
- It automatically creates a `FunctionNode` with the function's name as the node name.
|
||||
|
||||
### 3. External Agent Files
|
||||
|
||||
Agents can be defined in their own YAML files and referenced by filename in the edges list.
|
||||
|
||||
- Example: `generate_headline.yaml` references the agent defined in that file.
|
||||
- The mapper caches resolved nodes by their string value, so using the same filename in multiple edges correctly reuses the same agent instance, preserving the graph structure (e.g. for loops).
|
||||
@@ -0,0 +1,43 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from google.adk import Event
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
|
||||
|
||||
class Feedback(BaseModel):
|
||||
grade: Literal["tech-related", "unrelated"] = Field(
|
||||
description=(
|
||||
"Decide if the headline is related to technology or software"
|
||||
" engineering."
|
||||
)
|
||||
)
|
||||
feedback: str = Field(
|
||||
description=(
|
||||
"If the headline is unrelated to technology, provide feedback on how"
|
||||
" to make it more tech-focused."
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def process_input(node_input: str):
|
||||
"""Puts user input in the state."""
|
||||
return Event(state={"topic": node_input})
|
||||
|
||||
|
||||
def route_headline(node_input: Feedback):
|
||||
return Event(route=node_input.grade)
|
||||
@@ -0,0 +1,20 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
agent_class: LlmAgent
|
||||
name: evaluate_headline
|
||||
instruction: |
|
||||
Grade whether the headline is related to technology or software engineering.
|
||||
output_schema_code: .agent.Feedback
|
||||
output_key: feedback
|
||||
@@ -0,0 +1,20 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
agent_class: LlmAgent
|
||||
name: generate_headline
|
||||
instruction: |
|
||||
Write a headline about the topic "{topic}".
|
||||
If feedback is provided, take it into account.
|
||||
The feedback: {feedback?}
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
agent_class: Workflow
|
||||
name: loop_workflow
|
||||
edges:
|
||||
- - START
|
||||
- .agent.process_input
|
||||
- generate_headline.yaml
|
||||
- evaluate_headline.yaml
|
||||
- .agent.route_headline
|
||||
- - .agent.route_headline
|
||||
- unrelated: generate_headline.yaml
|
||||
Reference in New Issue
Block a user