JupyterCodeExecutor

JupyterCodeExecutor(
    jupyter_server: JupyterConnectable | JupyterConnectionInfo,
    kernel_name: str = 'python3',
    timeout: int = 60,
    output_dir: Path | str = PosixPath('.')
)

(Experimental) A code executor class that executes code blocks and returns the result.
(Experimental) A code executor class that executes code statefully using a Jupyter server supplied to this class.
Each execution is stateful and can access variables created from previous executions in the same session.

Parameters:
NameDescription
jupyter_serverType: JupyterConnectable | JupyterConnectionInfo
kernel_nameType: str

Default: ‘python3’
timeoutType: int

Default: 60
output_dirType: pathlib.Path | str

Default: PosixPath(’.’)

Instance Attributes

code_extractor


(Experimental) Export a code extractor that can be used by an agent.

Instance Methods

execute_code_blocks

execute_code_blocks(self, code_blocks: list[CodeBlock]) -> IPythonCodeResult

(Experimental) Execute a list of code blocks and return the result.
This method executes a list of code blocks as cells in the Jupyter kernel.
See: https://jupyter-client.readthedocs.io/en/stable/messaging.html for the message protocol.

Parameters:
NameDescription
code_blocksA list of code blocks to execute.

Type: list[CodeBlock]
Returns:
TypeDescription
autogen.coding.base.IPythonCodeResultIPythonCodeResult: The result of the code execution.

restart

restart(self) -> None

(Experimental) Restart a new session.


stop

stop(self) -> None

Stop the kernel.