Skip to content

Dialog Tape

Types and classes for dialog tapes and annotators.

Classes:

  • AnnotationAction

    AnnotationAction is a subclass of Action that represents an action produced by an annotator.

  • AnnotatorFreeFormThought

    AnnotatorFreeFormThought is a subclass of Thought that represents a free-form thought provided by an annotator.

  • AssistantStep

    Represents a step taken by an assistant in a dialog.

  • AssistantThought

    Represents a thought generated by an assistant.

  • DialogAnnotator

    DialogAnnotator is a class that extends the Annotator agent with specific types DialogTape and DialogAnnotatorTape.

  • DialogContext

    Context for dialog agents, containing tools and other information.

  • FunctionCall

    A class representing a function call.

  • FunctionSpec

    A class representing the specification of a function.

  • SystemStep

    Step rendered into system message of the prompt.

  • ToolCall

    ToolCall is a model representing a tool call with a specific function, id, and type.

  • ToolCalls

    Action that wraps one-or-many tool calls.

  • ToolResult

    ToolResult is a subclass of Observation that represents the result of a tool call.

  • ToolSpec

    ToolSpec is a model that represents a tool specification with a type and a function.

  • UserStep

    Represents a step taken by a user in a dialog.

Attributes:

DialogAnnotatorTape: TypeAlias = Tape[DialogTape, AnnotatorFreeFormThought | AnnotationAction] module-attribute

Type alias for dialog annotator tapes.

DialogEvent: TypeAlias = AgentEvent[DialogTape] module-attribute

Type alias for dialog events.

DialogStep: TypeAlias = UserStep | ToolResult | SystemStep | AssistantThought | SetNextNode | Pass | Call | Respond | FinalStep | AssistantStep | ToolCalls module-attribute

Type alias for dialog steps.

DialogTape = Tape[DialogContext | None, DialogStep] module-attribute

Type alias for dialog tapes.

AnnotationAction

Bases: Action

AnnotationAction is a subclass of Action that represents an action produced by an annotator.

Attributes:

  • kind (Literal['annotation_action']) –

    A string literal indicating the type of action.

  • annotation (dict) –

    A dictionary containing annotation data.

Source code in tapeagents/dialog_tape.py
268
269
270
271
272
273
274
275
276
277
278
class AnnotationAction(Action):
    """
    AnnotationAction is a subclass of Action that represents an action produced by an annotator.

    Attributes:
        kind (Literal["annotation_action"]): A string literal indicating the type of action.
        annotation (dict): A dictionary containing annotation data.
    """

    kind: Literal["annotation_action"] = "annotation_action"
    annotation: dict

AnnotatorFreeFormThought

Bases: Thought

AnnotatorFreeFormThought is a subclass of Thought that represents a free-form thought provided by an annotator.

Attributes:

  • kind (Literal['annotator_free_form_thought']) –

    A constant string that identifies the type of thought.

  • content (str) –

    The content of the free-form thought provided by the annotator.

Source code in tapeagents/dialog_tape.py
255
256
257
258
259
260
261
262
263
264
265
class AnnotatorFreeFormThought(Thought):
    """
    AnnotatorFreeFormThought is a subclass of Thought that represents a free-form thought provided by an annotator.

    Attributes:
        kind (Literal["annotator_free_form_thought"]): A constant string that identifies the type of thought.
        content (str): The content of the free-form thought provided by the annotator.
    """

    kind: Literal["annotator_free_form_thought"] = "annotator_free_form_thought"
    content: str

AssistantStep

Bases: Action

Represents a step taken by an assistant in a dialog.

Attributes:

  • content (str) –

    The content of the assistant's response.

  • kind (Literal['assistant']) –

    The type of step, which is always "assistant".

Source code in tapeagents/dialog_tape.py
67
68
69
70
71
72
73
74
75
76
77
class AssistantStep(Action):
    """
    Represents a step taken by an assistant in a dialog.

    Attributes:
        content (str): The content of the assistant's response.
        kind (Literal["assistant"]): The type of step, which is always "assistant".
    """

    content: str
    kind: Literal["assistant"] = "assistant"

AssistantThought

Bases: Thought

Represents a thought generated by an assistant.

Attributes:

  • content (Any) –

    The content of the assistant's thought.

  • kind (Literal['assistant_thought']) –

    A literal string indicating the type of thought.

Source code in tapeagents/dialog_tape.py
54
55
56
57
58
59
60
61
62
63
64
class AssistantThought(Thought):
    """
    Represents a thought generated by an assistant.

    Attributes:
        content (Any): The content of the assistant's thought.
        kind (Literal["assistant_thought"]): A literal string indicating the type of thought.
    """

    content: Any
    kind: Literal["assistant_thought"] = "assistant_thought"

DialogAnnotator

Bases: Annotator[DialogTape, DialogAnnotatorTape]

DialogAnnotator is a class that extends the Annotator agent with specific types DialogTape and DialogAnnotatorTape.

Methods:

  • make_own_tape

    DialogTape) -> DialogAnnotatorTape: Creates and returns a DialogAnnotatorTape instance using the provided DialogTape instance.

Methods:

  • make_own_tape

    Creates a DialogAnnotatorTape instance using given DialogTape as context.

Source code in tapeagents/dialog_tape.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
class DialogAnnotator(Annotator[DialogTape, DialogAnnotatorTape]):
    """
    DialogAnnotator is a class that extends the Annotator agent with specific types DialogTape and DialogAnnotatorTape.

    Methods:
        make_own_tape(tape: DialogTape) -> DialogAnnotatorTape:
            Creates and returns a DialogAnnotatorTape instance using the provided DialogTape instance.
    """

    def make_own_tape(self, tape: DialogTape) -> DialogAnnotatorTape:
        """
        Creates a DialogAnnotatorTape instance using given DialogTape as context.

        Args:
            tape (DialogTape): The DialogTape instance to be converted.

        Returns:
            DialogAnnotatorTape: A new instance of DialogAnnotatorTape with the provided context.
        """
        return DialogAnnotatorTape(context=tape)

make_own_tape(tape)

Creates a DialogAnnotatorTape instance using given DialogTape as context.

Parameters:

  • tape (DialogTape) –

    The DialogTape instance to be converted.

Returns:

  • DialogAnnotatorTape ( DialogAnnotatorTape ) –

    A new instance of DialogAnnotatorTape with the provided context.

Source code in tapeagents/dialog_tape.py
294
295
296
297
298
299
300
301
302
303
304
def make_own_tape(self, tape: DialogTape) -> DialogAnnotatorTape:
    """
    Creates a DialogAnnotatorTape instance using given DialogTape as context.

    Args:
        tape (DialogTape): The DialogTape instance to be converted.

    Returns:
        DialogAnnotatorTape: A new instance of DialogAnnotatorTape with the provided context.
    """
    return DialogAnnotatorTape(context=tape)

DialogContext

Bases: BaseModel

Context for dialog agents, containing tools and other information.

Source code in tapeagents/dialog_tape.py
237
238
239
240
241
242
243
class DialogContext(BaseModel):
    """
    Context for dialog agents, containing tools and other information.
    """

    # TODO: define type signature for tools including JSONSchema and etc
    tools: list[ToolSpec]

FunctionCall

Bases: BaseModel

A class representing a function call.

Attributes:

  • name (str) –

    The name of the function being called.

  • arguments (Any) –

    The arguments to be passed to the function.

Source code in tapeagents/dialog_tape.py
80
81
82
83
84
85
86
87
88
89
90
class FunctionCall(BaseModel):
    """
    A class representing a function call.

    Attributes:
        name (str): The name of the function being called.
        arguments (Any): The arguments to be passed to the function.
    """

    name: str
    arguments: Any

FunctionSpec

Bases: BaseModel

A class representing the specification of a function.

Attributes:

  • name (str) –

    The name of the function.

  • description (str) –

    A brief description of the function.

  • parameters (dict) –

    A dictionary containing the parameters of the function.

Source code in tapeagents/dialog_tape.py
196
197
198
199
200
201
202
203
204
205
206
207
208
class FunctionSpec(BaseModel):
    """
    A class representing the specification of a function.

    Attributes:
        name (str): The name of the function.
        description (str): A brief description of the function.
        parameters (dict): A dictionary containing the parameters of the function.
    """

    name: str
    description: str
    parameters: dict

SystemStep

Bases: Observation

Step rendered into system message of the prompt.

Attributes:

  • content (str) –

    The content of the system step.

  • kind (Literal['system']) –

    A literal indicating the type of step, which is always "system".

Source code in tapeagents/dialog_tape.py
28
29
30
31
32
33
34
35
36
37
38
class SystemStep(Observation):
    """
    Step rendered into system message of the prompt.

    Attributes:
        content (str): The content of the system step.
        kind (Literal["system"]): A literal indicating the type of step, which is always "system".
    """

    content: str
    kind: Literal["system"] = "system"

ToolCall

Bases: BaseModel

ToolCall is a model representing a tool call with a specific function, id, and type.

Attributes:

  • function (FunctionCall) –

    The function call associated with the tool.

  • id (str) –

    The identifier for the tool call. Defaults to an empty string.

  • type (str) –

    The type of the tool call. Defaults to "function".

Source code in tapeagents/dialog_tape.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class ToolCall(BaseModel):
    """
    ToolCall is a model representing a tool call with a specific function, id, and type.

    Attributes:
        function (FunctionCall): The function call associated with the tool.
        id (str): The identifier for the tool call. Defaults to an empty string.
        type (str): The type of the tool call. Defaults to "function".
    """

    function: FunctionCall
    id: str = ""
    type: str = "function"

ToolCalls

Bases: Action

Action that wraps one-or-many tool calls.

We structure this class similar to OpenAI tool calls, but we let function arguments be Any, not just str (see FunctionCall class)

Attributes:

  • tool_calls (list[ToolCall]) –

    The list of tool calls to be made.

  • kind (Literal['assistant']) –

    The type of step, which is always "assistant".

Methods:

  • from_dicts

    Create a ToolCalls instance from a list of dictionaries.

  • from_llm_output

    Converts an LLMOutput object to a ToolCalls object.

Source code in tapeagents/dialog_tape.py
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
class ToolCalls(Action):
    """Action that wraps one-or-many tool calls.

    We structure this class similar to OpenAI tool calls, but we let function arguments be Any, not just str
    (see `FunctionCall` class)

    Attributes:
        tool_calls (list[ToolCall]): The list of tool calls to be made.
        kind (Literal["assistant"]): The type of step, which is always "assistant".
    """

    tool_calls: list[ToolCall]
    kind: Literal["assistant"] = "assistant"

    @staticmethod
    def from_dicts(dicts: list):
        """
        Create a ToolCalls instance from a list of dictionaries.

        Args:
            dicts (list): A list of dictionaries where each dictionary represents a tool call.

        Returns:
            (ToolCalls): An instance of ToolCalls created from the provided list of dictionaries.
        """
        return ToolCalls.model_validate({"tool_calls": dicts})

    @staticmethod
    def from_llm_output(llm_output: LLMOutput) -> ToolCalls:
        """
        Converts an LLMOutput object to a ToolCalls object.

        Args:
            llm_output (LLMOutput): The output from the language model, which contains tool calls.

        Returns:
            ToolCalls: An object containing a list of ToolCall objects.

        Raises:
            ValueError: If the llm_output does not contain any tool calls.
        """
        if not llm_output.tool_calls:
            raise ValueError()
        tool_calls = [
            ToolCall(
                function=FunctionCall(name=tc.function.name, arguments=tc.function.arguments),
                id=tc.id,
            )
            for tc in llm_output.tool_calls
        ]
        return ToolCalls(tool_calls=tool_calls)

from_dicts(dicts) staticmethod

Create a ToolCalls instance from a list of dictionaries.

Parameters:

  • dicts (list) –

    A list of dictionaries where each dictionary represents a tool call.

Returns:

  • ToolCalls

    An instance of ToolCalls created from the provided list of dictionaries.

Source code in tapeagents/dialog_tape.py
122
123
124
125
126
127
128
129
130
131
132
133
@staticmethod
def from_dicts(dicts: list):
    """
    Create a ToolCalls instance from a list of dictionaries.

    Args:
        dicts (list): A list of dictionaries where each dictionary represents a tool call.

    Returns:
        (ToolCalls): An instance of ToolCalls created from the provided list of dictionaries.
    """
    return ToolCalls.model_validate({"tool_calls": dicts})

from_llm_output(llm_output) staticmethod

Converts an LLMOutput object to a ToolCalls object.

Parameters:

  • llm_output (LLMOutput) –

    The output from the language model, which contains tool calls.

Returns:

  • ToolCalls ( ToolCalls ) –

    An object containing a list of ToolCall objects.

Raises:

  • ValueError

    If the llm_output does not contain any tool calls.

Source code in tapeagents/dialog_tape.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
@staticmethod
def from_llm_output(llm_output: LLMOutput) -> ToolCalls:
    """
    Converts an LLMOutput object to a ToolCalls object.

    Args:
        llm_output (LLMOutput): The output from the language model, which contains tool calls.

    Returns:
        ToolCalls: An object containing a list of ToolCall objects.

    Raises:
        ValueError: If the llm_output does not contain any tool calls.
    """
    if not llm_output.tool_calls:
        raise ValueError()
    tool_calls = [
        ToolCall(
            function=FunctionCall(name=tc.function.name, arguments=tc.function.arguments),
            id=tc.id,
        )
        for tc in llm_output.tool_calls
    ]
    return ToolCalls(tool_calls=tool_calls)

ToolResult

Bases: Observation

ToolResult is a subclass of Observation that represents the result of a tool call.

Attributes:

  • content (Any) –

    The content of the tool result.

  • tool_call_id (str) –

    The unique identifier for the tool call. Defaults to an empty string.

  • kind (Literal['tool']) –

    The kind of result, which is always "tool". Defaults to "tool".

Source code in tapeagents/dialog_tape.py
161
162
163
164
165
166
167
168
169
170
171
172
173
class ToolResult(Observation):
    """
    ToolResult is a subclass of Observation that represents the result of a tool call.

    Attributes:
        content (Any): The content of the tool result.
        tool_call_id (str): The unique identifier for the tool call. Defaults to an empty string.
        kind (Literal["tool"]): The kind of result, which is always "tool". Defaults to "tool".
    """

    content: Any
    tool_call_id: str = ""
    kind: Literal["tool"] = "tool"

ToolSpec

Bases: BaseModel

ToolSpec is a model that represents a tool specification with a type and a function.

Attributes:

  • type (Literal['function']) –

    The type of the tool, which is always "function".

  • function (FunctionSpec) –

    The specification of the function.

Methods:

  • from_function

    Creates an instance of the class by validating the model from a given function.

Source code in tapeagents/dialog_tape.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
class ToolSpec(BaseModel):
    """
    ToolSpec is a model that represents a tool specification with a type and a function.

    Attributes:
        type (Literal["function"]): The type of the tool, which is always "function".
        function (FunctionSpec): The specification of the function.
    """

    type: Literal["function"] = "function"
    function: FunctionSpec

    @classmethod
    def from_function(cls, function: Callable):
        """
        Creates an instance of the class by validating the model from a given function.

        Args:
            function (Callable): The function to be converted and validated.

        Returns:
            (ToolSpec): An instance of the class with the validated model.
        """
        return cls.model_validate(convert_to_openai_tool(function))

from_function(function) classmethod

Creates an instance of the class by validating the model from a given function.

Parameters:

  • function (Callable) –

    The function to be converted and validated.

Returns:

  • ToolSpec

    An instance of the class with the validated model.

Source code in tapeagents/dialog_tape.py
223
224
225
226
227
228
229
230
231
232
233
234
@classmethod
def from_function(cls, function: Callable):
    """
    Creates an instance of the class by validating the model from a given function.

    Args:
        function (Callable): The function to be converted and validated.

    Returns:
        (ToolSpec): An instance of the class with the validated model.
    """
    return cls.model_validate(convert_to_openai_tool(function))

UserStep

Bases: Observation

Represents a step taken by a user in a dialog.

Attributes:

  • content (str) –

    The content of the user's step.

  • kind (Literal['user']) –

    The type of step, which is always "user".

Source code in tapeagents/dialog_tape.py
41
42
43
44
45
46
47
48
49
50
51
class UserStep(Observation):
    """
    Represents a step taken by a user in a dialog.

    Attributes:
        content (str): The content of the user's step.
        kind (Literal["user"]): The type of step, which is always "user".
    """

    content: str
    kind: Literal["user"] = "user"