Index
agent_cover.instrumentation.llm_providers
LLM Provider Instrumentation (Data Coverage).
This module intercepts the final calls to External APIs (LLMs) to verify Decision Coverage.
🔗 Architectural Relationships
Unlike other instrumentors that track Code Coverage (was this line run?), this module feeds the Verification Layer.
- Feeds: OutputAnalyzer (Sends generated text for analysis).
- Validates against: AgentCoverConfig (Checks if output matches expected
decisions). - Configured by: targets.py (Defines API methods like
openai.create).
⚙️ How it works
It wraps the synchronous and asynchronous API calls to LLM providers. It does not alter the response returned to your application, but "siphons" a copy of the text to the Analyzer.
Usage
from agent_cover.instrumentation.llm_providers import instrument_llm_providers
instrument_llm_providers()
Classes
LLMProviderInstrumentor
Bases: BaseInstrumentor
Instrumentor that sits at the edge of the system (External APIs).
Unlike other instrumentors that track code coverage, this tracks Data Coverage. It intercepts the raw string response from the LLM to analyze if business logic requirements (Decisions) were met.
Attributes:
| Name | Type | Description |
|---|---|---|
registry |
Optional[AgentRegistry]
|
The registry for agent components. |
analyzer |
OutputAnalyzer
|
The component responsible for analyzing extracted text. |
importer_func |
Callable
|
Function used to import modules dynamically. |
module_iterator |
Callable
|
Function that returns the current mapping of loaded modules. |
targets_provider |
Callable
|
Function that returns a list of targets to instrument. |
extractors |
List[PayloadExtractor]
|
List of strategies used to parse LLM results. |
is_instrumented |
bool
|
Flag indicating if instrumentation has already run. |
Methods:
| Name | Description |
|---|---|
instrument |
Performs the actual patching of target methods. |
_resolve_target |
helper to find the specific object/method to patch. |
_create_wrapper |
Creates the closure that wraps the original method. |
_delegate_extraction |
Iterates through extractors to parse the result. |
Source code in src/agent_cover/instrumentation/llm_providers/patcher.py
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
Functions
__init__(registry=None, analyzer=None, patch_manager=None, importer_func=None, module_iterator=None, targets_provider=None, extractors=None)
Initializes the LLMProviderInstrumentor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Optional[AgentRegistry]
|
The registry instance. |
None
|
analyzer
|
Optional[OutputAnalyzer]
|
Custom analyzer instance. |
None
|
patch_manager
|
Optional[PatchManager]
|
The patch manager for safe patching. |
None
|
importer_func
|
Optional[Callable]
|
Custom import function. |
None
|
module_iterator
|
Optional[Callable]
|
Custom module iterator provider (for dependency injection). |
None
|
targets_provider
|
Optional[Callable]
|
Custom provider for patch targets. |
None
|
extractors
|
Optional[List[PayloadExtractor]]
|
Custom list of payload extractors. |
None
|
Source code in src/agent_cover/instrumentation/llm_providers/patcher.py
instrument()
Applies patches to the defined LLM provider targets.
This method iterates through the targets provided by targets_provider.
It loads the necessary modules (using a snapshot to allow for test isolation)
and wraps the specified methods/functions to enable output analysis.
Source code in src/agent_cover/instrumentation/llm_providers/patcher.py
Functions
instrument_llm_providers()
Convenience function to instantiate and run the instrumentor.
Returns:
| Name | Type | Description |
|---|---|---|
LLMProviderInstrumentor |
LLMProviderInstrumentor
|
The initialized and executed instrumentor instance. |