# Useful but Little-Known Features of ADK 2.0
๐ What if your agent's prompts could improve themselves automatically, instead of requiring manual tuning?
ADK 2.0's optimization feature combines samplers and agent optimizers to automatically refine your agent's instructions based on evaluation results.
๐ Title: Optimization
๐ URL:
๐งฉ Overview
The optimization feature consists of two components: Samplers (which evaluate candidates) and Agent Optimizers (which improve instructions). `LocalEvalSampler` runs candidate agents against evaluation datasets and computes scores. Two optimizers are available: `GEPARootAgentPromptOptimizer`, which uses the GEPA algorithm to optimize the root agent's prompt, and `SimplePromptOptimizer`, which iterates through an execute-evaluate-critique-rewrite cycle. Results are returned as an `OptimizerResult` containing optimized agents with their scores.
๐ How to use it
Run optimization from the CLI with `adk optimize`.
```python
import asyncio
from google.adk.evaluation.eval_config import EvalConfig
from google.adk.evaluation.local_eval_sets_manager import LocalEvalSetsManager
from google.adk.optimization.local_eval_sampler import LocalEvalSampler
from google.adk.optimization.local_eval_sampler import LocalEvalSamplerConfig
from google.adk.optimization.simple_prompt_optimizer import SimplePromptOptimizer
from google.adk.optimization.simple_prompt_optimizer import (
SimplePromptOptimizerConfig,
)
# Set up the sampler
sampler_config = LocalEvalSamplerConfig(
eval_config=EvalConfig(criteria={"response_match_score": 0.75}),
app_name="my_agent",
train_eval_set="train_eval_set",
)
sampler = LocalEvalSampler(sampler_config, LocalEvalSetsManager(agents_dir="."))
# Run optimization
optimizer = SimplePromptOptimizer(config=SimplePromptOptimizerConfig())
result = sampler))
# Get the optimized agent and score
best = result.optimized_agents[0]
best_agent = best.optimized_agent
print(f"Score: {best.overall_score}")
```
๐ Building it into production
ใปRun optimization periodically as evaluation datasets evolve, keeping prompts continuously refined
ใปUse `SimplePromptOptimizer` for quick iterations and `GEPARootAgentPromptOptimizer` for thorough exploration
ใปCompare pre- and post-optimization scores and only update prompts when improvement is confirmed
ใปBuild evaluation datasets from real user interactions for practical optimization
๐ก Use cases
๐ Automatically improve agent prompts based on evaluation scores
๐ฌ Systematically compare multiple prompt candidates and select the best one
๐ Re-optimize prompts after model changes or API specification updates
๐ฏ Fine-tune prompts for specific tasks like code generation, summarization, or classification
โ ๏ธ Watch out
`GEPARootAgentPromptOptimizer` only optimizes the root agent's prompt. It does not cover sub-agent prompts, so optimize those separately if needed. Also, optimization requires multiple evaluation runs, so keep an eye on LLM API call costs.
โจ With optimization, you can move from trial-and-error prompt tuning to data-driven automation. Set up regular optimization cycles to continuously raise your agent's quality bar.
#
ADK# #
AIAgent#