manager
agent_cover.manager
Main entry point for managing agent coverage instrumentation.
This module acts as the Controller of the library. It orchestrates the lifecycle of the coverage process, ensuring that all components (Registry, Config, Context, Instrumentors) are initialized in the correct order and wired together via Dependency Injection.
Classes
AgentCoverage
Lifecycle manager for the AgentCover system.
This class corresponds to a single test session. It orchestrates initialization, instrumentation, and cleanup.
Attributes:
| Name | Type | Description |
|---|---|---|
registry |
AgentRegistry
|
The storage for coverage data. |
config |
AgentCoverConfig
|
The loaded configuration. |
instrumentors |
List[BaseInstrumentor]
|
List of active instrumentors. |
Examples:
Using the Context Manager (Recommended):
This ensures that patches are applied at the start and safely removed at the end.
from agent_cover.manager import AgentCoverage
def main():
# Initialize coverage
with AgentCoverage() as coverage:
# ... Run your agent logic here ...
my_agent.invoke("Hello world")
# Access coverage data programmatically
print(f"Executions: {len(coverage.registry.executions)}")
# Patches are removed automatically here
Source code in src/agent_cover/manager.py
26 27 28 29 30 31 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 | |
Functions
__enter__()
__exit__(exc_type, exc_val, exc_tb)
__init__(registry=None, config=None, context_manager=None, analyzer=None, patch_manager=None)
Initializes the AgentCoverage manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Optional[AgentRegistry]
|
Optional custom registry. Defaults to a new AgentRegistry. |
None
|
config
|
Optional[AgentCoverConfig]
|
Optional custom config. Defaults to a new AgentCoverConfig. |
None
|
context_manager
|
Optional[AgentContextManager]
|
Optional custom context manager. Defaults to a new AgentContextManager. |
None
|
analyzer
|
Optional[OutputAnalyzer]
|
Optional custom output analyzer. Defaults to a new OutputAnalyzer. |
None
|
patch_manager
|
Optional[PatchManager]
|
Optional custom patch manager. Defaults to DefaultPatchManager. |
None
|
Source code in src/agent_cover/manager.py
start(importer_func=None, module_iterator=None, inspection_provider=None, targets_provider_map=None, version_checker=None, stack_walker=None)
Starts the instrumentation process.
This method initializes all necessary instrumentors. It supports dependency injection for various internal components to facilitate testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
importer_func
|
Optional[Callable[[str], Any]]
|
Optional function to import modules (for DI/testing). |
None
|
module_iterator
|
Optional[Callable[[], Dict[str, Any]]]
|
Optional function to iterate over modules (for DI/testing). |
None
|
inspection_provider
|
Optional[InspectionProvider]
|
Optional provider for code inspection (for DI/testing). |
None
|
targets_provider_map
|
Optional[Dict[str, Callable]]
|
Optional map for target providers (for DI/testing). |
None
|
version_checker
|
Optional[VersionChecker]
|
Optional version checker instance (for DI/testing). |
None
|
stack_walker
|
Optional[Callable[[Any], Iterator[Any]]]
|
Optional callable for walking the stack (for DI/testing). |
None
|
Source code in src/agent_cover/manager.py
stop()
Stops the instrumentation in an idempotent and safe manner.
This method reverts all applied patches by uninstrumenting the components in reverse order of their initialization.