Index
agent_cover.instrumentation.promptflow
Microsoft PromptFlow Integration.
This module provides specialized support for the PromptFlow ecosystem.
🔗 Architectural Relationships
PromptFlow is unique because it defines logic in YAML files (flow.dag.yaml) pointing to external assets.
It operates as a Context-Agnostic system because the execution of a flow implies an active agent context.
- Scans: File System (via scan_promptflow_definitions) to find
.jinja2templates referenced in DAGs. - Patches: PromptFlow Runtime (
render_jinja_templateand@tool). - Writes to: AgentRegistry (Using
FILE:prefixes for Jinja templates andTOOL:for python nodes). - Feeds: OutputAnalyzer (Also inspects tool outputs for decision coverage).
⚙️ How it works
The instrumentation works in two phases to link static files to runtime execution without explicit context tracking:
- Static Phase: Parses
flow.dag.yaml. Finds nodes of typeprompt. Registers the associated Jinja file content hash as a coverage target. - Runtime Phase: Patches the internal
render_jinja_template. When executed, we hash the template content and match it back to the ID registered in phase 1.
Usage
from agent_cover.instrumentation.promptflow import (
scan_promptflow_definitions,
instrument_promptflow
)
# 1. Register static assets
scan_promptflow_definitions()
# 2. Track execution
instrument_promptflow()
Classes
PromptFlowInstrumentor
Bases: BaseInstrumentor
Instruments Microsoft PromptFlow components.
PromptFlow defines flows using a mix of YAML configuration (flow.dag.yaml),
Python tools (@tool), and Jinja2 templates. This instrumentor applies patches
to track:
- Template Rendering: Patches internal render functions to track when a Jinja template is used.
- Tool Execution: Wraps the
@tooldecorator to track when a node in the flow is executed.
It works in tandem with scan_promptflow_definitions
which statically registers the files found in the DAG.
Attributes:
| Name | Type | Description |
|---|---|---|
analyzer |
OutputAnalyzer
|
The analyzer used to process execution results. |
targets_provider |
Callable
|
A function that returns a list of targets to instrument. |
registry |
AgentRegistry
|
The registry where execution data is stored. |
patch_manager |
PatchManager
|
Manager for applying and reverting patches. |
module_iterator |
Callable
|
Function to retrieve current sys.modules. |
importer_func |
Callable
|
Function to import modules dynamically. |
is_instrumented |
bool
|
Flag indicating if instrumentation has already run. |
Methods:
| Name | Description |
|---|---|
instrument |
Applies patches to the target PromptFlow modules. |
Source code in src/agent_cover/instrumentation/promptflow/patcher.py
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 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 298 299 300 301 302 | |
Functions
__init__(registry=None, analyzer=None, patch_manager=None, module_iterator=None, importer_func=None, targets_provider=None)
Initializes the PromptFlowInstrumentor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Optional[AgentRegistry]
|
The agent registry instance. |
None
|
analyzer
|
Optional[OutputAnalyzer]
|
Optional output analyzer instance. |
None
|
patch_manager
|
Optional[PatchManager]
|
Optional patch manager instance. |
None
|
module_iterator
|
Optional[Callable[[], Dict[str, Any]]]
|
Optional callable to get current modules. |
None
|
importer_func
|
Optional[Callable[[str], Any]]
|
Optional callable to import modules. |
None
|
targets_provider
|
Optional[Callable[[], TargetList]]
|
Optional callable to provide instrumentation targets. |
None
|
Source code in src/agent_cover/instrumentation/promptflow/patcher.py
instrument()
Applies runtime patches to PromptFlow's core modules.
It targets:
- promptflow.tools.common.render_jinja_template: To catch prompt usage.
- promptflow.core.tool: To catch python tool usage.
Note
This method is fault-tolerant; if PromptFlow is not installed, it simply skips instrumentation without raising errors.
Source code in src/agent_cover/instrumentation/promptflow/patcher.py
Functions
instrument_promptflow(registry=None)
Legacy helper function to instantiate and run the instrumentor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Optional[AgentRegistry]
|
Optional AgentRegistry instance. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PromptFlowInstrumentor |
The instrumentor instance. |
Source code in src/agent_cover/instrumentation/promptflow/patcher.py
scan_promptflow_definitions(root_path=None, registry=None, walker_func=None, file_reader=None)
Scans for PromptFlow YAML files.
This function scans the directory tree for flow.dag.yaml files and processes
them to register Jinja2 templates found within the nodes. It is completely
isolated from the real file system via walker_func and file_reader injections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
Optional[str]
|
The root directory to start scanning. Defaults to the current working directory. |
None
|
registry
|
Optional[AgentRegistry]
|
The registry instance to register definitions into. Defaults to the global registry. |
None
|
walker_func
|
Optional[Callable]
|
A callable that behaves like os.walk. Defaults to |
None
|
file_reader
|
Optional[Callable]
|
A callable that reads a file path and returns content.
Defaults to |
None
|