config
agent_cover.config
Configuration management module for AgentCover.
This module acts as the schema definition for the agent-cover.yaml file.
It dictates how the library understands the user's business requirements ("Decisions").
The agent-cover.yaml File
This file defines the Business Logic decisions you want to enforce manually. Place it in the root of your project (where you run pytest).
```yaml decisions: - id: "OrderProcessor.status" # Unique ID for the rule description: "Check order flow" # Description for the report target_field: "status" # JSON key to look for in LLM output expected_values: # Values required for 100% coverage - "PENDING" - "SHIPPED" - "CANCELLED"
- id: "SentimentAnalysis" target_field: "sentiment" expected_values: ["POSITIVE", "NEGATIVE", "NEUTRAL"]
🔗 Architectural Relationships
The configuration serves as the Rulebook for the coverage session.
- Consumed by: OutputAnalyzer.
The analyzer reads the
decisionslist defined here to validate runtime LLM outputs against expected values. - Populated by:
- YAML Loader: (User defined rules in
agent-cover.yaml). - Structure Scanner: (Auto-generated rules found by inspecting Pydantic models).
- YAML Loader: (User defined rules in
Key Components: - DecisionConfig: Represents a single business rule. - AgentCoverConfig: The root configuration container.
Classes
AgentCoverConfig
dataclass
The root configuration object for AgentCover.
This dataclass holds the global configuration, primarily the list of business logic rules (DecisionConfig) that the OutputAnalyzer will use.
Attributes:
| Name | Type | Description |
|---|---|---|
decisions |
List[DecisionConfig]
|
A list of decision rules to enforce. |
Source code in src/agent_cover/config.py
DecisionConfig
dataclass
Represents a configuration for a specific decision within the agent.
This dataclass defines a "Decision Coverage" goal. It maps a specific field in the agent's output to a set of expected values that must be observed to achieve 100% coverage.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for this decision (e.g., "SentimentAnalysis" or "ClassName.field"). |
description |
str
|
Human-readable description of what this rule tests. |
target_field |
str
|
The key in the JSON output/dict to inspect (e.g., "status", "intent"). |
expected_values |
List[str]
|
All possible values that should be observed during testing. |
file_path |
Optional[str]
|
Source file origin (auto-filled by scanners). |
line_number |
Optional[int]
|
Source line origin (auto-filled by scanners). |
Examples:
Defining a rule to check if the agent handles both 'Refund' and 'Sales' intents:
# In agent-cover.yaml
decisions:
- id: intent_classification
description: Ensure all intents are triggered
target_field: intent
expected_values:
- REFUND
- SALES
- TECH_SUPPORT
Source code in src/agent_cover/config.py
Functions
get_config()
Retrieves the global AgentCoverConfig instance.
This function returns the global AgentCoverConfig instance, loading it if it hasn't been loaded yet.
Returns:
| Name | Type | Description |
|---|---|---|
AgentCoverConfig |
AgentCoverConfig
|
The global AgentCoverConfig instance. |
Source code in src/agent_cover/config.py
load_config(root_path, reader_func=None)
Loads the configuration from the file system.
This function loads the AgentCover configuration from a YAML file (agent-cover.yaml) located in the specified root path. It uses a provided reader function (or a default one) to read the file content and then parses it into an AgentCoverConfig object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
str
|
The root path where the agent-cover.yaml file is located. |
required |
reader_func
|
Optional[Callable[[str], Dict[str, Any]]]
|
An optional function to read the YAML file. This is useful for testing, allowing a mock reader to be injected. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AgentCoverConfig |
AgentCoverConfig
|
An AgentCoverConfig object containing the loaded configuration. |
Source code in src/agent_cover/config.py
parse_config_from_dict(data)
Parses configuration data from a dictionary.
This function takes a dictionary containing configuration data and parses it into an AgentCoverConfig object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
A dictionary containing the configuration data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AgentCoverConfig |
AgentCoverConfig
|
An AgentCoverConfig object populated with the parsed data. |