autogen_core.code_executor#
- class CodeBlock(code: str, language: str)[source]#
Bases:
object
A code block extracted fromm an agent message.
- 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:
ValueError – Errors in user inputs
TimeoutError – Code execution timeouts
CancelledError – CancellationToken evoked during execution
- 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]#
- global_imports: Sequence[str | ImportFromModule | Alias]#
- class FunctionWithRequirementsStr(func: 'str', python_packages: 'Sequence[str]' = [], global_imports: 'Sequence[Import]' = [])[source]#
Bases:
object
- global_imports: Sequence[str | ImportFromModule | Alias]#
- 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