Agents
agents ¶
Agent factory sub-package for ADK reflection agents.
Provides factory functions and a registry for creating component-aware reflection agents. Each factory returns an ADK LlmAgent configured with appropriate instructions and validation tools for a specific component type.
| ATTRIBUTE | DESCRIPTION |
|---|---|
create_text_reflection_agent | Factory for text reflection agents. TYPE: |
create_schema_reflection_agent | Factory for schema reflection agents. TYPE: |
create_config_reflection_agent | Factory for config reflection agents. TYPE: |
get_reflection_agent | Auto-selects agent based on component name. TYPE: |
component_registry | Default global registry. |
Examples:
from gepa_adk.adapters.agents import get_reflection_agent
agent = get_reflection_agent("output_schema", "gemini-2.5-flash")
See Also
reflection_agents: Full module documentation.
component_registry module-attribute ¶
component_registry = ComponentReflectionRegistry()
Default component reflection registry.
Pre-configured with: - output_schema → create_schema_reflection_agent - generate_content_config → create_config_reflection_agent - Default fallback → create_text_reflection_agent
Use this registry or create your own for custom configuration.
ComponentReflectionRegistry ¶
Registry mapping component names to reflection agent factories.
Enables automatic selection of the appropriate reflection agent based on component type, with support for custom validator registration.
The registry uses exact string matching for component names. Unknown components fall back to the default text reflection agent.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_factories | Component-to-factory map. TYPE: |
_default_factory | Fallback factory for unknown components. TYPE: |
Examples:
Register custom factory:
from gepa_adk.adapters.agents.reflection_agents import (
ComponentReflectionRegistry,
)
from google.adk.agents import LlmAgent
registry = ComponentReflectionRegistry()
def custom_factory(model: str) -> LlmAgent:
return LlmAgent(
name="custom_reflector",
model=model,
instruction="Custom: {component_text}",
)
registry.register("my_component", custom_factory)
agent = registry.get_agent("my_component", "gemini-2.5-flash")
See Also
get_reflection_agent: Convenience function using default registry.
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
__init__ ¶
Initialize empty registry with default text factory.
register ¶
register(
component_name: str, factory: ReflectionAgentFactory
) -> None
Register a factory for a component name.
| PARAMETER | DESCRIPTION |
|---|---|
component_name | Component name to register (e.g., "output_schema"). Uses exact match - no pattern matching for MVP. TYPE: |
factory | Factory function that takes model name and returns LlmAgent. TYPE: |
Examples:
Register schema factory:
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
get_factory ¶
get_factory(component_name: str) -> ReflectionAgentFactory
Get factory for a component name.
| PARAMETER | DESCRIPTION |
|---|---|
component_name | Component name to look up. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
ReflectionAgentFactory | Registered factory if found, otherwise default text factory. |
Examples:
Get factory:
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
get_agent ¶
Create a reflection agent for a component.
Convenience method that gets the factory and invokes it.
| PARAMETER | DESCRIPTION |
|---|---|
component_name | Component name. TYPE: |
model | Model name/identifier. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
LlmAgent | Configured LlmAgent for the component type. |
Examples:
Get agent directly:
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
create_config_reflection_agent ¶
Create a reflection agent for generate_content_config components.
Creates an LlmAgent configured for LLM generation configuration reflection. The agent receives parameter guidelines and valid ranges to help propose optimal configurations based on trial results.
| PARAMETER | DESCRIPTION |
|---|---|
model | Model name/identifier (e.g., "gemini-2.5-flash"). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
LlmAgent | Configured LlmAgent with config reflection instruction. |
Examples:
Create agent for config reflection:
from gepa_adk.adapters.agents.reflection_agents import (
create_config_reflection_agent,
)
agent = create_config_reflection_agent(model="gemini-2.5-flash")
# Agent has:
# - name="config_reflector"
# - instruction with parameter guidelines
# - output_key="proposed_component_text"
# - No tools (validation happens in handler)
See Also
CONFIG_REFL: Config instruction template.
Note
The agent does not use validation tools because config validation is built into the GenerateContentConfigHandler.apply() method. Invalid configs are gracefully rejected there.
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
create_schema_reflection_agent ¶
Create a reflection agent for output_schema components.
Creates an LlmAgent configured with: - Schema-focused reflection instruction - validate_output_schema tool for self-validation - Explicit instruction to use validation tool before returning
This agent can validate proposed Pydantic schemas before returning them, reducing wasted evolution iterations on invalid syntax.
| PARAMETER | DESCRIPTION |
|---|---|
model | Model name/identifier (e.g., "gemini-2.5-flash"). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
LlmAgent | Configured LlmAgent with schema validation tool. |
Examples:
Create agent for schema reflection:
from gepa_adk.adapters.agents.reflection_agents import (
create_schema_reflection_agent,
)
agent = create_schema_reflection_agent(model="gemini-2.5-flash")
# Agent has:
# - name="schema_reflector"
# - tools=[FunctionTool(validate_output_schema)]
# - instruction with validation guidance
# - output_key="proposed_component_text"
See Also
SCHEMA_REFL: Schema instruction template.validate_output_schema: Validation tool function.
Note
The agent uses output_key for text output extraction, not output_schema. This avoids ADK's limitation where tools and output_schema cannot be used together. The agent returns plain text (the Pydantic class definition).
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
create_text_reflection_agent ¶
Create a reflection agent for text components.
Creates an LlmAgent configured for free-form text reflection with no validation tools. Suitable for instructions, descriptions, and other text components that don't require structured validation.
| PARAMETER | DESCRIPTION |
|---|---|
model | Model name/identifier (e.g., "gemini-2.5-flash"). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
LlmAgent | Configured LlmAgent with text reflection instruction and no tools. |
Examples:
Create agent for instruction reflection:
from gepa_adk.adapters.agents.reflection_agents import (
create_text_reflection_agent,
)
agent = create_text_reflection_agent(model="gemini-2.5-flash")
# Agent has:
# - name="text_reflector"
# - instruction with {component_text} and {trials} placeholders
# - output_key="proposed_component_text"
# - No tools
See Also
REFLECTION_INSTRUCTION: Default instruction template.
Source code in src/gepa_adk/adapters/agents/reflection_agents.py
get_reflection_agent ¶
Get appropriate reflection agent for a component.
Convenience function that uses the global registry to create an agent based on component name. Falls back to text reflection for unknown components.
| PARAMETER | DESCRIPTION |
|---|---|
component_name | Component being evolved (e.g., "output_schema"). TYPE: |
model | Model name/identifier. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
LlmAgent | Configured LlmAgent for the component type. |
Examples:
Auto-select agent:
from gepa_adk.adapters.agents.reflection_agents import get_reflection_agent
# Returns schema agent with validation tool
schema_agent = get_reflection_agent("output_schema", "gemini-2.5-flash")
# Returns text agent without tools
text_agent = get_reflection_agent("instruction", "gemini-2.5-flash")
# Unknown components get text agent (fallback)
fallback_agent = get_reflection_agent("custom", "gemini-2.5-flash")
See Also
component_registry: Default registry.