Metadata
This module provides base metadata classes, used with AgentRun
and Transcript
objects.
Any BaseMetadata
subclass must be JSON serializable. There is a validator that checks for compliance.
BaseAgentRunMetadata
is an extension of BaseMetadata
that requires scores
. The scoring fields are useful for tracking metrics, like task completion or reward. All AgentRun
objects require these fields, but Transcript
objects don't.
Accessing metadata
Values
Use the get()
method for safer access to metadata values:
value = metadata.get("field_name") # Returns None if missing
value = metadata.get("field_name", default_value="fallback") # Custom default
value = metadata.get("field_name", raise_if_missing=True) # Raises if missing
Descriptions
Retrieve field descriptions using:
desc = metadata.get_field_description("field_name") # Single field
all_descs = metadata.get_all_field_descriptions() # All fields
Subclassing metadata classes
You can create custom metadata classes (e.g., to store arbitrary evaluation data or training information) by subclassing BaseMetadata
or BaseAgentRunMetadata
:
from pydantic import Field
from docent.data_models import BaseAgentRunMetadata
class RLTrainingMetadata(BaseAgentRunMetadata):
episode: int = Field(description="Training episode number")
policy_version: str = Field(description="Version of the policy used")
training_step: int = Field(description="Global training step")
Note
As demonstrated above, we recommend using pydantic.Field
to add field descriptions, which are passed to LLMs to help them better answer your questions.
You can then populate your custom metadata class as such:
metadata = RLTrainingMetadata(
# Required fields
scores={"reward_1": 0.1, "reward_2": 0.5, "reward_3": 0.8},
# Custom fields
episode=42,
policy_version="v1.2.3",
training_step=12500,
)
docent.data_models.metadata
BaseMetadata
Bases: BaseModel
Provides common functionality for accessing and validating metadata fields. All metadata classes should inherit from this class.
Serialization Behavior
- Field descriptions are highly recommended and stored in serialized versions of the object.
- When a subclass of BaseMetadata is uploaded to a server, all extra fields and their descriptions are retained.
- To recover the original structure with proper typing upon download, use:
CustomMetadataClass.model_validate(obj.model_dump())
.
Attributes:
Name | Type | Description |
---|---|---|
model_config |
Pydantic configuration that allows extra fields. |
|
allow_fields_without_descriptions |
bool
|
Boolean indicating whether to allow fields without descriptions. |
Source code in docent/data_models/metadata.py
21 22 23 24 25 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 168 169 170 171 172 173 174 175 176 177 178 179 |
|
model_post_init
Initializes field descriptions from extra data after model initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context provided by Pydantic's post-initialization hook. |
required |
Source code in docent/data_models/metadata.py
get
Gets a value from the metadata by key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key to look up in the metadata. |
required |
default_value
|
Any
|
Value to return if the key is not found. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value associated with the key, or the default value if not found. |
Source code in docent/data_models/metadata.py
get_field_description
Gets the description of a field defined in the model schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_name
|
str
|
The name of the field. |
required |
Returns:
Type | Description |
---|---|
str | None
|
str or None: The description string if the field is defined in the model schema and has a description, otherwise None. |
Source code in docent/data_models/metadata.py
get_all_field_descriptions
Gets descriptions for all fields defined in the model schema.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str | None]
|
A dictionary mapping field names to their descriptions. Only includes fields that have descriptions defined in the schema. |
Source code in docent/data_models/metadata.py
BaseAgentRunMetadata
Bases: BaseMetadata
Extends BaseMetadata with fields specific to agent evaluation runs.
Attributes:
Name | Type | Description |
---|---|---|
scores |
dict[str, int | float | bool | None]
|
Dictionary of evaluation metrics. |
default_score_key |
str | None
|
The primary evaluation metric key. |
Source code in docent/data_models/metadata.py
get_default_score
Gets the default evaluation score.
Returns:
Type | Description |
---|---|
int | float | bool | None
|
int, float, bool, or None: The value of the default score if a default score key is set, otherwise None. |
Source code in docent/data_models/metadata.py
model_post_init
Initializes field descriptions from extra data after model initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context provided by Pydantic's post-initialization hook. |
required |
Source code in docent/data_models/metadata.py
get
Gets a value from the metadata by key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key to look up in the metadata. |
required |
default_value
|
Any
|
Value to return if the key is not found. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value associated with the key, or the default value if not found. |
Source code in docent/data_models/metadata.py
get_field_description
Gets the description of a field defined in the model schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_name
|
str
|
The name of the field. |
required |
Returns:
Type | Description |
---|---|
str | None
|
str or None: The description string if the field is defined in the model schema and has a description, otherwise None. |
Source code in docent/data_models/metadata.py
get_all_field_descriptions
Gets descriptions for all fields defined in the model schema.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str | None]
|
A dictionary mapping field names to their descriptions. Only includes fields that have descriptions defined in the schema. |
Source code in docent/data_models/metadata.py
FrameDimension
Bases: BaseModel
A dimension for organizing agent runs.