Adk reflection
adk_reflection ¶
ADK-based reflection function factory.
This module provides the factory function for creating reflection functions that use Google ADK agents. The returned function can be passed to AsyncReflectiveMutationProposer as the adk_reflection_fn parameter.
Terminology
- component_text: The current text content of a component being evolved
- trial: One performance record {feedback, trajectory}
- feedback: Critic evaluation {score, feedback_text, feedback_*} (stochastic)
- trajectory: Execution record {input, output, trace} (deterministic)
- trials: Collection of trial records for reflection
- proposed_component_text: The improved text for the same component
| ATTRIBUTE | DESCRIPTION |
|---|---|
create_adk_reflection_fn | Factory that creates a ReflectionFn using an ADK LlmAgent for reflection. The returned function produces TYPE: |
Examples:
Create a reflection function with custom agent:
from google.adk.agents import LlmAgent
from gepa_adk.engine.adk_reflection import create_adk_reflection_fn
from gepa_adk.adapters.execution.agent_executor import AgentExecutor
agent = LlmAgent(
name="reflector",
model="gemini-2.5-flash",
instruction="Improve: {component_text}\nTrials: {trials}",
)
executor = AgentExecutor()
reflection_fn = create_adk_reflection_fn(agent, executor=executor)
See Also
gepa_adk.engine.proposer: Proposer that uses reflection functions.
create_adk_reflection_fn ¶
create_adk_reflection_fn(
reflection_agent: Any,
executor: AgentExecutorProtocol,
output_key: str = "proposed_component_text",
) -> ReflectionFn
Create a reflection function from an ADK LlmAgent.
This factory function creates an async callable that uses the Google ADK framework for reflection. The returned function can be passed to AsyncReflectiveMutationProposer as the adk_reflection_fn parameter.
The caller is responsible for selecting the appropriate reflection agent. See gepa_adk.api.evolve() for the standard wiring pattern.
| PARAMETER | DESCRIPTION |
|---|---|
reflection_agent | ADK LlmAgent configured with instruction containing TYPE: |
executor | AgentExecutorProtocol implementation for unified agent execution. Handles session management and execution, enabling feature parity across all agent types. TYPE: |
output_key | Key in session state where ADK stores the agent's output. Defaults to "proposed_component_text". When set, the agent's output_key is configured to this value, and output is retrieved from session state after execution. Falls back to event-based extraction if the output_key is not found in session state. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
ReflectionFn | Async callable matching ReflectionFn signature that generates proposed |
ReflectionFn | component text via the ADK agent. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError | If ADK agent execution fails (propagated from executor). |
Examples:
Basic usage with executor:
from google.adk.agents import LlmAgent
from gepa_adk.adapters.execution.agent_executor import AgentExecutor
from gepa_adk.engine.adk_reflection import create_adk_reflection_fn
agent = LlmAgent(
name="InstructionReflector",
model="gemini-2.5-flash",
instruction="""Improve this component text:
{component_text}
Based on these trials:
{trials}
Return proposed component text only."""
)
executor = AgentExecutor()
reflection_fn = create_adk_reflection_fn(agent, executor=executor)
trials = [{"input": "Hi", "output": "Hey", "feedback": {"score": 0.5}}]
proposed = await reflection_fn("Be helpful", trials, "instruction")
See Also
gepa_adk.engine.proposer: Module containing ReflectionFn type alias and AsyncReflectiveMutationProposer class.gepa_adk.api.evolve: Standard wiring pattern for constructing the reflection chain.
Note
Opens a fresh ADK session for each invocation via AgentExecutor, ensuring complete isolation between reflection operations. State is initialized with component_text (str) and trials (JSON-serialized list of trial records).
Source code in src/gepa_adk/engine/adk_reflection.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |