JupyterCodeExecutor

JupyterCodeExecutor(
    jupyter_server: autogen.coding.jupyter.JupyterConnectable | autogen.coding.jupyter.JupyterConnectionInfo,
    kernel_name: str = 'python3',
    timeout: int = 60,
    output_dir: pathlib.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_serverThe Jupyter server to use.

Type: autogen.coding.jupyter.JupyterConnectable | autogen.coding.jupyter.JupyterConnectionInfo
kernel_nameThe kernel name to use.

Make sure it is installed.

By default, it is “python3”.

Type: str

Default: ‘python3’
timeoutThe timeout for code execution, by default 60.

Type: int

Default: 60
output_dirThe directory to save output files, by default ”.”.

Type: 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[autogen.coding.CodeBlock]) -> autogen.coding.base.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[autogen.coding.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.