autogen_core.code_executor#

class Alias(name: 'str', alias: 'str')[source]#

Bases: object

alias: str#
name: str#
class CodeBlock(code: str, language: str)[source]#

Bases: object

A code block extracted fromm an agent message.

code: str#
language: str#
class CodeExecutor(*args, **kwargs)[source]#

Bases: Protocol

Executes code blocks and returns the result.

async execute_code_blocks(code_blocks: List[CodeBlock], cancellation_token: CancellationToken) CodeResult[source]#

Execute code blocks and return the result.

This method should be implemented by the code executor.

Parameters:

code_blocks (List[CodeBlock]) – The code blocks to execute.

Returns:

CodeResult – The result of the code execution.

Raises:
async restart() None[source]#

Restart the code executor.

This method should be implemented by the code executor.

This method is called when the agent is reset.

class CodeResult(exit_code: int, output: str)[source]#

Bases: object

Result of a code execution.

exit_code: int#
output: str#
class FunctionWithRequirements(func: 'Callable[P, T]', python_packages: 'Sequence[str]' = <factory>, global_imports: 'Sequence[Import]' = <factory>)[source]#

Bases: Generic[T, P]

classmethod from_callable(func: Callable[[P], T], python_packages: Sequence[str] = [], global_imports: Sequence[str | ImportFromModule | Alias] = []) FunctionWithRequirements[T, P][source]#
static from_str(func: str, python_packages: Sequence[str] = [], global_imports: Sequence[str | ImportFromModule | Alias] = []) FunctionWithRequirementsStr[source]#
func: Callable[[P], T]#
global_imports: Sequence[str | ImportFromModule | Alias]#
python_packages: Sequence[str]#
class FunctionWithRequirementsStr(func: 'str', python_packages: 'Sequence[str]' = [], global_imports: 'Sequence[Import]' = [])[source]#

Bases: object

compiled_func: Callable[[...], Any]#
func: str#
global_imports: Sequence[str | ImportFromModule | Alias]#
python_packages: Sequence[str]#
class ImportFromModule(module: 'str', imports: 'List[Union[str, Alias]]')[source]#

Bases: object

imports: List[str | Alias]#
module: str#
with_requirements(python_packages: Sequence[str] = [], global_imports: Sequence[str | ImportFromModule | Alias] = []) Callable[[Callable[[P], T]], FunctionWithRequirements[T, P]][source]#

Decorate a function with package and import requirements

Parameters:
  • python_packages (List[str], optional) – Packages required to function. Can include version info.. Defaults to [].

  • global_imports (List[Import], optional) – Required imports. Defaults to [].

Returns:

Callable[[Callable[P, T]], FunctionWithRequirements[T, P]] – The decorated function