registry
agent_cover.registry
Agent Registry Module.
This module defines the AgentRegistry, which serves as the central state store (Single Source of Truth) for the entire coverage session.
🔗 Architectural Relationships
The Registry acts as the data synchronization bridge between the Static Analysis phase and the Runtime Instrumentation phase.
-
Static Definitions (What should be tested): Populated by Scanners like scan_raw_string_prompts, scan_pydantic_models, and scan_promptflow_definitions.
-
Runtime Executions (What was touched): Populated by Instrumentors like ToolInstrumentor and PromptInstrumentor.
-
Decision Verification (Business Logic): Populated by the OutputAnalyzer, which maps LLM outputs to DecisionConfig rules.
Classes
AgentRegistry
Central storage mechanism for agent coverage data.
This singleton-like class holds the state of the coverage session. It uses a Canonical ID system to link static code definitions (found by parsing files) with runtime objects (intercepted during execution).
Attributes:
| Name | Type | Description |
|---|---|---|
definitions |
Dict[str, Dict[str, Any]]
|
A map of static definitions found
in the codebase. Keys are canonical IDs (e.g., |
executions |
Set[str]
|
A set of canonical IDs that were executed during the test run. Presence in this set implies "covered". |
decision_hits |
Dict[str, Set[str]]
|
Tracks business logic validation. Maps a Decision ID (from config) to a set of observed values found in the agent's output. |
content_map |
Dict[str, str]
|
Maps MD5 hashes of content (like prompt templates) to their canonical IDs. This handles cases where runtime objects don't have file location metadata but have identical content to static files. |
on_hit_callback |
Optional[Callable]
|
A callback function triggered whenever a new execution or decision hit is recorded. Used for immediate data flushing in multiprocess environments. |
Examples:
Checking coverage programmatically:
from agent_cover.registry import get_registry
registry = get_registry()
# Check if a specific tool was used
tool_id = "src/tools.py:TOOL:search_google"
if tool_id in registry.executions:
print("Tool was used!")
# Check decision coverage
hits = registry.decision_hits.get("intent_classification", set())
print(f"Observed intents: {hits}")
Source code in src/agent_cover/registry.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 | |
Functions
__init__()
Initializes a new AgentRegistry instance.
Source code in src/agent_cover/registry.py
clear()
Clears all stored data in the registry.
This method resets the registry to its initial state, removing all definitions, executions, and decision hits. It is essential for cleanup and preventing data contamination between test runs or instrumentation sessions.
Source code in src/agent_cover/registry.py
get_canonical_id(content_str, current_id)
Retrieves or registers a canonical ID for a given content string.
This method is essential for mapping runtime objects (which might not have filename info) back to statically scanned files based on content hashing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_str
|
str
|
The string content (e.g., prompt template text) to hash. |
required |
current_id
|
str
|
The fallback ID to use if this content hasn't been seen before. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The existing canonical ID if the content matches a known definition, |
str
|
otherwise returns |
Source code in src/agent_cover/registry.py
merge(other_data)
Merges coverage data from an external fragment into the current registry.
This is used by the CLI aggregator to consolidate results from multiple worker processes into a single source of truth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_data
|
Dict[str, Any]
|
A dictionary containing 'executions', 'decision_hits', and 'definitions' keys. |
required |
Source code in src/agent_cover/registry.py
register_content_map(content_str, known_id)
Registers a mapping between the content hash and the canonical ID.
This method computes the MD5 hash of the given content string and associates it with the provided known ID. This allows for efficient lookup and ensures uniqueness based on content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_str
|
str
|
The string content to hash. |
required |
known_id
|
str
|
The canonical ID to associate with the content hash. |
required |
Source code in src/agent_cover/registry.py
register_decision_hit(decision_id, value)
Registers an observed value for a specific business decision rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decision_id
|
str
|
The ID of the decision rule from configuration. |
required |
value
|
Any
|
The value observed during runtime (will be cast to string). |
required |
Source code in src/agent_cover/registry.py
register_definition(key, kind, metadata)
Registers or updates a definition in the registry.
This method adds a new definition to the registry, associating it with a unique key. If the key exists, the definition is updated with the new metadata, merging it with existing data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The unique key for the definition. |
required |
kind
|
str
|
The type/kind of the definition (e.g., "PROMPT", "TOOL"). |
required |
metadata
|
Dict[str, Any]
|
A dictionary containing the metadata for the definition. |
required |
Source code in src/agent_cover/registry.py
register_execution(key)
Registers an execution in the registry.
If the key is new, it adds it to the set of executed items and triggers the synchronization callback if configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The unique identifier of the executed component. |
required |
Source code in src/agent_cover/registry.py
reset()
Resets the registry.
This method is an alias for the clear() method, providing a
convenient way to reset the registry.
Functions
get_registry()
Retrieves the global AgentRegistry instance.
This function provides a global access point to the AgentRegistry, ensuring a single instance is used throughout the application.
Returns:
| Type | Description |
|---|---|
AgentRegistry
|
The global AgentRegistry instance. |