Skip to content

Environment

Base classes for environments that execute actions and produce observations

Classes:

CodeExecutionEnvironment

Bases: Environment

Environment for the team agents The only action that the environment can perform is to execute the code blocks

Source code in tapeagents/environment.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class CodeExecutionEnvironment(Environment):
    """
    Environment for the team agents
    The only action that the environment can perform is to execute the code blocks
    """

    def __init__(self, container_executor: ContainerExecutor):
        self.container_executor = container_executor

    def react(self, tape: Tape) -> Tape:
        match step := tape.steps[-1]:
            case ExecuteCode():
                result = self.container_executor.execute_code_blocks(step.code)
                return tape.append(CodeExecutionResult(result=result))
            case _:
                return tape

ExternalObservationNeeded

Bases: Exception

Environments raise this when they can't make the required observation for an action

Source code in tapeagents/environment.py
24
25
26
27
28
29
30
31
32
class ExternalObservationNeeded(Exception):
    """Environments raise this when they can't make the required observation for an action"""

    def __init__(self, action: Action, *args, **wargs):
        super().__init__(*args, **wargs)
        self.action = action

    def __str__(self) -> str:
        return f"Environment needs external observation for action {self.action}"

NoActionsToReactTo

Bases: Exception

Environments raise this when there are no actions to react to

Source code in tapeagents/environment.py
35
36
37
38
39
class NoActionsToReactTo(Exception):
    """Environments raise this when there are no actions to react to"""

    def __init__(self, *args, **wargs):
        super().__init__(*args, **wargs)