Agent provider
agent_provider ¶
Protocol definition for agent loading and persistence.
This module defines the AgentProvider protocol that enables custom agent loading and persistence for gepa-adk. Implementations provide agent configuration storage and retrieval, enabling the evolution system to load agents and persist evolved instructions.
| ATTRIBUTE | DESCRIPTION |
|---|---|
AgentProvider | Protocol for loading and persisting agents. TYPE: |
Examples:
Implement a minimal in-memory provider:
from google.adk.agents import LlmAgent
from gepa_adk.ports import AgentProvider
class InMemoryProvider:
def __init__(self):
self._agents = {}
def get_agent(self, name: str) -> LlmAgent:
if not name:
raise ValueError("Agent name cannot be empty")
if name not in self._agents:
raise KeyError(f"Agent not found: {name}")
return self._agents[name]
def save_instruction(self, name: str, instruction: str) -> None:
if not name:
raise ValueError("Agent name cannot be empty")
if name not in self._agents:
raise KeyError(f"Agent not found: {name}")
self._agents[name].instruction = instruction
def list_agents(self) -> list[str]:
return list(self._agents.keys())
Use the provider:
provider = InMemoryProvider()
agent = provider.get_agent("my_agent")
provider.save_instruction("my_agent", "New instruction")
Note
The protocol uses sync methods for simplicity. Implementations that need async can use async internally and block in sync methods, or provide async wrappers. The protocol itself does not perform I/O; implementations handle storage operations.
AgentProvider ¶
Bases: Protocol
flowchart TD
gepa_adk.ports.agent_provider.AgentProvider[AgentProvider]
click gepa_adk.ports.agent_provider.AgentProvider href "" "gepa_adk.ports.agent_provider.AgentProvider"
Protocol for loading and persisting agents.
Implementations provide agent configuration storage and retrieval, enabling the evolution system to load agents and persist evolved instructions.
Examples:
Implement a minimal in-memory provider:
class InMemoryProvider:
def __init__(self):
self._agents = {}
def get_agent(self, name: str) -> LlmAgent:
if not name:
raise ValueError("Agent name cannot be empty")
if name not in self._agents:
raise KeyError(f"Agent not found: {name}")
return self._agents[name]
def save_instruction(self, name: str, instruction: str) -> None:
if not name:
raise ValueError("Agent name cannot be empty")
if name not in self._agents:
raise KeyError(f"Agent not found: {name}")
self._agents[name].instruction = instruction
def list_agents(self) -> list[str]:
return list(self._agents.keys())
Verify protocol compliance:
from gepa_adk.ports import AgentProvider
provider = InMemoryProvider()
assert isinstance(provider, AgentProvider) # Runtime check works
Note
All implementations must provide get_agent(), save_instruction(), and list_agents() methods. Use @runtime_checkable to enable isinstance() checks for protocol compliance.
Source code in src/gepa_adk/ports/agent_provider.py
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 | |
get_agent ¶
Load an agent by its unique name.
| PARAMETER | DESCRIPTION |
|---|---|
name | The unique identifier for the agent. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
'LlmAgent' | The configured LlmAgent instance ready for use. |
| RAISES | DESCRIPTION |
|---|---|
KeyError | If no agent with the given name exists. |
ValueError | If name is empty or invalid. |
Examples:
Load a named agent:
Note
Only non-empty names are accepted. Configured agents ready for use with the evolution system should be returned.
Source code in src/gepa_adk/ports/agent_provider.py
save_instruction ¶
Persist an evolved instruction for a named agent.
| PARAMETER | DESCRIPTION |
|---|---|
name | The unique identifier for the agent. TYPE: |
instruction | The new instruction text to persist. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
KeyError | If no agent with the given name exists. |
ValueError | If name is empty or invalid. |
IOError | If persistence fails (implementation-specific). |
Examples:
Save an evolved instruction:
Note
Only after successful persistence should subsequent calls to get_agent() return an agent with the updated instruction. Implementations should validate empty names before processing.
Source code in src/gepa_adk/ports/agent_provider.py
list_agents ¶
List all available agent names.
| RETURNS | DESCRIPTION |
|---|---|
list[str] | A list of agent name strings. Empty list if no agents. |
Examples:
Discover available agents:
Note
Ordering of returned names is not guaranteed by the protocol. Some implementations may return names in a specific order, but callers should not rely upon any particular sequence.