# File based from: https://github.com/microsoft/autogen/blob/main/autogen/coding/base.py# Credit to original authorsfrom__future__importannotationsfromdataclassesimportdataclassfromtypingimportList,Protocol,runtime_checkablefrom.._cancellation_tokenimportCancellationToken
[docs]@dataclassclassCodeBlock:"""A code block extracted fromm an agent message."""code:strlanguage:str
[docs]@dataclassclassCodeResult:"""Result of a code execution."""exit_code:intoutput:str
[docs]@runtime_checkableclassCodeExecutor(Protocol):"""Executes code blocks and returns the result."""
[docs]asyncdefexecute_code_blocks(self,code_blocks:List[CodeBlock],cancellation_token:CancellationToken)->CodeResult:"""Execute code blocks and return the result. This method should be implemented by the code executor. Args: code_blocks (List[CodeBlock]): The code blocks to execute. Returns: CodeResult: The result of the code execution. Raises: ValueError: Errors in user inputs asyncio.TimeoutError: Code execution timeouts asyncio.CancelledError: CancellationToken evoked during execution """...
[docs]asyncdefrestart(self)->None:"""Restart the code executor. This method should be implemented by the code executor. This method is called when the agent is reset. """...