Module 10 Lesson 3: Configuration-Driven Agents
Separating logic from code. Using YAML and JSON to define agent personas, tools, and constraints.
Configuration-Driven Agents: No-Code Identity
The biggest shift when moving to an ADK mindset is that you stop writing Python code to define an agent. Instead, you write a Configuration File (usually YAML).
This allows you to change the agent's behavior to "Update" its internal logic without re-deploying your entire application.
1. The Anatomy of an Agent Config
A typical configuration file includes the "Identity" of the agent separate from the "Execution Logic."
# agent_researcher.yaml
name: "Market Analyst"
version: "2.1"
model:
provider: "openai"
model_id: "gpt-4o"
temperature: 0.1
persona:
role: "Senior Research Specialist"
backstory: "You specialize in technical documentation and fact-checking."
capabilities:
- tool: "web_search"
max_calls_per_run: 5
- tool: "calculator"
constraints:
- "Never share confidential PII"
- "Always cite sources in APA style"
2. Why Configuration is Superior to Code
A. Hot Loading
If your manager wants the agent to be "Friendlier," you just change the YAML and refresh the server. You don't need to rebuild the Docker container or run a new CI/CD pipeline.
B. Security Auditing
A security officer can read a YAML file. They cannot (easily) read through 1,000 lines of Python with nested function calls. By putting the Persona and Tools in a config, you make the agent's behavior transparent.
C. Prompt Injection Prevention
When the prompt is hard-coded in Python, it's easier to accidentally mix user input with system instructions. In a config-driven world, the System Prompt is a protected variable that is combined with user input through a strictly controlled "Template."
3. Visualizing the Config Pipeline
graph LR
YAML[YAML Config] --> Parser[ADK Parser]
Parser --> Validator[Schema Checker]
Validator --> Agent[Live Agent Instance]
App[Main Python App] -->|ID: Researcher| Agent
4. Environment-Specific Configs
You can use different configs for different stages:
researcher.dev.yaml: Uses a cheap, local Llama 3 model.researcher.prod.yaml: Uses a high-quality GPT-4o model with strict cost limits.
5. Code Example: Loading the Config
import yaml
from adk import AgentFactory
def start_agent():
# Load the definition from the file
with open("researcher.yaml", "r") as f:
config = yaml.safe_load(f)
# Create the agent based on the config
my_agent = AgentFactory.create(config)
return my_agent.run("Who is the CEO of Apple?")
Key Takeaways
- YAML definitions make agents "Portable" and "Auditable."
- Separation of concerns: Parameters (Temp, Model) belong in config, not code.
- Hot-swapping allows for rapid iteration of agent behavior.
- Configuration schemas ensure that every agent in the company follows the same structure.