Core
Core data structures for the tape agents framework.
Classes:
-
Action
–Base class representing an agent's action in a tape.
-
AgentEvent
–Event produced by the agent during the run.
-
AgentStep
–Base class representing a step produced by an agent.
-
Call
–Action that calls another agent.
-
Episode
–Auxiliary data structure for tape with annotations attached.
-
Error
–Base class representing an error in a tape.
-
FinalStep
–Action that stops orchestrator loop with a reason.
-
LLMCall
–LLMCall stores info about a call to a language model.
-
LLMOutputParsingFailureAction
–Represents an action that is produced automatically when the LLM output parsing fails.
-
Observation
–Base class representing an observation in a tape.
-
PartialStep
–Wrap your step as partial step to indicate that it is not finished yet.
-
Pass
–Action that does nothing.
-
Prompt
–A class representing a LLM prompt with messages and tools.
-
Respond
–Action that returns a response to the top-level agent after processing the call.
-
SetNextNode
–Action that sets the next node to run in the current agent.
-
Step
–Base class representing a step in a tape.
-
StepMetadata
–StepMetadata is a model that represents metadata for a tape step.
-
StopStep
–Action that stops orchestrator loop.
-
Tape
–Tape class represents a sequence of steps produced by agents and environments with associated metadata.
-
TapeMetadata
–TapeMetadata is a model that represents metadata information for a tape.
-
Thought
–Base class representing an agent's thought in a tape.
-
TrainingText
–Training text instance used to finetune a language model.
Attributes:
-
AnnotatorTape
–Type alias for annotator tapes.
-
AnnotatorTapeType
–Type variable for annotator tape types.
-
ContextType
–Type variable for context types.
-
LLMOutput
(TypeAlias
) –Type alias for the output of the language model.
-
StepType
–Type variable for step types.
-
TapeType
–Type variable for tape types.
AnnotatorTape = Tape[TapeType, StepType]
module-attribute
Type alias for annotator tapes.
AnnotatorTapeType = TypeVar('AnnotatorTapeType', bound=AnnotatorTape)
module-attribute
Type variable for annotator tape types.
ContextType = TypeVar('ContextType')
module-attribute
Type variable for context types.
LLMOutput: TypeAlias = litellm.utils.Message
module-attribute
Type alias for the output of the language model.
StepType = TypeVar('StepType', bound=Action | Observation | Thought)
module-attribute
Type variable for step types.
TapeType = TypeVar('TapeType', bound=Tape)
module-attribute
Type variable for tape types.
Action
Bases: AgentStep
Base class representing an agent's action in a tape.
Source code in tapeagents/core.py
137 138 139 140 141 142 |
|
AgentEvent
Bases: BaseModel
, Generic[TapeType]
Event produced by the agent during the run.
Can contain a step, a final tape with all new steps, or a partial step when used in streaming mode. Attributes are mutually exclusive.
Attributes:
-
step
(SerializeAsAny[Step]
) –A step produced by the agent.
-
partial_step
(PartialStep
) –A partial step produced by the agent.
-
partial_tape
(TapeType
) –A partial tape produced by the agent.
-
final_tape
(TapeType
) –A final tape produced by the agent.
Source code in tapeagents/core.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
AgentStep
Bases: Step
Base class representing a step produced by an agent.
Source code in tapeagents/core.py
121 122 123 124 125 126 |
|
Call
Bases: Thought
Action that calls another agent.
Attributes:
-
kind
(Literal['call']
) –A constant string indicating the type of action.
-
content
(str
) –The content passed with the call to the agent.
-
agent_name
(str
) –The name of the agent to call.
Source code in tapeagents/core.py
202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
Episode
Bases: BaseModel
Auxiliary data structure for tape with annotations attached. Humans may want to look at a tape with one-or-many annotations attached to agent's actions. This is a data structure to store such tapes. We store the tape id for traceability.
Source code in tapeagents/core.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
Error
Bases: Step
Base class representing an error in a tape.
Source code in tapeagents/core.py
113 114 115 116 117 118 |
|
FinalStep
Bases: StopStep
Action that stops orchestrator loop with a reason.
Attributes:
-
kind
(Literal['final_step']
) –A constant string indicating the type of action.
-
reason
(str
) –The reason for stopping the orchestr
Source code in tapeagents/core.py
168 169 170 171 172 173 174 175 176 177 178 |
|
LLMCall
Bases: BaseModel
LLMCall stores info about a call to a language model.
Attributes:
-
timestamp
(str
) –The timestamp when the call was made, in ISO 8601 format.
-
prompt
(Prompt
) –The input prompt provided to the language model.
-
output
(LLMOutput
) –The output generated by the language model.
-
prompt_length_tokens
(int
) –The length of the prompt in tokens. Defaults to -1 if not set.
-
output_length_tokens
(int
) –The length of the output in tokens. Defaults to -1 if not set.
-
cached
(bool
) –Indicates whether the result was retrieved from cache.
Source code in tapeagents/core.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
LLMOutputParsingFailureAction
Represents an action that is produced automatically when the LLM output parsing fails.
Attributes:
-
kind
(Literal['llm_output_parsing_failure_action']
) –A constant string indicating the type of action.
-
error
(str
) –A description of the error that occurred during parsing.
-
llm_output
(str
) –The raw output from the LLM that could not be parsed.
Source code in tapeagents/core.py
145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
Observation
Bases: Step
Base class representing an observation in a tape.
Source code in tapeagents/core.py
105 106 107 108 109 110 |
|
PartialStep
Bases: BaseModel
Wrap your step as partial step to indicate that it is not finished yet.
Attributes:
-
step
(Step
) –An instance of the Step class representing the step details.
Source code in tapeagents/core.py
94 95 96 97 98 99 100 101 102 |
|
Pass
Bases: Thought
Action that does nothing.
Source code in tapeagents/core.py
194 195 196 197 198 199 |
|
Prompt
Bases: BaseModel
A class representing a LLM prompt with messages and tools.
Attributes:
-
id
(str
) –A unique identifier for the prompt, generated by default.
-
tools
(list[dict]
) –A list of tools associated with the prompt, default is None.
-
messages
(list[dict]
) –A list of messages in the prompt, default is an empty list.
Methods:
-
from_user_message
–Creates a Prompt instance from a user message.
Source code in tapeagents/core.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
from_user_message(content)
staticmethod
Creates a Prompt instance from a user message.
Parameters:
-
content
(str
) –The content of the user message.
Returns:
-
Prompt
(Prompt
) –A Prompt instance with the user message.
Source code in tapeagents/core.py
333 334 335 336 337 338 339 340 341 342 343 344 |
|
Respond
Bases: Thought
Action that returns a response to the top-level agent after processing the call.
Attributes:
-
kind
(Literal['respond']
) –A constant string indicating the type of action.
-
content
(str
) –The content of the response.
-
copy_output
(bool
) –Indicates whether the last step before this one should be copied to the top-level agent.
Source code in tapeagents/core.py
217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
SetNextNode
Bases: Thought
Action that sets the next node to run in the current agent.
Attributes:
-
kind
(Literal['set_next_node']
) –A constant string indicating the type of action.
-
next_node
(str
) –The name of the next node to run.
Source code in tapeagents/core.py
181 182 183 184 185 186 187 188 189 190 191 |
|
Step
Bases: BaseModel
Base class representing a step in a tape.
Attributes:
-
metadata
(StepMetadata
) –Metadata associated with the step.
-
kind
(Literal['define_me']
) –A placeholder value indicating the kind of step. This should be overwritten in subclasses.
Methods:
-
get_kind
–Returns the default value of the 'kind' field.
-
llm_dict
–Dumps the step data as dictionary, excluding the metadata.
-
llm_view
–Returns a JSON string representation of the step data, excluding the metadata.
Source code in tapeagents/core.py
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 |
|
get_kind()
classmethod
Returns the default value of the 'kind' field.
Source code in tapeagents/core.py
88 89 90 91 |
|
llm_dict()
Dumps the step data as dictionary, excluding the metadata.
Source code in tapeagents/core.py
80 81 82 |
|
llm_view(indent=2)
Returns a JSON string representation of the step data, excluding the metadata.
Source code in tapeagents/core.py
84 85 86 |
|
StepMetadata
Bases: BaseModel
StepMetadata is a model that represents metadata for a tape step.
Attributes:
-
id
(str
) –A unique identifier for the step, generated using uuid4.
-
prompt_id
(str
) –An identifier for the llm prompt used to produce the step.
-
node
(str
) –The node that produced the step.
-
agent
(str
) –The agent that produced the step.
-
other
(dict[str, Any]
) –A dictionary to store additional metadata related to the step.
Source code in tapeagents/core.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
StopStep
Bases: Action
Action that stops orchestrator loop.
Source code in tapeagents/core.py
160 161 162 163 164 165 |
|
Tape
Bases: BaseModel
, Generic[ContextType, StepType]
Tape class represents a sequence of steps produced by agents and environments with associated metadata.
Supports iteration, slicing, concatenation, and appending of steps.
Attributes:
-
metadata
(TapeMetadata
) –Metadata associated with the tape.
-
context
(ContextType
) –Context information for the tape.
-
steps
(List[StepType]
) –List of steps in the tape.
Methods:
-
__add__
–Concatenate two tapes or append list of steps to the tape
-
append
–Adds a step to the tape and creates new metadata (new tape id, etc...).
-
with_new_id
–Creates a copy of the tape with new metadata.
Source code in tapeagents/core.py
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 |
|
__add__(tape)
Concatenate two tapes or append list of steps to the tape
Source code in tapeagents/core.py
290 291 292 293 294 295 296 297 298 299 300 |
|
append(step)
Adds a step to the tape and creates new metadata (new tape id, etc...).
Source code in tapeagents/core.py
302 303 304 305 306 |
|
with_new_id()
Creates a copy of the tape with new metadata.
Source code in tapeagents/core.py
308 309 310 311 312 |
|
TapeMetadata
Bases: BaseModel
TapeMetadata is a model that represents metadata information for a tape.
Attributes:
-
id
(str
) –A unique identifier for the tape, generated by default using uuid4.
-
parent_id
(str
) –An optional identifier for the parent tape.
-
author
(str
) –An optional name of the author of the tape.
-
author_tape_id
(str
) –An optional identifier for the author's tape.
-
n_added_steps
(int
) –The number of steps added to the tape in the last agent run, default is 0.
-
error
(Any
) –An optional field to store any errors occured during the last agent run.
-
result
(Any
) –Optional field to store the result associated with the tape, default is an empty dictionary.
Source code in tapeagents/core.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
Thought
Bases: AgentStep
Base class representing an agent's thought in a tape.
Source code in tapeagents/core.py
129 130 131 132 133 134 |
|
TrainingText
Bases: BaseModel
Training text instance used to finetune a language model.
Attributes:
-
text
(str
) –The full text of the training instance.
-
n_predicted
(int
) –The number of predicted tokens in the text.
-
reward
(float
) –The reward associated with the training instance. Defaults to 0.0.
-
logprobs
(List[float]
) –A list of log probabilities of the completion tokens from the assistant model.
-
ref_logprobs
(List[float]
) –A list of reference log probabilities of the completion tokens from the reference model.
-
group_id
(str
) –ID of the group. It is used by the RL finetuning script to normalize rewards.
-
prompt_text
(str
) –Portion of the text that serves as the prompt (i.e., the text excluding the predicted tokens).
-
output_text
(str
) –Portion of the text that represents the predicted output (i.e., the last n_predicted tokens).
Source code in tapeagents/core.py
17 18 19 20 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 |
|