Transcript
A Transcript
object represents a sequence of chat messages (user, assistant, system, tool) from the perspective of a single agent. See here for more details on the chat message schemas.
Action units
Action units are logical groupings of related messages in a conversation. They represent complete interaction cycles between users, AI assistants, and tools.
Action units are determined by the following rules:
- System Messages: Each system message forms its own standalone action unit
- User-Assistant Exchanges:
- A new user message starts a new action unit (unless following another user message)
- Assistant messages following a user or another assistant stay in the same unit
- Tool messages are always part of the current unit
For precise details on how action units are determined, refer to the _compute_units_of_action
method implementation.
Conceptual Examples
Example 1: basic action units
Action Unit 0:
[System] "You are a helpful AI assistant..."
Action Unit 1:
[User] "What's the weather today?"
[Assistant] "The weather in your area is sunny with a high of 72°F"
Action Unit 2:
[User] "What should I wear?"
[Assistant] "Given the sunny weather, light clothing would be appropriate"
Example 2: action units with tools
Action Unit 0:
[System] "You are a coding assistant..."
Action Unit 1:
[User] "Create a Python function to calculate Fibonacci numbers"
[Assistant] "I'll create that function for you"
[Tool] Code generation tool output
Action Unit 2:
[Assistant] "Here's the function I created: ..."
Edge cases
Multiple consecutive user messages stay in same unit
Action Unit 0:
[User] "Hello"
[User] "Can you help me with something?"
[Assistant] "Yes, I'd be happy to help."
docent.data_models.transcript
Transcript
Bases: BaseModel
Represents a transcript of messages in a conversation with an AI agent.
A transcript contains a sequence of messages exchanged between different roles (system, user, assistant, tool) and provides methods to organize these messages into logical units of action.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
Unique identifier for the transcript, auto-generated by default. |
name |
str | None
|
Optional human-readable name for the transcript. |
description |
str | None
|
Optional description of the transcript. |
messages |
list[ChatMessage]
|
List of chat messages in the transcript. |
metadata |
BaseMetadata
|
Additional structured metadata about the transcript. |
Source code in docent/data_models/transcript.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
units_of_action
property
Get the units of action in the transcript.
A unit of action represents a logical group of messages, such as a system message on its own or a user message followed by assistant responses and tool outputs.
Returns:
Type | Description |
---|---|
list[list[int]]
|
list[list[int]]: List of units of action, where each unit is a list of message indices. |
serialize_metadata
serialize_metadata(metadata: BaseMetadata, _info: Any) -> dict[str, Any]
Custom serializer for the metadata field so the internal fields are explicitly preserved.
Source code in docent/data_models/transcript.py
get_first_block_in_action_unit
Get the index of the first message in a given action unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_unit_idx
|
int
|
The index of the action unit. |
required |
Returns:
Type | Description |
---|---|
int | None
|
int | None: The index of the first message in the action unit, or None if the action unit doesn't exist. |
Raises:
Type | Description |
---|---|
IndexError
|
If the action unit index is out of range. |
Source code in docent/data_models/transcript.py
get_action_unit_for_block
Find the action unit that contains the specified message block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_idx
|
int
|
The index of the message block to find. |
required |
Returns:
Type | Description |
---|---|
int | None
|
int | None: The index of the action unit containing the block, or None if no action unit contains the block. |
Source code in docent/data_models/transcript.py
set_messages
set_messages(messages: list[ChatMessage])
Set the messages in the transcript and recompute units of action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[ChatMessage]
|
The new list of chat messages to set. |
required |
Source code in docent/data_models/transcript.py
to_str_with_token_limit
to_str_with_token_limit(token_limit: int, transcript_idx: int = 0, agent_run_idx: int | None = None, highlight_action_unit: int | None = None) -> list[str]
Represents the transcript as a list of strings, each of which is at most token_limit tokens under the GPT-4 tokenization scheme.
We'll try to split up long transcripts along message boundaries and include metadata. For very long messages, we'll have to truncate them and remove metadata.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of strings, each of which is at most token_limit tokens |
list[str]
|
under the GPT-4 tokenization scheme. |
Source code in docent/data_models/transcript.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
TranscriptWithoutMetadataValidator
Bases: Transcript
A version of Transcript that doesn't have the model_validator on metadata. Needed for sending/receiving transcripts via JSON, since they incorrectly trip the existing model_validator.
Source code in docent/data_models/transcript.py
units_of_action
property
Get the units of action in the transcript.
A unit of action represents a logical group of messages, such as a system message on its own or a user message followed by assistant responses and tool outputs.
Returns:
Type | Description |
---|---|
list[list[int]]
|
list[list[int]]: List of units of action, where each unit is a list of message indices. |
serialize_metadata
serialize_metadata(metadata: BaseMetadata, _info: Any) -> dict[str, Any]
Custom serializer for the metadata field so the internal fields are explicitly preserved.
Source code in docent/data_models/transcript.py
get_first_block_in_action_unit
Get the index of the first message in a given action unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_unit_idx
|
int
|
The index of the action unit. |
required |
Returns:
Type | Description |
---|---|
int | None
|
int | None: The index of the first message in the action unit, or None if the action unit doesn't exist. |
Raises:
Type | Description |
---|---|
IndexError
|
If the action unit index is out of range. |
Source code in docent/data_models/transcript.py
get_action_unit_for_block
Find the action unit that contains the specified message block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_idx
|
int
|
The index of the message block to find. |
required |
Returns:
Type | Description |
---|---|
int | None
|
int | None: The index of the action unit containing the block, or None if no action unit contains the block. |
Source code in docent/data_models/transcript.py
set_messages
set_messages(messages: list[ChatMessage])
Set the messages in the transcript and recompute units of action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[ChatMessage]
|
The new list of chat messages to set. |
required |
Source code in docent/data_models/transcript.py
to_str_with_token_limit
to_str_with_token_limit(token_limit: int, transcript_idx: int = 0, agent_run_idx: int | None = None, highlight_action_unit: int | None = None) -> list[str]
Represents the transcript as a list of strings, each of which is at most token_limit tokens under the GPT-4 tokenization scheme.
We'll try to split up long transcripts along message boundaries and include metadata. For very long messages, we'll have to truncate them and remove metadata.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of strings, each of which is at most token_limit tokens |
list[str]
|
under the GPT-4 tokenization scheme. |
Source code in docent/data_models/transcript.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|