EmbeddedIPythonCodeExecutor

EmbeddedIPythonCodeExecutor(**kwargs: Any)

(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.

Parameters:
NameDescription
**kwargsType: Any

Class Attributes

kernel_name



model_config



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

construct(**values: Any) -> Self
Parameters:
NameDescription
**valuesType: Any

copy

copy(
    self,
    *,
    include: AbstractSetIntStr | MappingIntStrAny | None = None,
    exclude: AbstractSetIntStr | MappingIntStrAny | None = None,
    update: Dict[str, Any] | None = None,
    deep: bool = False
) -> Self

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

data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = \{**data, **(update or \{})}
copied = self.model_validate(data)
Parameters:
NameDescription
includeOptional set or mapping specifying which fields to include in the copied model.

Type: AbstractSetIntStr | MappingIntStrAny | None

Default: None
excludeOptional set or mapping specifying which fields to exclude in the copied model.

Type: AbstractSetIntStr | MappingIntStrAny | None

Default: None
updateOptional dictionary of field-value pairs to override field values in the copied model.

Type: Dict[str, Any] | None

Default: None
deepIf True, the values of fields that are Pydantic models will be deep-copied.

Type: bool

Default: False
Returns:
TypeDescription
SelfA copy of the model with included, excluded and updated fields as specified.

dict

dict(
    self,
    *,
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False
) -> Dict[str, Any]
Parameters:
NameDescription
includeType: IncEx | None

Default: None
excludeType: IncEx | None

Default: None
by_aliasType: bool

Default: False
exclude_unsetType: bool

Default: False
exclude_defaultsType: bool

Default: False
exclude_noneType: bool

Default: False

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 an IPython kernel managed by this class.
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.

from_orm

from_orm(obj: Any) -> Self
Parameters:
NameDescription
objType: Any

json

json(
    self,
    *,
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    encoder: Callable[[Any], Any] | None = PydanticUndefined,
    models_as_dict: bool = PydanticUndefined,
    **dumps_kwargs: Any
) -> str
Parameters:
NameDescription
includeType: IncEx | None

Default: None
excludeType: IncEx | None

Default: None
by_aliasType: bool

Default: False
exclude_unsetType: bool

Default: False
exclude_defaultsType: bool

Default: False
exclude_noneType: bool

Default: False
encoderType: Callable[[Any], Any] | None

Default: PydanticUndefined
models_as_dictType: bool

Default: PydanticUndefined
**dumps_kwargsType: Any

model_construct

model_construct(**values: Any) -> Self

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:
NameDescription
**valuesType: Any
Returns:
TypeDescription
SelfA new instance of the Model class with validated data.

model_copy

model_copy(
    self,
    *,
    update: Mapping[str, Any] | None = None,
    deep: bool = False
) -> Self

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy

Returns a copy of the model.

Parameters:
NameDescription
updateValues to change/add in the new model.

Note: the data is not validated before creating the new model.

You should trust this data.

Type: Mapping[str, Any] | None

Default: None
deepSet to True to make a deep copy of the model.

Type: bool

Default: False
Returns:
TypeDescription
SelfNew model instance.

model_dump

model_dump(
    self,
    *,
    mode: "Literal['json', 'python'] | str" = 'python',
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    context: Any | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    round_trip: bool = False,
    warnings: "bool | Literal['none', 'warn', 'error']" = True,
    serialize_as_any: bool = False
) -> dict[str, Any]

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Parameters:
NameDescription
modeThe mode in which to_python should run.

If mode is ‘json’, the output will only contain JSON serializable types.

If mode is ‘python’, the output may contain non-JSON-serializable Python objects.

Type: “Literal[‘json’, ‘python’] | str”

Default: ‘python’
includeA set of fields to include in the output.

Type: IncEx | None

Default: None
excludeA set of fields to exclude from the output.

Type: IncEx | None

Default: None
contextAdditional context to pass to the serializer.

Type: Any | None

Default: None
by_aliasWhether to use the field’s alias in the dictionary key if defined.

Type: bool

Default: False
exclude_unsetWhether to exclude fields that have not been explicitly set.

Type: bool

Default: False
exclude_defaultsWhether to exclude fields that are set to their default value.

Type: bool

Default: False
exclude_noneWhether to exclude fields that have a value of None.

Type: bool

Default: False
round_tripIf True, dumped values should be valid as input for non-idempotent types such as Json[T].

Type: bool

Default: False
warningsHow to handle serialization errors.

False/“none” ignores them, True/“warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

Type: “bool | Literal[‘none’, ‘warn’, ‘error’]“

Default: True
serialize_as_anyWhether to serialize fields with duck-typing serialization behavior.

Type: bool

Default: False
Returns:
TypeDescription
dict[str, typing.Any]A dictionary representation of the model.

model_dump_json

model_dump_json(
    self,
    *,
    indent: int | None = None,
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    context: Any | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    round_trip: bool = False,
    warnings: "bool | Literal['none', 'warn', 'error']" = True,
    serialize_as_any: bool = False
) -> str

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json

Generates a JSON representation of the model using Pydantic’s to_json method.

Parameters:
NameDescription
indentIndentation to use in the JSON output.

If None is passed, the output will be compact.

Type: int | None

Default: None
includeField(s) to include in the JSON output.

Type: IncEx | None

Default: None
excludeField(s) to exclude from the JSON output.

Type: IncEx | None

Default: None
contextAdditional context to pass to the serializer.

Type: Any | None

Default: None
by_aliasWhether to serialize using field aliases.

Type: bool

Default: False
exclude_unsetWhether to exclude fields that have not been explicitly set.

Type: bool

Default: False
exclude_defaultsWhether to exclude fields that are set to their default value.

Type: bool

Default: False
exclude_noneWhether to exclude fields that have a value of None.

Type: bool

Default: False
round_tripIf True, dumped values should be valid as input for non-idempotent types such as Json[T].

Type: bool

Default: False
warningsHow to handle serialization errors.

False/“none” ignores them, True/“warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

Type: “bool | Literal[‘none’, ‘warn’, ‘error’]“

Default: True
serialize_as_anyWhether to serialize fields with duck-typing serialization behavior.

Type: bool

Default: False
Returns:
TypeDescription
strA JSON string representation of the model.

model_json_schema

model_json_schema(
    by_alias: bool = True,
    ref_template: str = '#/$defs/{model}',
    schema_generator: type[GenerateJsonSchema] = pydantic.json_schema.GenerateJsonSchema,
    mode: JsonSchemaMode = 'validation'
) -> dict[str, Any]

Generates a JSON schema for a model class.

Parameters:
NameDescription
by_aliasWhether to use attribute aliases or not.

Type: bool

Default: True
ref_templateThe reference template.

Type: str

Default: ’#/$defs/{model}‘
schema_generatorTo override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications

Type: type[GenerateJsonSchema]

Default: pydantic.json_schema.GenerateJsonSchema
modeThe mode in which to generate the schema.

Type: JsonSchemaMode

Default: ‘validation’
Returns:
TypeDescription
dict[str, typing.Any]The JSON schema for the given model class.

model_parametrized_name

model_parametrized_name(params: tuple[type[Any], ...]) -> str

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

Parameters:
NameDescription
paramsTuple of types of the class.

Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.

Type: tuple[type[Any], …]
Returns:
TypeDescription
strString representing the new class where params are passed to cls as type variables.

model_post_init

model_post_init(self, _BaseModel__context: Any) -> None

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:
NameDescription
_BaseModel__contextType: Any

model_rebuild

model_rebuild(
    *,
    force: bool = False,
    raise_errors: bool = True
) -> 

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:
NameDescription
forceWhether to force the rebuilding of the model schema, defaults to False.

Type: bool

Default: False
raise_errorsWhether to raise errors, defaults to True.

Type: bool

Default: True

model_validate

model_validate(
    obj: Any,
    *,
    strict: bool | None = None,
    from_attributes: bool | None = None,
    context: Any | None = None
) -> Self

Validate a pydantic model instance.

Parameters:
NameDescription
objThe object to validate.

Type: Any
strictWhether to enforce types strictly.

Type: bool | None

Default: None
from_attributesWhether to extract data from object attributes.

Type: bool | None

Default: None
contextAdditional context to pass to the validator.

Type: Any | None

Default: None
Returns:
TypeDescription
SelfThe validated model instance.

model_validate_json

model_validate_json(
    json_data: str | bytes | bytearray,
    *,
    strict: bool | None = None,
    context: Any | None = None
) -> Self

Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing

Validate the given JSON data against the Pydantic model.

Parameters:
NameDescription
json_dataThe JSON data to validate.

Type: str | bytes | bytearray
strictWhether to enforce types strictly.

Type: bool | None

Default: None
contextExtra variables to pass to the validator.

Type: Any | None

Default: None
Returns:
TypeDescription
SelfThe validated Pydantic model.

model_validate_strings

model_validate_strings(
    obj: Any,
    *,
    strict: bool | None = None,
    context: Any | None = None
) -> Self

Validate the given object with string data against the Pydantic model.

Parameters:
NameDescription
objThe object containing string data to validate.

Type: Any
strictWhether to enforce types strictly.

Type: bool | None

Default: None
contextExtra variables to pass to the validator.

Type: Any | None

Default: None
Returns:
TypeDescription
SelfThe validated Pydantic model.

parse_file

parse_file(
    path: str | Path,
    *,
    content_type: str | None = None,
    encoding: str = 'utf8',
    proto: DeprecatedParseProtocol | None = None,
    allow_pickle: bool = False
) -> 
Parameters:
NameDescription
pathType: str | Path
content_typeType: str | None

Default: None
encodingType: str

Default: ‘utf8’
protoType: DeprecatedParseProtocol | None

Default: None
allow_pickleType: bool

Default: False

parse_obj

parse_obj(obj: Any) -> Self
Parameters:
NameDescription
objType: Any

parse_raw

parse_raw(
    b: str | bytes,
    *,
    content_type: str | None = None,
    encoding: str = 'utf8',
    proto: DeprecatedParseProtocol | None = None,
    allow_pickle: bool = False
) -> 
Parameters:
NameDescription
bType: str | bytes
content_typeType: str | None

Default: None
encodingType: str

Default: ‘utf8’
protoType: DeprecatedParseProtocol | None

Default: None
allow_pickleType: bool

Default: False

restart

restart(self) -> None

(Experimental) Restart a new session.


schema

schema(by_alias: bool = True, ref_template: str = '#/$defs/{model}') -> Dict[str, Any]
Parameters:
NameDescription
by_aliasType: bool

Default: True
ref_templateType: str

Default: ’#/$defs/{model}‘

schema_json

schema_json(
    *,
    by_alias: bool = True,
    ref_template: str = '#/$defs/{model}',
    **dumps_kwargs: Any
) -> str
Parameters:
NameDescription
by_aliasType: bool

Default: True
ref_templateType: str

Default: ’#/$defs/{model}‘
**dumps_kwargsType: Any

update_forward_refs

update_forward_refs(**localns: Any) -> None
Parameters:
NameDescription
**localnsType: Any

validate

validate(value: Any) -> Self
Parameters:
NameDescription
valueType: Any