Skip to main content

EmbeddedIPythonCodeExecutor

(Experimental) A code executor class that executes code statefully using an embedded IPython kernel managed by this class.
This will execute LLM generated code on the local machine.
Each execution is stateful and can access variables created from previous executions in the same session. The kernel must be installed before using this class. The kernel can be installed using the following command:
python -m ipykernel install --user --name \{kernel_name} where kernel_name is the name of the kernel to install.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Parameters:

Class Attributes

kernel_name



model_computed_fields



model_config



model_fields



output_dir



timeout



Instance Attributes

code_extractor


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

model_extra


Get extra fields set during validation.
Returns:
A dictionary of extra fields, or None if config.extra is not set to "allow".

model_fields_set


Returns the set of fields that have been explicitly set on this model instance.
Returns:
A set of strings representing the fields that have been set, i.e. that were not filled from defaults.

Instance Methods

construct

Parameters:

copy

Returns a copy of the model.
!!! warning “Deprecated” This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
Parameters: Returns:

dict

Parameters:

execute_code_blocks

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

from_orm

Parameters:

json

Parameters:

model_construct

Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
!!! note model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in an error if extra values are passed, but they will be ignored.
Parameters: Returns:

model_copy

!!! abstract “Usage Documentation” model_copy Returns a copy of the model.
!!! note The underlying instance’s [__dict__][object.dict] attribute is copied. This might have unexpected side effects if you store anything in it, on top of the model fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters: Returns:

model_dump

!!! abstract “Usage Documentation” model_dump Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters: Returns:

model_dump_json

!!! abstract “Usage Documentation” model_dump_json Generates a JSON representation of the model using Pydantic’s to_json method.
Parameters: Returns:

model_json_schema

Generates a JSON schema for a model class.
Parameters: Returns:

model_parametrized_name

Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters: Returns:

model_post_init

Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Parameters:

model_rebuild

Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:

model_validate

Validate a pydantic model instance.
Parameters: Returns:

model_validate_json

!!! abstract “Usage Documentation” JSON Parsing Validate the given JSON data against the Pydantic model.
Parameters: Returns:

model_validate_strings

Validate the given object with string data against the Pydantic model.
Parameters: Returns:

parse_file

Parameters:

parse_obj

Parameters:

parse_raw

Parameters:

restart

(Experimental) Restart a new session.

schema

Parameters:

schema_json

Parameters:

update_forward_refs

Parameters:

validate

Parameters: