# Practical and Useful Patterns with ADK
📄 What if you could define agents in YAML instead of code? ADK's Agent Config enables declarative agent definitions with environment-specific switching -- no redeployment needed for prompt or model changes!
📌 Title: Agent Config — Declarative, Code-Free Agent Definitions in YAML
🔗 URL:
🧩 Overview
Agent Config lets you build ADK workflows without writing code, using YAML files to define `name`, `model`, `description`, `instruction`, `tools`, and `sub_agents`. Create projects with `adk create --type=config`, then run with `adk web`, `adk run`, or `adk api_server`. For programmatic loading, use `config_agent_utils.from_config()` in Python. This separation of agent definition from code enables prompt changes, model swaps, and environment-specific configurations without redeployment.
🛠 Usage
A basic Agent Config YAML:
```yaml
# root_agent.yaml
name: assistant_agent
model: gemini-flash-latest
description: A helper agent that answers user questions.
instruction: |
You are an agent that answers various user questions.
Provide accurate and helpful responses.
tools:
- google_search
sub_agents:
- config_path: specialist_agent.yaml
```
Create and run a project:
```bash
# Create project
adk create --type=config my_agent
# Run options
adk web # Web interface
adk run # Terminal execution
adk api_server # API server mode
```
Load programmatically in Python:
Use `config_agent_utils.from_config()` from `google.adk.agents` to programmatically load an agent from a YAML file path (e.g., `"my_agent/root_agent.yaml"`).
🏗 Practical Patterns
**Environment-Specific Configuration**: Maintain separate YAML files for dev/staging/prod and select them via environment variables.
```yaml
# config/dev/root_agent.yaml
name: assistant_agent
model: gemini-flash-latest
instruction: |
[DEV] Include debug information in your responses.
# config/prod/root_agent.yaml
name: assistant_agent
model: gemini-2.5-pro
instruction: |
Answer user questions accurately and concisely.
```
Read the environment name with `os.getenv("ENVIRONMENT", "dev")` and dynamically load the corresponding YAML file via `config_agent_utils.from_config(f"config/{env}/root_agent.yaml")`.
**Prompt Versioning**: Track YAML files in Git for full prompt change history. Update instructions without code changes and roll back easily when needed.
**A/B Testing**: Prepare multiple YAML files with different instructions or models, and switch between them at runtime to compare performance.
Call `get_ab_variant(user_id)` to determine the A/B variant (`"a"` or `"b"`), then load the corresponding YAML file with `config_agent_utils.from_config(f"config/variant_{variant}.yaml")` for runtime A/B testing.
💡 Use Cases
🔄 Prompt and model changes without code modifications or redeployment
🌍 Per-environment configuration management (dev/staging/prod)
📊 A/B testing different instructions and models
📝 Git-tracked prompt versioning with easy rollback
🧩 Enabling non-engineers to update agent configurations safely
⚠️ Considerations
- Currently only Gemini models are supported. Other model providers are not yet available.
- Custom code tools are limited to Python and Java.
- `LangGraphAgent` and `A2aAgent` are not yet supported in Agent Config.
- API keys and project settings are managed via `.env` files -- be careful not to commit secrets.
✨ Agent Config separates agent definitions from code, enabling non-engineers to safely modify prompts and models while making environment switching and A/B testing straightforward. Use it to maximize operational flexibility!
#
ADK# #
AIAgent#