Skip to main content

agora.common.executor

Executor Objects

class Executor()

Abstract base class for executors that run protocol implementations.

__call__

@abstractmethod
def __call__(protocol_id: str, code: str, tools: List[ToolLike],
input_args: list, input_kwargs: dict) -> Any

Executes code with provided tools and arguments.

Arguments:

  • protocol_id str - The protocol identifier.
  • code str - The code to execute.
  • tools List[ToolLike] - Available tools for the code.
  • input_args list - Positional arguments.
  • input_kwargs dict - Keyword arguments.

Returns:

  • Any - The result of the code execution.

new_conversation

def new_conversation(protocol_id: str, code: str, multiround: bool,
tools: List[ToolLike]) -> Conversation

Starts a new conversation using the executor.

Arguments:

  • protocol_id str - The protocol identifier.
  • code str - The code to execute.
  • multiround bool - Whether multiple rounds are allowed.
  • tools List[ToolLike] - Tools allowed for execution.

Returns:

  • Conversation - A conversation object for execution.

UnsafeExecutor Objects

class UnsafeExecutor(Executor)

Executes code in an unsafe environment, allowing unrestricted operations.

__call__

def __call__(protocol_id: str, code: str, tools: List[ToolLike],
input_args: list, input_kwargs: dict) -> Any

Executes code using Python's importlib without restrictions.

Arguments:

  • protocol_id str - The protocol identifier.
  • code str - The code to execute.
  • tools List[ToolLike] - Tools available to the executed code.
  • input_args list - Positional arguments.
  • input_kwargs dict - Keyword arguments.

Returns:

  • Any - The result of the executed code.

RestrictedExecutor Objects

class RestrictedExecutor(Executor)

Executes code in a restricted environment to ensure safety.

__call__

def __call__(protocol_id: str, code: str, tools: List[ToolLike],
input_args: list, input_kwargs: dict) -> Any

Executes the code using a restricted interpreter with limited globals.

Arguments:

  • protocol_id str - The protocol identifier.
  • code str - The code to execute.
  • tools List[ToolLike] - Tools allowed in the environment.
  • input_args list - Positional arguments for the function.
  • input_kwargs dict - Keyword arguments for the function.

Returns:

  • Any - The result of the execution.

ExecutorConversation Objects

class ExecutorConversation(Conversation)

Handles conversations by executing code via the associated executor.

__init__

def __init__(executor: Executor, protocol_id: str, code: str, multiround: bool,
tools: List[ToolLike]) -> None

Initializes ExecutorConversation.

Arguments:

  • executor Executor - The executor used for code execution.
  • protocol_id str - The identifier of the protocol.
  • code str - The code to be executed.
  • multiround bool - Whether multiple rounds are allowed.
  • tools List[ToolLike] - Tools allowed for execution.

__call__

def __call__(message: str, print_output: bool = True) -> Any

Processes a message by executing the implementation code.

Arguments:

  • message str - The input message for the conversation.
  • print_output bool - Whether to print the result.

Returns:

  • Any - The output from the execution of the code.