Base
Core exporting infrastructure.
This module provides base classes, types, result builders, and extras for exportign flows.
BaseExtras dataclass
¶
BaseExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
)
Bases: ExportContributor
Base class for all exporter extras with export contribution.
add_arg ¶
add_arg(arg: InstanceArgument | str, tabs: int = 0) -> None
Add an extra argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg | InstanceArgument | The argument to add. | required |
tabs | int | The number of tabs to indent the argument, by default 0. | 0 |
Source code in waldiez/exporting/core/extras/base.py
add_import ¶
add_import(import_statement: ImportStatement) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
import_statement | str | The import statement to add. | required |
Source code in waldiez/exporting/core/extras/base.py
add_imports ¶
add_imports(imports: Sequence[ImportStatement]) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imports | Set[str] | The import statements to add. | required |
append_after_agent ¶
append_after_agent(content: str) -> None
Append content to the after_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_after_all_agents ¶
append_after_all_agents(content: str) -> None
Append content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_before_agent ¶
append_before_agent(content: str) -> None
Append content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
contribute_to_export ¶
contribute_to_export(result: ExportResult) -> None
Contribute this extras' content to the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | ExportResult | The export result to contribute to. | required |
Source code in waldiez/exporting/core/extras/base.py
get_extra_args_content ¶
get_extra_args_content() -> str
has_content ¶
has_content() -> bool
Check if there's any meaningful content.
Returns:
Type | Description |
---|---|
bool | True if there's any content in this extras instance. |
Source code in waldiez/exporting/core/extras/base.py
has_specific_content abstractmethod
¶
has_specific_content() -> bool
Check if there's subclass-specific content.
Returns:
Type | Description |
---|---|
bool | True if there's specific content for this extras type. |
prepend_after_all_agents ¶
prepend_after_all_agents(content: str) -> None
Prepend content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
prepend_before_agent ¶
prepend_before_agent(content: str) -> None
Prepend content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
CaptainExtras dataclass
¶
CaptainExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
nested_config: Optional[dict[str, Any]] = None,
)
Bases: StandardExtras
Extras for captain agents.
has_specific_content ¶
has_specific_content() -> bool
Check for captain specific content.
Returns:
Type | Description |
---|---|
bool | True if there's captain specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/captain_extras.py
ChatExtras dataclass
¶
ChatExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
chat_prerequisites: str = "",
chat_initiation: str = "",
chat_registration: str = "",
)
Bases: BaseExtras
Extras for chat exporters.
Attributes:
Name | Type | Description |
---|---|---|
chat_definition | str | The chat definition content. |
chat_initiation | str | The chat initiation content. |
add_registration ¶
add_registration(registration: str) -> None
Add chat registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
registration | str | The chat registration content. | required |
Source code in waldiez/exporting/core/extras/chat_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for chat specific content.
Returns:
Type | Description |
---|---|
bool | True if there's chat specific content. |
Source code in waldiez/exporting/core/extras/chat_extras.py
set_chat_initiation ¶
set_chat_initiation(initiation: str) -> None
Set the chat initiation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initiation | str | The chat initiation content. | required |
set_chat_prerequisites ¶
set_chat_prerequisites(prerequisites: str) -> None
Set the chat prerequisites.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prerequisites | str | The chat prerequisites content. | required |
CodeExecutionConfig dataclass
¶
CodeExecutionConfig(
executor_content: str = "",
executor_argument: str = "False",
executor_import: ImportStatement | None = None,
)
ConfigurableExporter ¶
Bases: Exporter[Extras]
Exporter with configuration support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Optional[Dict[str, Any]] | Configuration dictionary, by default None | None |
**kwargs | Any | Additional keyword arguments. | {} |
Source code in waldiez/exporting/core/exporters.py
get_config_value ¶
Get a configuration value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | The configuration key. | required |
default | Any | Default value if key not found, by default None | None |
Returns:
Type | Description |
---|---|
Any | The configuration value or default. |
Source code in waldiez/exporting/core/exporters.py
ContentGenerator ¶
Bases: Protocol
Protocol for generating content.
generate ¶
generate(
merged_result: ExportResult,
is_async: bool,
after_run: str,
**kwargs: Any
) -> str
Generate content based on provided parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
merged_result | ExportResult | The merged export result containing all content. | required |
is_async | bool | Whether to generate async content. | required |
after_run | str | Additional content to add after the main flow execution. | required |
**kwargs | Any | Parameters to influence content generation. | {} |
Returns:
Type | Description |
---|---|
str | The generated content. |
Source code in waldiez/exporting/core/protocols.py
ContentMetadata dataclass
¶
ContentMetadata(
content_type: ContentType,
source_id: Optional[str] = None,
dependencies: list[str] = list[str](),
tags: set[str] = set[str](),
)
Metadata about exported content.
DefaultPathResolver ¶
Bases: PathResolver
Default path resolver for Waldiez items.
resolve ¶
Resolve a path to a local file system path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Union[str, Path] | The path to resolve. | required |
Returns:
Type | Description |
---|---|
Optional[Path] | The resolved local path or None if not found. |
Source code in waldiez/exporting/core/extras/path_resolver.py
DefaultSerializer ¶
Bases: Serializer
Default serializer for Waldiez items.
serialize ¶
Serialize an item to a formatted string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The item to serialize. | required |
**kwargs | Any | Additional keyword arguments, such as | {} |
Returns:
Type | Description |
---|---|
str | The serialized string representation of the item. |
Source code in waldiez/exporting/core/extras/serializer.py
EnvironmentVariable dataclass
¶
EnvironmentVariable(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
)
ExportConfig dataclass
¶
ExportConfig(
name: str = "Waldiez Flow",
description: str = "Make AG2 Agents Collaborate: Drag, Drop, and Orchestrate with Waldiez",
requirements: list[str] = list[str](),
tags: list[str] = list[str](),
output_extension: str = "py",
is_async: bool = False,
output_directory: Optional[str | Path] = None,
uploads_root: Optional[Path] = None,
cache_seed: Optional[int] = None,
structured_io: bool = False,
skip_patch_io: bool = True,
)
Configuration for export operations.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of the export. |
description | str | A brief description of the export. |
requirements | list[str] | A list of requirements for the export. |
tags | list[str] | A list of tags associated with the export. |
output_directory | Optional[str | Path] | The directory where the exported content will be saved. |
uploads_root | Optional[str | Path] | The root directory for uploads, if applicable. |
cache_seed | Optional[int] | The seed for caching, if applicable. |
structured_io | bool | Whether the export should use structured I/O. |
output_extension | str | The file extension for the exported content. |
is_async | bool | Whether the exported content should be asynchronous. |
skip_patch_io | bool | Whether to skip patching I/O operations. |
create classmethod
¶
create(**kwargs: Any) -> ExportConfig
Create a new ExportConfig instance with the provided values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Keyword arguments to initialize the ExportConfig. | {} |
Returns:
Type | Description |
---|---|
ExportConfig | A new instance of ExportConfig. |
Source code in waldiez/exporting/core/types.py
for_notebook property
¶
for_notebook: bool
Check if the export is intended for a notebook environment.
Returns:
Type | Description |
---|---|
bool | True if the output extension is 'ipynb', otherwise False. |
update ¶
update(**kwargs: Any) -> None
Update the export configuration with new values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Keyword arguments to update the configuration. | {} |
Raises:
Type | Description |
---|---|
ValueError | If an invalid configuration key is provided. |
Source code in waldiez/exporting/core/types.py
ExportContributor ¶
Bases: Protocol
Protocol for objects that can contribute to exports.
contribute_to_export ¶
contribute_to_export(result: ExportResult) -> None
Contribute content to the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | ExportResult | The export result to contribute to. | required |
ExportPosition ¶
Bases: Enum
Position for content in the exported code.
Attributes:
Name | Type | Description |
---|---|---|
TOP | int | Position at the top of the file, typically for comments or metadata. |
IMPORTS | int | Position for import statements. |
TOOLS | int | Position for tool definitions. |
MODELS | int | Position for model configurations (llm_config). |
AGENTS | int | Position for agent definitions. |
CHATS | int | Position for chat/connection definitions. |
BOTTOM | int | Position at the bottom of the file, typically for main execution or final code. |
ExportResult dataclass
¶
ExportResult(
main_content: Optional[str] = None,
imports: set[ImportStatement] = set[ImportStatement](),
positioned_content: list[PositionedContent] = list[
PositionedContent
](),
instance_arguments: list[InstanceArgument] = list[
InstanceArgument
](),
environment_variables: list[EnvironmentVariable] = list[
EnvironmentVariable
](),
validation_result: Optional[ValidationResult] = None,
metadata: dict[str, Any] = dict[str, Any](),
)
Complete export result with all components.
add_content ¶
add_content(
content: str,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
order: Union[ContentOrder, int] = MAIN_CONTENT,
skip_strip: bool = False,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
metadata: Optional[dict[str, Any]] = None,
) -> None
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The position of the content, by default AGENTS | DEFAULT_EXPORT_POSITION |
order | int | The order within the position, by default 0 | MAIN_CONTENT |
skip_strip | bool | Whether to skip stripping whitespace from content, by default False | False |
agent_id | Optional[str] | The agent ID if positioned relative to an agent, by default None | None |
agent_position | Optional[AgentPosition] | The position relative to the agent, by default None | None |
metadata | Optional[dict[str, Any]] | Additional metadata for the content, by default None | None |
Source code in waldiez/exporting/core/result.py
add_env_var ¶
add_env_var(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
) -> None
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the environment variable. | required |
value | str | The value of the environment variable. | required |
description | Optional[str] | Description of the variable, by default None | None |
required | bool | Whether the variable is required, by default True | True |
Source code in waldiez/exporting/core/result.py
add_import ¶
add_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement to add. | required |
position | ImportPosition | The position of the import, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/result.py
add_imports ¶
add_imports(
statements: Union[
set[str],
list[str],
set[ImportStatement],
list[ImportStatement],
],
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements | Union[ |
] The import statements to add. | required |
position | ImportPosition | The position of the imports, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/result.py
add_instance_argument ¶
add_instance_argument(
name: str,
value: Any,
instance_id: str,
tabs: int = 0,
comment: Optional[str] = None,
) -> None
Add an instance argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the argument. | required |
value | Any | The value of the argument. | required |
instance_id | str | The ID of the instance this argument belongs to. | required |
tabs | int | Number of tabs for indentation, by default 0 | 0 |
comment | Optional[str] | Optional comment for the argument, by default None | None |
Source code in waldiez/exporting/core/result.py
add_instance_arguments ¶
add_instance_arguments(
arguments: Union[
list[InstanceArgument], set[InstanceArgument]
],
) -> None
Add multiple instance arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arguments | Union[list[InstanceArgument], set[InstanceArgument]] | The instance arguments to add. | required |
Source code in waldiez/exporting/core/result.py
clear ¶
Clear all content from the result.Source code in
waldiez/exporting/core/result.py
get_agent_content ¶
get_agent_content(
agent_id: str,
agent_position: Optional[AgentPosition] = None,
) -> list[PositionedContent]
Get content positioned relative to a specific agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id | str | The ID of the agent. | required |
agent_position | Optional[AgentPosition] | Filter by specific agent position, by default None (all positions) | None |
Returns:
Type | Description |
---|---|
list[PositionedContent] | Sorted list of content for the specified agent. |
Source code in waldiez/exporting/core/result.py
get_all_content_sorted ¶
get_all_content_sorted() -> list[PositionedContent]
Get all positioned content sorted by position and order.
Returns:
Type | Description |
---|---|
list[PositionedContent] | All positioned content sorted. |
Source code in waldiez/exporting/core/result.py
get_content_by_position ¶
get_content_by_position(
position: ExportPosition,
skip_agent_arguments: bool = True,
) -> list[PositionedContent]
Get all content for a specific position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ExportPosition | The position to filter by. | required |
skip_agent_arguments | bool | Whether to skip content positioned as agent arguments, by default True | True |
Returns:
Type | Description |
---|---|
list[PositionedContent] | Sorted list of content for the specified position. |
Source code in waldiez/exporting/core/result.py
get_imports_by_position ¶
get_imports_by_position(
position: ImportPosition,
) -> list[ImportStatement]
Get imports filtered by position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ImportPosition | The position to filter by. | required |
Returns:
Type | Description |
---|---|
list[ImportStatement] | list of imports for the specified position. |
Source code in waldiez/exporting/core/result.py
get_sorted_imports ¶
get_sorted_imports() -> list[ImportStatement]
Get imports sorted by position and statement.
Returns:
Type | Description |
---|---|
list[ImportStatement] | Sorted list of import statements. |
get_statistics ¶
Get statistics about the export result.
Returns:
Type | Description |
---|---|
dict[str, int] | dictionary with statistics about the export. |
Source code in waldiez/exporting/core/result.py
has_content ¶
has_content() -> bool
Check if there's any meaningful content.
Returns:
Type | Description |
---|---|
bool | True if there's any content, imports, or environment variables. |
Source code in waldiez/exporting/core/result.py
has_errors ¶
has_errors() -> bool
Check if there are validation errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors. |
Source code in waldiez/exporting/core/result.py
has_warnings ¶
has_warnings() -> bool
Check if there are validation warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings. |
Source code in waldiez/exporting/core/result.py
merge ¶
merge(
other: ExportResult,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
) -> None
Merge another ExportResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ExportResult | The other result to merge. | required |
position | ExportPosition | The position for the merged content, by default AGENTS | DEFAULT_EXPORT_POSITION |
Source code in waldiez/exporting/core/result.py
merge_with ¶
merge_with(other: ExportResult) -> None
Merge another ExportResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ExportResult | The other result to merge. | required |
Source code in waldiez/exporting/core/result.py
ExportResultBuilder dataclass
¶
ExportResultBuilder(_result: ExportResult = ExportResult())
Builder pattern for constructing ExportResult objects.
build ¶
build() -> ExportResult
with_content ¶
with_content(
content: str,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
order: ContentOrder = MAIN_CONTENT,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
) -> ExportResultBuilder
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The content position, by default AGENTS | DEFAULT_EXPORT_POSITION |
order | int | The order within position, by default 0 | MAIN_CONTENT |
agent_id | Optional[str] | Agent ID for agent-relative positioning, by default None | None |
agent_position | Optional[AgentPosition] | Position relative to agent, by default None | None |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_env_var ¶
with_env_var(
name: str, value: str, description: Optional[str] = None
) -> ExportResultBuilder
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Variable name. | required |
value | str | Variable value. | required |
description | Optional[str] | Variable description, by default None | None |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_import ¶
with_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> ExportResultBuilder
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement. | required |
position | ImportPosition | The import position, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_main_content ¶
with_main_content(content: str) -> ExportResultBuilder
Set the main content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The main content to set. | required |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_metadata ¶
with_metadata(key: str, value: Any) -> ExportResultBuilder
Add metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | Metadata key. | required |
value | Any | Metadata value. | required |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
Exporter ¶
Exporter(
context: Optional[ExporterContext] = None, **kwargs: Any
)
Exporter base class with structured extras and clean interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context | Optional[ExporterContext] | The exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for subclasses. | {} |
Source code in waldiez/exporting/core/exporter.py
add_content ¶
add_content(
content: str,
position: ExportPosition,
order: ContentOrder = MAIN_CONTENT,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
skip_strip: bool | None = None,
**metadata: Any
) -> None
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The position of the content. | required |
order | int | The order within the position, by default 0 | MAIN_CONTENT |
agent_id | Optional[str] | Agent ID for agent-relative positioning, by default None | None |
agent_position | Optional[AgentPosition] | Position relative to agent, by default None | None |
skip_strip | bool | None | Whether to skip stripping whitespace, by default None If None, defaults to True for CHATS position (keep identation), | None |
**metadata | Any | Additional metadata for the content. | {} |
Source code in waldiez/exporting/core/exporter.py
add_env_var ¶
add_env_var(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
) -> None
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the environment variable. | required |
value | str | The value of the environment variable. | required |
description | Optional[str] | Description of the variable, by default None | None |
required | bool | Whether the variable is required, by default True | True |
Source code in waldiez/exporting/core/exporter.py
add_import ¶
add_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement to add. | required |
position | ImportPosition | The position of the import, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/exporter.py
add_imports ¶
add_imports(
statements: set[str],
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements | Set[str] | The import statements to add. | required |
position | ImportPosition | The position of the imports, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/exporter.py
clear ¶
context property
¶
context: ExporterContext
export ¶
export() -> ExportResult
Export and return the complete result.
Returns:
Type | Description |
---|---|
ExportResult | The complete export result. |
extras abstractmethod
property
¶
Get the structured extras for this exporter.
Returns:
Type | Description |
---|---|
Extras | The extras instance. |
generate_main_content abstractmethod
¶
get_content_by_position ¶
get_content_by_position(
position: ExportPosition,
) -> list[PositionedContent]
Get content for a specific position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ExportPosition | The position to filter by. | required |
Returns:
Type | Description |
---|---|
List[PositionedContent] | List of content for the specified position. |
Source code in waldiez/exporting/core/exporter.py
get_environment_variables ¶
get_environment_variables() -> list[EnvironmentVariable]
Get environment variables.
Returns:
Type | Description |
---|---|
List[EnvironmentVariable] | List of environment variables. |
Source code in waldiez/exporting/core/exporter.py
get_imports ¶
get_imports() -> list[ImportStatement]
Get sorted imports.
Returns:
Type | Description |
---|---|
List[ImportStatement] | Sorted list of import statements. |
Source code in waldiez/exporting/core/exporter.py
get_metadata ¶
Get metadata from the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | The metadata key. | required |
default | Any | Default value if key not found, by default None | None |
Returns:
Type | Description |
---|---|
Any | The metadata value or default. |
Source code in waldiez/exporting/core/exporter.py
get_statistics ¶
has_content ¶
has_content() -> bool
has_errors ¶
has_errors() -> bool
Check if there are validation errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors. |
has_warnings ¶
has_warnings() -> bool
Check if there are validation warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings. |
reset ¶
ExporterContentError ¶
Bases: ExporterError
Exception raised when content generation fails.
ExporterContext dataclass
¶
ExporterContext(
serializer: Optional[Serializer] = None,
path_resolver: Optional[PathResolver] = None,
validator: Optional[Validator] = None,
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
)
Context object containing common exporter dependencies.
get_config ¶
get_config(
name: Optional[str] = None,
description: Optional[str] = None,
requirements: Optional[list[str]] = None,
tags: Optional[list[str]] = None,
output_extension: Optional[str] = None,
is_async: bool = False,
output_directory: Optional[str] = None,
cache_seed: Optional[int] = None,
structured_io: bool = False,
skip_patch_io: bool = True,
) -> ExportConfig
Get export config or return default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | Optional[str] | The name of the export, by default None | None |
description | Optional[str] | A brief description of the export, by default None | None |
requirements | Optional[list[str]] | A list of requirements for the export, by default None | None |
tags | Optional[list[str]] | A list of tags associated with the export, by default None | None |
output_extension | Optional[str] | The file extension for the output, by default None | None |
is_async | bool | Whether the export is asynchronous, by default False | False |
output_directory | Optional[str] | The directory where the output will be saved, by default None | None |
cache_seed | Optional[int] | The seed for caching, by default None | None |
structured_io | bool | Whether to use structured I/O, by default False | False |
skip_patch_io | bool | Whether to skip patching I/O, by default True | True |
Returns:
Type | Description |
---|---|
ExportConfig | The export configuration. |
Source code in waldiez/exporting/core/context.py
get_logger ¶
get_logger() -> ExportingLogger
get_path_resolver ¶
get_path_resolver() -> PathResolver
get_serializer ¶
get_serializer() -> Serializer
set_config ¶
set_config(config: ExportConfig) -> None
Set the export configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | ExportConfig | The export configuration to set. | required |
ExporterInitializationError ¶
Bases: ExporterError
Exception raised when exporter initialization fails.
ExporterValidationError ¶
Bases: ExporterError
Exception raised when export validation fails.
ExportingLogger ¶
Bases: Protocol
Protocol for logging during exporting.
critical ¶
Log a critical error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The critical error message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
debug ¶
Log a debug message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The debug message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
error ¶
Log an error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The error message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
exception ¶
Log an exception message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The exception message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
info ¶
Log an informational message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The informational message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
log ¶
Log a message with the specified level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The message to log or message template for formatting. | required |
level | str | The logging level to use (e.g., "debug", "info", "warning", "error", "critical"). Defaults to "info". | 'info' |
*args | Any | Arguments to format into the message using % formatting. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
set_level ¶
set_level(level: str) -> None
Set the logging level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level | str | The logging level to set (e.g., "debug", "info", "warning", "error", "critical"). | required |
Raises:
Type | Description |
---|---|
ValueError | If the provided level is invalid. |
Source code in waldiez/exporting/core/protocols.py
success ¶
Log a success message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The success message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
warning ¶
Log a warning message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The warning message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
GroupManagerExtras dataclass
¶
GroupManagerExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
strategy: GroupManagerStrategy = PATTERN,
pattern_definition: str = "",
pattern_class_name: str = "AutoPattern",
pattern_imports: set[str] = set[str](),
group_chat_definition: str = "",
group_chat_name: str = "",
group_chat_argument: str = "",
custom_speaker_selection: str = "",
context_variables_content: str = "",
after_work_content: str = "",
)
Bases: StandardExtras
Extras for group manager agents.
has_specific_content ¶
has_specific_content() -> bool
Check if group manager has specific content.
Returns:
Type | Description |
---|---|
bool | True if there is specific content for the group manager, |
Source code in waldiez/exporting/core/extras/agent_extras/group_manager_extras.py
ImportStatement dataclass
¶
ImportStatement(
statement: str,
position: ImportPosition = THIRD_PARTY,
metadata: Optional[dict[str, Any]] = None,
)
Represents an import statement with its position.
InstanceArgument dataclass
¶
InstanceArgument(
instance_id: str,
name: str,
value: Any,
tabs: int = 0,
tabs_length: int = 4,
with_new_line_before: bool = False,
with_new_line_after: bool = False,
with_new_line_if_empty: bool = False,
skip_if_empty_string: bool = True,
comment: Optional[str] = None,
)
Represents an instance argument for an agent, model or tool.
get_content ¶
Get the content representation of the instance argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prepend_new_line | bool | Whether to prepend a new line before the content, by default False. | False |
append_new_line | bool | Whether to append a new line at the end of the content, by default False. | False |
Returns:
Type | Description |
---|---|
str | The formatted content string for the instance argument. |
Source code in waldiez/exporting/core/types.py
has_content ¶
has_content() -> bool
Check if the instance argument has content.
Returns:
Type | Description |
---|---|
bool | True if the instance argument has content, otherwise False. |
Source code in waldiez/exporting/core/types.py
ModelExtras dataclass
¶
ModelExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
llm_config: Optional[dict[str, Any]] = None,
config_file_path: str = "",
)
Bases: BaseExtras
Extras for model exporters.
get_content ¶
get_content() -> str
Get the content of the LLM configuration.
Returns:
Type | Description |
---|---|
str | The serialized LLM configuration. |
Source code in waldiez/exporting/core/extras/model_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for model specific content.
Returns:
Type | Description |
---|---|
bool | True if there's model specific content. |
Source code in waldiez/exporting/core/extras/model_extras.py
set_config_file_path ¶
set_config_file_path(path: str) -> None
Set the configuration file path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The configuration file path. | required |
PathResolver ¶
Bases: Protocol
Protocol for resolving a path.
resolve ¶
Resolve a path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The path to resolve. | required |
Returns:
Type | Description |
---|---|
str | The resolved path. |
Raises:
Type | Description |
---|---|
ValueError | If the path cannot be resolved. |
Source code in waldiez/exporting/core/protocols.py
PositionedContent dataclass
¶
PositionedContent(
content: str,
position: ExportPosition,
order: int = 0,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
metadata: dict[str, Any] = dict[str, Any](),
)
RAGUserExtras dataclass
¶
RAGUserExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
before_content: str = "",
imports: set[str] = set[str](),
)
Bases: StandardExtras
RAG configuration.
ReasoningExtras dataclass
¶
ReasoningExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: StandardExtras
Extras for reasoning agents.
has_specific_content ¶
has_specific_content() -> bool
Check for reasoning specific content.
Returns:
Type | Description |
---|---|
bool | True if there's reasoning specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/reasoning_extras.py
Serializer ¶
Bases: Protocol
Protocol for serialization components.
SimpleExporter ¶
SimpleExporter(
context: Optional[ExporterContext] = None, **kwargs: Any
)
Bases: Exporter[None]
Simple exporter that doesn't use extras system.Source code in
waldiez/exporting/core/exporter.py
StandardExtras dataclass
¶
StandardExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: BaseExtras
Extras for standard agents (UserProxy, Assistant, etc.).
get_code_execution_arg ¶
get_code_execution_arg() -> InstanceArgument
Get the code execution argument string.
Returns:
Type | Description |
---|---|
InstanceArgument | The code execution argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_system_message_arg ¶
get_system_message_arg() -> InstanceArgument
Get the system message argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The system message argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_termination_arg ¶
get_termination_arg() -> InstanceArgument
Get the termination argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The termination argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for standard agent specific content.
Returns:
Type | Description |
---|---|
bool | True if there's standard agent specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_code_execution ¶
set_code_execution(config: CodeExecutionConfig) -> None
Set code execution configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | CodeExecutionConfig | The code execution configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_system_message_config ¶
set_system_message_config(
config: SystemMessageConfig,
) -> None
Set system message configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SystemMessageConfig | The system message configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_termination_config ¶
set_termination_config(config: TerminationConfig) -> None
Set termination configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | TerminationConfig | The termination configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
SystemMessageConfig dataclass
¶
TerminationConfig dataclass
¶
ToolExtras dataclass
¶
ToolExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
function_content: str = "",
registration_content: str = "",
)
Bases: BaseExtras
Extras for tool exporters.
add_function_content ¶
add_function_content(content: str) -> None
Add function definition content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The function content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
add_registration_content ¶
add_registration_content(content: str) -> None
Add function registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The registration content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
ValidationError dataclass
¶
ValidationError(
message: str,
severity: str = "error",
location: Optional[str] = None,
suggestion: Optional[str] = None,
)
Represents a validation error.
ValidationResult dataclass
¶
ValidationResult(
is_valid: bool,
errors: list[ValidationError] = list[ValidationError](),
warnings: list[ValidationError] = list[
ValidationError
](),
)
Result of validation operations.
add_error ¶
add_error(
message: str,
location: Optional[str] = None,
suggestion: Optional[str] = None,
) -> None
Add a validation error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | str | The error message to add. | required |
location | Optional[str] | The location in the code where the error occurred, by default None | None |
suggestion | Optional[str] | A suggestion for fixing the error, by default None | None |
Source code in waldiez/exporting/core/validation.py
add_warning ¶
Add a validation warning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | str | The warning message to add. | required |
location | Optional[str] | The location in the code where the warning occurred, by default None | None |
Source code in waldiez/exporting/core/validation.py
has_errors ¶
has_errors() -> bool
Check if there are any errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors, otherwise False. |
has_warnings ¶
has_warnings() -> bool
Check if there are any warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings, otherwise False. |
merge ¶
merge(other: ValidationResult) -> None
Merge another ValidationResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ValidationResult | The other validation result to merge. | required |
Source code in waldiez/exporting/core/validation.py
Validator ¶
Bases: Protocol
Protocol for validation components.
validate ¶
validate(content: Any) -> ValidationResult
Validate content and return result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | Any | The content to validate. | required |
Returns:
Type | Description |
---|---|
ValidationResult | The validation result. |
Source code in waldiez/exporting/core/protocols.py
constants ¶
Constants for Waldiez exporting core.
content ¶
Content module for Waldiez exporting core.
ContentMetadata dataclass
¶
ContentMetadata(
content_type: ContentType,
source_id: Optional[str] = None,
dependencies: list[str] = list[str](),
tags: set[str] = set[str](),
)
Metadata about exported content.
PositionedContent dataclass
¶
PositionedContent(
content: str,
position: ExportPosition,
order: int = 0,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
metadata: dict[str, Any] = dict[str, Any](),
)
context ¶
Singleton context for exporters.
DefaultExporterContext ¶
DefaultExporterContext(
serializer: Optional[Serializer] = None,
validator: Optional[Validator] = None,
path_resolver: Optional[PathResolver] = None,
logger: Optional[ExportingLogger] = None,
config: Optional[ExportConfig] = None,
)
Bases: ExporterContext
Singleton context for exporters.
Provides a default configuration with standard serializer and escaper. Access via get_default_exporter_context() for proper initialization. This is a singleton - only one instance exists per application. Direct instantiation may not behave as expected.Note
Source code in
waldiez/exporting/core/context.py
ExporterContext dataclass
¶
ExporterContext(
serializer: Optional[Serializer] = None,
path_resolver: Optional[PathResolver] = None,
validator: Optional[Validator] = None,
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
)
Context object containing common exporter dependencies.
get_config ¶
get_config(
name: Optional[str] = None,
description: Optional[str] = None,
requirements: Optional[list[str]] = None,
tags: Optional[list[str]] = None,
output_extension: Optional[str] = None,
is_async: bool = False,
output_directory: Optional[str] = None,
cache_seed: Optional[int] = None,
structured_io: bool = False,
skip_patch_io: bool = True,
) -> ExportConfig
Get export config or return default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | Optional[str] | The name of the export, by default None | None |
description | Optional[str] | A brief description of the export, by default None | None |
requirements | Optional[list[str]] | A list of requirements for the export, by default None | None |
tags | Optional[list[str]] | A list of tags associated with the export, by default None | None |
output_extension | Optional[str] | The file extension for the output, by default None | None |
is_async | bool | Whether the export is asynchronous, by default False | False |
output_directory | Optional[str] | The directory where the output will be saved, by default None | None |
cache_seed | Optional[int] | The seed for caching, by default None | None |
structured_io | bool | Whether to use structured I/O, by default False | False |
skip_patch_io | bool | Whether to skip patching I/O, by default True | True |
Returns:
Type | Description |
---|---|
ExportConfig | The export configuration. |
Source code in waldiez/exporting/core/context.py
get_logger ¶
get_logger() -> ExportingLogger
get_path_resolver ¶
get_path_resolver() -> PathResolver
get_serializer ¶
get_serializer() -> Serializer
set_config ¶
set_config(config: ExportConfig) -> None
Set the export configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | ExportConfig | The export configuration to set. | required |
create_exporter_context ¶
create_exporter_context(
serializer: Optional[Serializer] = None,
validator: Optional[Validator] = None,
path_resolver: Optional[PathResolver] = None,
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
) -> ExporterContext
Create an exporter context with the given components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serializer | Optional[Serializer] | The serializer component, by default None | None |
path_resolver | Optional[PathResolver] | The path resolver component, by default None | None |
validator | Optional[Validator] | The validator component, by default None | None |
config | Optional[ExportConfig] | The export configuration, by default None | None |
logger | Optional[ExportingLogger] | The logger instance, by default None | None |
Returns:
Type | Description |
---|---|
ExporterContext | The created context. |
Source code in waldiez/exporting/core/context.py
get_default_exporter_context ¶
get_default_exporter_context(
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
) -> ExporterContext
Get the default exporter context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Optional[ExportConfig] | The export configuration, by default None | None |
logger | Optional[ExportingLogger] | The logger instance, by default None | None |
Returns:
Type | Description |
---|---|
ExporterContext | The default exporter context. |
Source code in waldiez/exporting/core/context.py
create_empty_result ¶
create_empty_result() -> ExportResult
create_exporter_context ¶
create_exporter_context(
serializer: Optional[Serializer] = None,
validator: Optional[Validator] = None,
path_resolver: Optional[PathResolver] = None,
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
) -> ExporterContext
Create an exporter context with the given components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serializer | Optional[Serializer] | The serializer component, by default None | None |
path_resolver | Optional[PathResolver] | The path resolver component, by default None | None |
validator | Optional[Validator] | The validator component, by default None | None |
config | Optional[ExportConfig] | The export configuration, by default None | None |
logger | Optional[ExportingLogger] | The logger instance, by default None | None |
Returns:
Type | Description |
---|---|
ExporterContext | The created context. |
Source code in waldiez/exporting/core/context.py
create_result_with_content ¶
create_result_with_content(
main_content: str, imports: Optional[list[str]] = None
) -> ExportResult
Create an ExportResult with basic content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_content | str | The main content. | required |
imports | Optional[list[str]] | list of import statements, by default None | None |
Returns:
Type | Description |
---|---|
ExportResult | The created ExportResult. |
Source code in waldiez/exporting/core/result.py
enums ¶
Enums for Waldiez exporting core.
ExportPosition ¶
Bases: Enum
Position for content in the exported code.
Attributes:
Name | Type | Description |
---|---|---|
TOP | int | Position at the top of the file, typically for comments or metadata. |
IMPORTS | int | Position for import statements. |
TOOLS | int | Position for tool definitions. |
MODELS | int | Position for model configurations (llm_config). |
AGENTS | int | Position for agent definitions. |
CHATS | int | Position for chat/connection definitions. |
BOTTOM | int | Position at the bottom of the file, typically for main execution or final code. |
errors ¶
Exporter core exceptions module.
ExporterContentError ¶
Bases: ExporterError
Exception raised when content generation fails.
ExporterInitializationError ¶
Bases: ExporterError
Exception raised when exporter initialization fails.
ExporterValidationError ¶
Bases: ExporterError
Exception raised when export validation fails.
exporter ¶
Base exporter classes.
Exporter ¶
Exporter(
context: Optional[ExporterContext] = None, **kwargs: Any
)
Exporter base class with structured extras and clean interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context | Optional[ExporterContext] | The exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for subclasses. | {} |
Source code in waldiez/exporting/core/exporter.py
add_content ¶
add_content(
content: str,
position: ExportPosition,
order: ContentOrder = MAIN_CONTENT,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
skip_strip: bool | None = None,
**metadata: Any
) -> None
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The position of the content. | required |
order | int | The order within the position, by default 0 | MAIN_CONTENT |
agent_id | Optional[str] | Agent ID for agent-relative positioning, by default None | None |
agent_position | Optional[AgentPosition] | Position relative to agent, by default None | None |
skip_strip | bool | None | Whether to skip stripping whitespace, by default None If None, defaults to True for CHATS position (keep identation), | None |
**metadata | Any | Additional metadata for the content. | {} |
Source code in waldiez/exporting/core/exporter.py
add_env_var ¶
add_env_var(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
) -> None
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the environment variable. | required |
value | str | The value of the environment variable. | required |
description | Optional[str] | Description of the variable, by default None | None |
required | bool | Whether the variable is required, by default True | True |
Source code in waldiez/exporting/core/exporter.py
add_import ¶
add_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement to add. | required |
position | ImportPosition | The position of the import, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/exporter.py
add_imports ¶
add_imports(
statements: set[str],
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements | Set[str] | The import statements to add. | required |
position | ImportPosition | The position of the imports, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/exporter.py
clear ¶
context property
¶
context: ExporterContext
export ¶
export() -> ExportResult
Export and return the complete result.
Returns:
Type | Description |
---|---|
ExportResult | The complete export result. |
extras abstractmethod
property
¶
Get the structured extras for this exporter.
Returns:
Type | Description |
---|---|
Extras | The extras instance. |
generate_main_content abstractmethod
¶
get_content_by_position ¶
get_content_by_position(
position: ExportPosition,
) -> list[PositionedContent]
Get content for a specific position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ExportPosition | The position to filter by. | required |
Returns:
Type | Description |
---|---|
List[PositionedContent] | List of content for the specified position. |
Source code in waldiez/exporting/core/exporter.py
get_environment_variables ¶
get_environment_variables() -> list[EnvironmentVariable]
Get environment variables.
Returns:
Type | Description |
---|---|
List[EnvironmentVariable] | List of environment variables. |
Source code in waldiez/exporting/core/exporter.py
get_imports ¶
get_imports() -> list[ImportStatement]
Get sorted imports.
Returns:
Type | Description |
---|---|
List[ImportStatement] | Sorted list of import statements. |
Source code in waldiez/exporting/core/exporter.py
get_metadata ¶
Get metadata from the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | The metadata key. | required |
default | Any | Default value if key not found, by default None | None |
Returns:
Type | Description |
---|---|
Any | The metadata value or default. |
Source code in waldiez/exporting/core/exporter.py
get_statistics ¶
has_content ¶
has_content() -> bool
has_errors ¶
has_errors() -> bool
Check if there are validation errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors. |
has_warnings ¶
has_warnings() -> bool
Check if there are validation warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings. |
reset ¶
exporters ¶
Exporters for Waldiez.
ConfigurableExporter ¶
Bases: Exporter[Extras]
Exporter with configuration support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Optional[Dict[str, Any]] | Configuration dictionary, by default None | None |
**kwargs | Any | Additional keyword arguments. | {} |
Source code in waldiez/exporting/core/exporters.py
get_config_value ¶
Get a configuration value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | The configuration key. | required |
default | Any | Default value if key not found, by default None | None |
Returns:
Type | Description |
---|---|
Any | The configuration value or default. |
Source code in waldiez/exporting/core/exporters.py
SimpleExporter ¶
SimpleExporter(
context: Optional[ExporterContext] = None, **kwargs: Any
)
Bases: Exporter[None]
Simple exporter that doesn't use extras system.Source code in
waldiez/exporting/core/exporter.py
extras ¶
Extras for Waldiez exporting core module.
BaseExtras dataclass
¶
BaseExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
)
Bases: ExportContributor
Base class for all exporter extras with export contribution.
add_arg ¶
add_arg(arg: InstanceArgument | str, tabs: int = 0) -> None
Add an extra argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg | InstanceArgument | The argument to add. | required |
tabs | int | The number of tabs to indent the argument, by default 0. | 0 |
Source code in waldiez/exporting/core/extras/base.py
add_import ¶
add_import(import_statement: ImportStatement) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
import_statement | str | The import statement to add. | required |
Source code in waldiez/exporting/core/extras/base.py
add_imports ¶
add_imports(imports: Sequence[ImportStatement]) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imports | Set[str] | The import statements to add. | required |
append_after_agent ¶
append_after_agent(content: str) -> None
Append content to the after_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_after_all_agents ¶
append_after_all_agents(content: str) -> None
Append content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_before_agent ¶
append_before_agent(content: str) -> None
Append content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
contribute_to_export ¶
contribute_to_export(result: ExportResult) -> None
Contribute this extras' content to the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | ExportResult | The export result to contribute to. | required |
Source code in waldiez/exporting/core/extras/base.py
get_extra_args_content ¶
get_extra_args_content() -> str
has_content ¶
has_content() -> bool
Check if there's any meaningful content.
Returns:
Type | Description |
---|---|
bool | True if there's any content in this extras instance. |
Source code in waldiez/exporting/core/extras/base.py
has_specific_content abstractmethod
¶
has_specific_content() -> bool
Check if there's subclass-specific content.
Returns:
Type | Description |
---|---|
bool | True if there's specific content for this extras type. |
prepend_after_all_agents ¶
prepend_after_all_agents(content: str) -> None
Prepend content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
prepend_before_agent ¶
prepend_before_agent(content: str) -> None
Prepend content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
CaptainExtras dataclass
¶
CaptainExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
nested_config: Optional[dict[str, Any]] = None,
)
Bases: StandardExtras
Extras for captain agents.
has_specific_content ¶
has_specific_content() -> bool
Check for captain specific content.
Returns:
Type | Description |
---|---|
bool | True if there's captain specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/captain_extras.py
ChatExtras dataclass
¶
ChatExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
chat_prerequisites: str = "",
chat_initiation: str = "",
chat_registration: str = "",
)
Bases: BaseExtras
Extras for chat exporters.
Attributes:
Name | Type | Description |
---|---|---|
chat_definition | str | The chat definition content. |
chat_initiation | str | The chat initiation content. |
add_registration ¶
add_registration(registration: str) -> None
Add chat registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
registration | str | The chat registration content. | required |
Source code in waldiez/exporting/core/extras/chat_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for chat specific content.
Returns:
Type | Description |
---|---|
bool | True if there's chat specific content. |
Source code in waldiez/exporting/core/extras/chat_extras.py
set_chat_initiation ¶
set_chat_initiation(initiation: str) -> None
Set the chat initiation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initiation | str | The chat initiation content. | required |
set_chat_prerequisites ¶
set_chat_prerequisites(prerequisites: str) -> None
Set the chat prerequisites.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prerequisites | str | The chat prerequisites content. | required |
CodeExecutionConfig dataclass
¶
CodeExecutionConfig(
executor_content: str = "",
executor_argument: str = "False",
executor_import: ImportStatement | None = None,
)
DefaultPathResolver ¶
Bases: PathResolver
Default path resolver for Waldiez items.
resolve ¶
Resolve a path to a local file system path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Union[str, Path] | The path to resolve. | required |
Returns:
Type | Description |
---|---|
Optional[Path] | The resolved local path or None if not found. |
Source code in waldiez/exporting/core/extras/path_resolver.py
DefaultSerializer ¶
Bases: Serializer
Default serializer for Waldiez items.
serialize ¶
Serialize an item to a formatted string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The item to serialize. | required |
**kwargs | Any | Additional keyword arguments, such as | {} |
Returns:
Type | Description |
---|---|
str | The serialized string representation of the item. |
Source code in waldiez/exporting/core/extras/serializer.py
FlowExtras dataclass
¶
FlowExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
flow_name: str = "",
description: str = "",
config: ExportConfig = ExportConfig(),
version: str = get_waldiez_version(),
tools_result: Optional[ExportResult] = None,
models_result: Optional[ExportResult] = None,
agents_result: Optional[ExportResult] = None,
chats_result: Optional[ExportResult] = None,
header_content: str = "",
main_function: str = "",
after_run: str = "",
execution_code: str = "",
)
Bases: BaseExtras
Extras for flow exporter.
has_specific_content ¶
has_specific_content() -> bool
Check if the flow extras contain specific content.
Returns:
Type | Description |
---|---|
bool | True if any specific content is present, False otherwise. |
Source code in waldiez/exporting/core/extras/flow_extras.py
GroupManagerExtras dataclass
¶
GroupManagerExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
strategy: GroupManagerStrategy = PATTERN,
pattern_definition: str = "",
pattern_class_name: str = "AutoPattern",
pattern_imports: set[str] = set[str](),
group_chat_definition: str = "",
group_chat_name: str = "",
group_chat_argument: str = "",
custom_speaker_selection: str = "",
context_variables_content: str = "",
after_work_content: str = "",
)
Bases: StandardExtras
Extras for group manager agents.
has_specific_content ¶
has_specific_content() -> bool
Check if group manager has specific content.
Returns:
Type | Description |
---|---|
bool | True if there is specific content for the group manager, |
Source code in waldiez/exporting/core/extras/agent_extras/group_manager_extras.py
ModelExtras dataclass
¶
ModelExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
llm_config: Optional[dict[str, Any]] = None,
config_file_path: str = "",
)
Bases: BaseExtras
Extras for model exporters.
get_content ¶
get_content() -> str
Get the content of the LLM configuration.
Returns:
Type | Description |
---|---|
str | The serialized LLM configuration. |
Source code in waldiez/exporting/core/extras/model_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for model specific content.
Returns:
Type | Description |
---|---|
bool | True if there's model specific content. |
Source code in waldiez/exporting/core/extras/model_extras.py
set_config_file_path ¶
set_config_file_path(path: str) -> None
Set the configuration file path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The configuration file path. | required |
RAGUserExtras dataclass
¶
RAGUserExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
before_content: str = "",
imports: set[str] = set[str](),
)
Bases: StandardExtras
RAG configuration.
ReasoningExtras dataclass
¶
ReasoningExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: StandardExtras
Extras for reasoning agents.
has_specific_content ¶
has_specific_content() -> bool
Check for reasoning specific content.
Returns:
Type | Description |
---|---|
bool | True if there's reasoning specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/reasoning_extras.py
StandardExtras dataclass
¶
StandardExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: BaseExtras
Extras for standard agents (UserProxy, Assistant, etc.).
get_code_execution_arg ¶
get_code_execution_arg() -> InstanceArgument
Get the code execution argument string.
Returns:
Type | Description |
---|---|
InstanceArgument | The code execution argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_system_message_arg ¶
get_system_message_arg() -> InstanceArgument
Get the system message argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The system message argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_termination_arg ¶
get_termination_arg() -> InstanceArgument
Get the termination argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The termination argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for standard agent specific content.
Returns:
Type | Description |
---|---|
bool | True if there's standard agent specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_code_execution ¶
set_code_execution(config: CodeExecutionConfig) -> None
Set code execution configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | CodeExecutionConfig | The code execution configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_system_message_config ¶
set_system_message_config(
config: SystemMessageConfig,
) -> None
Set system message configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SystemMessageConfig | The system message configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_termination_config ¶
set_termination_config(config: TerminationConfig) -> None
Set termination configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | TerminationConfig | The termination configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
SystemMessageConfig dataclass
¶
TerminationConfig dataclass
¶
ToolExtras dataclass
¶
ToolExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
function_content: str = "",
registration_content: str = "",
)
Bases: BaseExtras
Extras for tool exporters.
add_function_content ¶
add_function_content(content: str) -> None
Add function definition content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The function content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
add_registration_content ¶
add_registration_content(content: str) -> None
Add function registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The registration content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
agent_extras ¶
Agent specific extras module.
CaptainExtras dataclass
¶
CaptainExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
nested_config: Optional[dict[str, Any]] = None,
)
Bases: StandardExtras
Extras for captain agents.
has_specific_content ¶
has_specific_content() -> bool
Check for captain specific content.
Returns:
Type | Description |
---|---|
bool | True if there's captain specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/captain_extras.py
CodeExecutionConfig dataclass
¶
CodeExecutionConfig(
executor_content: str = "",
executor_argument: str = "False",
executor_import: ImportStatement | None = None,
)
GroupManagerExtras dataclass
¶
GroupManagerExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
strategy: GroupManagerStrategy = PATTERN,
pattern_definition: str = "",
pattern_class_name: str = "AutoPattern",
pattern_imports: set[str] = set[str](),
group_chat_definition: str = "",
group_chat_name: str = "",
group_chat_argument: str = "",
custom_speaker_selection: str = "",
context_variables_content: str = "",
after_work_content: str = "",
)
Bases: StandardExtras
Extras for group manager agents.
has_specific_content ¶
has_specific_content() -> bool
Check if group manager has specific content.
Returns:
Type | Description |
---|---|
bool | True if there is specific content for the group manager, |
Source code in waldiez/exporting/core/extras/agent_extras/group_manager_extras.py
RAGUserExtras dataclass
¶
RAGUserExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
before_content: str = "",
imports: set[str] = set[str](),
)
Bases: StandardExtras
RAG configuration.
ReasoningExtras dataclass
¶
ReasoningExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: StandardExtras
Extras for reasoning agents.
has_specific_content ¶
has_specific_content() -> bool
Check for reasoning specific content.
Returns:
Type | Description |
---|---|
bool | True if there's reasoning specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/reasoning_extras.py
StandardExtras dataclass
¶
StandardExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: BaseExtras
Extras for standard agents (UserProxy, Assistant, etc.).
get_code_execution_arg ¶
get_code_execution_arg() -> InstanceArgument
Get the code execution argument string.
Returns:
Type | Description |
---|---|
InstanceArgument | The code execution argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_system_message_arg ¶
get_system_message_arg() -> InstanceArgument
Get the system message argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The system message argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_termination_arg ¶
get_termination_arg() -> InstanceArgument
Get the termination argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The termination argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for standard agent specific content.
Returns:
Type | Description |
---|---|
bool | True if there's standard agent specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_code_execution ¶
set_code_execution(config: CodeExecutionConfig) -> None
Set code execution configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | CodeExecutionConfig | The code execution configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_system_message_config ¶
set_system_message_config(
config: SystemMessageConfig,
) -> None
Set system message configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SystemMessageConfig | The system message configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_termination_config ¶
set_termination_config(config: TerminationConfig) -> None
Set termination configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | TerminationConfig | The termination configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
SystemMessageConfig dataclass
¶
TerminationConfig dataclass
¶
captain_extras ¶
Captain agent extras module.
CaptainExtras dataclass
¶
CaptainExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
nested_config: Optional[dict[str, Any]] = None,
)
Bases: StandardExtras
Extras for captain agents.
has_specific_content ¶
has_specific_content() -> bool
Check for captain specific content.
Returns:
Type | Description |
---|---|
bool | True if there's captain specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/captain_extras.py
group_manager_extras ¶
Group manager agent specific extras module.
GroupManagerExtras dataclass
¶
GroupManagerExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
strategy: GroupManagerStrategy = PATTERN,
pattern_definition: str = "",
pattern_class_name: str = "AutoPattern",
pattern_imports: set[str] = set[str](),
group_chat_definition: str = "",
group_chat_name: str = "",
group_chat_argument: str = "",
custom_speaker_selection: str = "",
context_variables_content: str = "",
after_work_content: str = "",
)
Bases: StandardExtras
Extras for group manager agents.
has_specific_content ¶
has_specific_content() -> bool
Check if group manager has specific content.
Returns:
Type | Description |
---|---|
bool | True if there is specific content for the group manager, |
Source code in waldiez/exporting/core/extras/agent_extras/group_manager_extras.py
rag_user_extras ¶
RAG related extas.
RAGUserExtras dataclass
¶
RAGUserExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
before_content: str = "",
imports: set[str] = set[str](),
)
Bases: StandardExtras
RAG configuration.
reasoning_extras ¶
Resoning agent extras module.
ReasoningExtras dataclass
¶
ReasoningExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: StandardExtras
Extras for reasoning agents.
has_specific_content ¶
has_specific_content() -> bool
Check for reasoning specific content.
Returns:
Type | Description |
---|---|
bool | True if there's reasoning specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/reasoning_extras.py
standard_extras ¶
Standard agent extras module.
CodeExecutionConfig dataclass
¶
CodeExecutionConfig(
executor_content: str = "",
executor_argument: str = "False",
executor_import: ImportStatement | None = None,
)
StandardExtras dataclass
¶
StandardExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
code_execution_config: Optional[
CodeExecutionConfig
] = None,
termination_config: Optional[TerminationConfig] = None,
system_message_config: Optional[
SystemMessageConfig
] = None,
)
Bases: BaseExtras
Extras for standard agents (UserProxy, Assistant, etc.).
get_code_execution_arg ¶
get_code_execution_arg() -> InstanceArgument
Get the code execution argument string.
Returns:
Type | Description |
---|---|
InstanceArgument | The code execution argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_system_message_arg ¶
get_system_message_arg() -> InstanceArgument
Get the system message argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The system message argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
get_termination_arg ¶
get_termination_arg() -> InstanceArgument
Get the termination argument.
Returns:
Type | Description |
---|---|
InstanceArgument | The termination argument. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for standard agent specific content.
Returns:
Type | Description |
---|---|
bool | True if there's standard agent specific content. |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_code_execution ¶
set_code_execution(config: CodeExecutionConfig) -> None
Set code execution configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | CodeExecutionConfig | The code execution configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_system_message_config ¶
set_system_message_config(
config: SystemMessageConfig,
) -> None
Set system message configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SystemMessageConfig | The system message configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
set_termination_config ¶
set_termination_config(config: TerminationConfig) -> None
Set termination configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | TerminationConfig | The termination configuration. | required |
Source code in waldiez/exporting/core/extras/agent_extras/standard_extras.py
SystemMessageConfig dataclass
¶
base ¶
Base extras system for all exporters.
BaseExtras dataclass
¶
BaseExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
)
Bases: ExportContributor
Base class for all exporter extras with export contribution.
add_arg ¶
add_arg(arg: InstanceArgument | str, tabs: int = 0) -> None
Add an extra argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg | InstanceArgument | The argument to add. | required |
tabs | int | The number of tabs to indent the argument, by default 0. | 0 |
Source code in waldiez/exporting/core/extras/base.py
add_import ¶
add_import(import_statement: ImportStatement) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
import_statement | str | The import statement to add. | required |
Source code in waldiez/exporting/core/extras/base.py
add_imports ¶
add_imports(imports: Sequence[ImportStatement]) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imports | Set[str] | The import statements to add. | required |
append_after_agent ¶
append_after_agent(content: str) -> None
Append content to the after_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_after_all_agents ¶
append_after_all_agents(content: str) -> None
Append content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
append_before_agent ¶
append_before_agent(content: str) -> None
Append content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to append. | required |
Source code in waldiez/exporting/core/extras/base.py
contribute_to_export ¶
contribute_to_export(result: ExportResult) -> None
Contribute this extras' content to the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | ExportResult | The export result to contribute to. | required |
Source code in waldiez/exporting/core/extras/base.py
get_extra_args_content ¶
get_extra_args_content() -> str
has_content ¶
has_content() -> bool
Check if there's any meaningful content.
Returns:
Type | Description |
---|---|
bool | True if there's any content in this extras instance. |
Source code in waldiez/exporting/core/extras/base.py
has_specific_content abstractmethod
¶
has_specific_content() -> bool
Check if there's subclass-specific content.
Returns:
Type | Description |
---|---|
bool | True if there's specific content for this extras type. |
prepend_after_all_agents ¶
prepend_after_all_agents(content: str) -> None
Prepend content to the after_all_agents section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
prepend_before_agent ¶
prepend_before_agent(content: str) -> None
Prepend content to the before_agent section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to prepend. | required |
Source code in waldiez/exporting/core/extras/base.py
chat_extras ¶
Chat specific extras module.
ChatExtras dataclass
¶
ChatExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
chat_prerequisites: str = "",
chat_initiation: str = "",
chat_registration: str = "",
)
Bases: BaseExtras
Extras for chat exporters.
Attributes:
Name | Type | Description |
---|---|---|
chat_definition | str | The chat definition content. |
chat_initiation | str | The chat initiation content. |
add_registration ¶
add_registration(registration: str) -> None
Add chat registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
registration | str | The chat registration content. | required |
Source code in waldiez/exporting/core/extras/chat_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for chat specific content.
Returns:
Type | Description |
---|---|
bool | True if there's chat specific content. |
Source code in waldiez/exporting/core/extras/chat_extras.py
set_chat_initiation ¶
set_chat_initiation(initiation: str) -> None
Set the chat initiation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initiation | str | The chat initiation content. | required |
set_chat_prerequisites ¶
set_chat_prerequisites(prerequisites: str) -> None
Set the chat prerequisites.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prerequisites | str | The chat prerequisites content. | required |
flow_extras ¶
Flow specific extras module.
FlowExtras dataclass
¶
FlowExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
flow_name: str = "",
description: str = "",
config: ExportConfig = ExportConfig(),
version: str = get_waldiez_version(),
tools_result: Optional[ExportResult] = None,
models_result: Optional[ExportResult] = None,
agents_result: Optional[ExportResult] = None,
chats_result: Optional[ExportResult] = None,
header_content: str = "",
main_function: str = "",
after_run: str = "",
execution_code: str = "",
)
Bases: BaseExtras
Extras for flow exporter.
has_specific_content ¶
has_specific_content() -> bool
Check if the flow extras contain specific content.
Returns:
Type | Description |
---|---|
bool | True if any specific content is present, False otherwise. |
Source code in waldiez/exporting/core/extras/flow_extras.py
model_extras ¶
Agent specific extras module.
ModelExtras dataclass
¶
ModelExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
llm_config: Optional[dict[str, Any]] = None,
config_file_path: str = "",
)
Bases: BaseExtras
Extras for model exporters.
get_content ¶
get_content() -> str
Get the content of the LLM configuration.
Returns:
Type | Description |
---|---|
str | The serialized LLM configuration. |
Source code in waldiez/exporting/core/extras/model_extras.py
has_specific_content ¶
has_specific_content() -> bool
Check for model specific content.
Returns:
Type | Description |
---|---|
bool | True if there's model specific content. |
Source code in waldiez/exporting/core/extras/model_extras.py
set_config_file_path ¶
set_config_file_path(path: str) -> None
Set the configuration file path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The configuration file path. | required |
path_resolver ¶
Default path resolver for Waldiez items.
DefaultPathResolver ¶
Bases: PathResolver
Default path resolver for Waldiez items.
resolve ¶
Resolve a path to a local file system path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Union[str, Path] | The path to resolve. | required |
Returns:
Type | Description |
---|---|
Optional[Path] | The resolved local path or None if not found. |
Source code in waldiez/exporting/core/extras/path_resolver.py
serializer ¶
serializer for converting items to formatted strings.
DefaultSerializer ¶
Bases: Serializer
Default serializer for Waldiez items.
serialize ¶
Serialize an item to a formatted string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The item to serialize. | required |
**kwargs | Any | Additional keyword arguments, such as | {} |
Returns:
Type | Description |
---|---|
str | The serialized string representation of the item. |
Source code in waldiez/exporting/core/extras/serializer.py
serialize_item ¶
Convert an item to a formatted string with given indentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item | Any | The item to convert. | required |
tabs | int | The number of tabs, by default 1. | 1 |
Returns:
Type | Description |
---|---|
str | The formatted string. |
Example
Source code in waldiez/exporting/core/extras/serializer.py
tool_extras ¶
Agent specific extras module.
ToolExtras dataclass
¶
ToolExtras(
instance_id: str,
extra_imports: list[ImportStatement] = list[
ImportStatement
](),
before_agent: str = "",
after_agent: str = "",
after_all_agents: str = "",
extra_args: list[InstanceArgument] = list[
InstanceArgument
](),
function_content: str = "",
registration_content: str = "",
)
Bases: BaseExtras
Extras for tool exporters.
add_function_content ¶
add_function_content(content: str) -> None
Add function definition content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The function content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
add_registration_content ¶
add_registration_content(content: str) -> None
Add function registration content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The registration content to add. | required |
Source code in waldiez/exporting/core/extras/tool_extras.py
get_agent_llm_config_arg ¶
get_agent_llm_config_arg(
agent: WaldiezAgent,
all_models: list[WaldiezModel],
model_names: dict[str, str],
cache_seed: int | None,
as_dict: bool = False,
tabs: int = 1,
) -> str
Get the string representation of the agent's llm config argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_models | list[WaldiezModel] | All the models in the flow. | required |
model_names | dict[str, str] | A mapping of model ids to model names. | required |
cache_seed | Optional[int] | The cache seed. | required |
as_dict | bool | Whether to return the argument as a dictionary, by default False. | False |
tabs | int | The number of tabs for indentation, by default 1. | 1 |
Returns:
Type | Description |
---|---|
str | The agent's llm config argument to use. |
Source code in waldiez/exporting/core/utils/llm_config.py
get_comment ¶
Get a comment for the script or notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comment | str | The comment to add. | required |
for_notebook | bool | Whether the comment is for a notebook, by default False | False |
md_headings | int | The number of markdown headings to use (if for_notebook is True), by default 2 | 3 |
Returns:
Type | Description |
---|---|
str | The formatted comment. |
Source code in waldiez/exporting/core/utils/comment.py
get_default_exporter_context ¶
get_default_exporter_context(
config: Optional[ExportConfig] = None,
logger: Optional[ExportingLogger] = None,
) -> ExporterContext
Get the default exporter context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Optional[ExportConfig] | The export configuration, by default None | None |
logger | Optional[ExportingLogger] | The logger instance, by default None | None |
Returns:
Type | Description |
---|---|
ExporterContext | The default exporter context. |
Source code in waldiez/exporting/core/context.py
merge_export_results ¶
merge_export_results(
*results: ExportResult,
) -> ExportResult
Merge multiple ExportResult objects into one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*results | ExportResult | Variable number of ExportResult objects to merge. | () |
Returns:
Type | Description |
---|---|
ExportResult | A new ExportResult containing all merged content. |
Source code in waldiez/exporting/core/result.py
protocols ¶
Core exporting protocols.
ContentGenerator ¶
Bases: Protocol
Protocol for generating content.
generate ¶
generate(
merged_result: ExportResult,
is_async: bool,
after_run: str,
**kwargs: Any
) -> str
Generate content based on provided parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
merged_result | ExportResult | The merged export result containing all content. | required |
is_async | bool | Whether to generate async content. | required |
after_run | str | Additional content to add after the main flow execution. | required |
**kwargs | Any | Parameters to influence content generation. | {} |
Returns:
Type | Description |
---|---|
str | The generated content. |
Source code in waldiez/exporting/core/protocols.py
ExportContributor ¶
Bases: Protocol
Protocol for objects that can contribute to exports.
contribute_to_export ¶
contribute_to_export(result: ExportResult) -> None
Contribute content to the export result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | ExportResult | The export result to contribute to. | required |
ExportingLogger ¶
Bases: Protocol
Protocol for logging during exporting.
critical ¶
Log a critical error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The critical error message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
debug ¶
Log a debug message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The debug message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
error ¶
Log an error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The error message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
exception ¶
Log an exception message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The exception message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
info ¶
Log an informational message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The informational message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
log ¶
Log a message with the specified level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The message to log or message template for formatting. | required |
level | str | The logging level to use (e.g., "debug", "info", "warning", "error", "critical"). Defaults to "info". | 'info' |
*args | Any | Arguments to format into the message using % formatting. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
set_level ¶
set_level(level: str) -> None
Set the logging level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level | str | The logging level to set (e.g., "debug", "info", "warning", "error", "critical"). | required |
Raises:
Type | Description |
---|---|
ValueError | If the provided level is invalid. |
Source code in waldiez/exporting/core/protocols.py
success ¶
Log a success message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The success message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
warning ¶
Log a warning message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | Any | The warning message to log or message template. | required |
*args | Any | Arguments to format into the message. | () |
**kwargs | Any | Keyword arguments to format into the message using str.format(). | {} |
Source code in waldiez/exporting/core/protocols.py
PathResolver ¶
Bases: Protocol
Protocol for resolving a path.
resolve ¶
Resolve a path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The path to resolve. | required |
Returns:
Type | Description |
---|---|
str | The resolved path. |
Raises:
Type | Description |
---|---|
ValueError | If the path cannot be resolved. |
Source code in waldiez/exporting/core/protocols.py
Serializer ¶
Bases: Protocol
Protocol for serialization components.
Validator ¶
Bases: Protocol
Protocol for validation components.
validate ¶
validate(content: Any) -> ValidationResult
Validate content and return result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | Any | The content to validate. | required |
Returns:
Type | Description |
---|---|
ValidationResult | The validation result. |
Source code in waldiez/exporting/core/protocols.py
result ¶
Export result containers and related classes.
ExportResult dataclass
¶
ExportResult(
main_content: Optional[str] = None,
imports: set[ImportStatement] = set[ImportStatement](),
positioned_content: list[PositionedContent] = list[
PositionedContent
](),
instance_arguments: list[InstanceArgument] = list[
InstanceArgument
](),
environment_variables: list[EnvironmentVariable] = list[
EnvironmentVariable
](),
validation_result: Optional[ValidationResult] = None,
metadata: dict[str, Any] = dict[str, Any](),
)
Complete export result with all components.
add_content ¶
add_content(
content: str,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
order: Union[ContentOrder, int] = MAIN_CONTENT,
skip_strip: bool = False,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
metadata: Optional[dict[str, Any]] = None,
) -> None
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The position of the content, by default AGENTS | DEFAULT_EXPORT_POSITION |
order | int | The order within the position, by default 0 | MAIN_CONTENT |
skip_strip | bool | Whether to skip stripping whitespace from content, by default False | False |
agent_id | Optional[str] | The agent ID if positioned relative to an agent, by default None | None |
agent_position | Optional[AgentPosition] | The position relative to the agent, by default None | None |
metadata | Optional[dict[str, Any]] | Additional metadata for the content, by default None | None |
Source code in waldiez/exporting/core/result.py
add_env_var ¶
add_env_var(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
) -> None
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the environment variable. | required |
value | str | The value of the environment variable. | required |
description | Optional[str] | Description of the variable, by default None | None |
required | bool | Whether the variable is required, by default True | True |
Source code in waldiez/exporting/core/result.py
add_import ¶
add_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement to add. | required |
position | ImportPosition | The position of the import, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/result.py
add_imports ¶
add_imports(
statements: Union[
set[str],
list[str],
set[ImportStatement],
list[ImportStatement],
],
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> None
Add multiple import statements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements | Union[ |
] The import statements to add. | required |
position | ImportPosition | The position of the imports, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Source code in waldiez/exporting/core/result.py
add_instance_argument ¶
add_instance_argument(
name: str,
value: Any,
instance_id: str,
tabs: int = 0,
comment: Optional[str] = None,
) -> None
Add an instance argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the argument. | required |
value | Any | The value of the argument. | required |
instance_id | str | The ID of the instance this argument belongs to. | required |
tabs | int | Number of tabs for indentation, by default 0 | 0 |
comment | Optional[str] | Optional comment for the argument, by default None | None |
Source code in waldiez/exporting/core/result.py
add_instance_arguments ¶
add_instance_arguments(
arguments: Union[
list[InstanceArgument], set[InstanceArgument]
],
) -> None
Add multiple instance arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arguments | Union[list[InstanceArgument], set[InstanceArgument]] | The instance arguments to add. | required |
Source code in waldiez/exporting/core/result.py
clear ¶
Clear all content from the result.Source code in
waldiez/exporting/core/result.py
get_agent_content ¶
get_agent_content(
agent_id: str,
agent_position: Optional[AgentPosition] = None,
) -> list[PositionedContent]
Get content positioned relative to a specific agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id | str | The ID of the agent. | required |
agent_position | Optional[AgentPosition] | Filter by specific agent position, by default None (all positions) | None |
Returns:
Type | Description |
---|---|
list[PositionedContent] | Sorted list of content for the specified agent. |
Source code in waldiez/exporting/core/result.py
get_all_content_sorted ¶
get_all_content_sorted() -> list[PositionedContent]
Get all positioned content sorted by position and order.
Returns:
Type | Description |
---|---|
list[PositionedContent] | All positioned content sorted. |
Source code in waldiez/exporting/core/result.py
get_content_by_position ¶
get_content_by_position(
position: ExportPosition,
skip_agent_arguments: bool = True,
) -> list[PositionedContent]
Get all content for a specific position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ExportPosition | The position to filter by. | required |
skip_agent_arguments | bool | Whether to skip content positioned as agent arguments, by default True | True |
Returns:
Type | Description |
---|---|
list[PositionedContent] | Sorted list of content for the specified position. |
Source code in waldiez/exporting/core/result.py
get_imports_by_position ¶
get_imports_by_position(
position: ImportPosition,
) -> list[ImportStatement]
Get imports filtered by position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position | ImportPosition | The position to filter by. | required |
Returns:
Type | Description |
---|---|
list[ImportStatement] | list of imports for the specified position. |
Source code in waldiez/exporting/core/result.py
get_sorted_imports ¶
get_sorted_imports() -> list[ImportStatement]
Get imports sorted by position and statement.
Returns:
Type | Description |
---|---|
list[ImportStatement] | Sorted list of import statements. |
get_statistics ¶
Get statistics about the export result.
Returns:
Type | Description |
---|---|
dict[str, int] | dictionary with statistics about the export. |
Source code in waldiez/exporting/core/result.py
has_content ¶
has_content() -> bool
Check if there's any meaningful content.
Returns:
Type | Description |
---|---|
bool | True if there's any content, imports, or environment variables. |
Source code in waldiez/exporting/core/result.py
has_errors ¶
has_errors() -> bool
Check if there are validation errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors. |
Source code in waldiez/exporting/core/result.py
has_warnings ¶
has_warnings() -> bool
Check if there are validation warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings. |
Source code in waldiez/exporting/core/result.py
merge ¶
merge(
other: ExportResult,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
) -> None
Merge another ExportResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ExportResult | The other result to merge. | required |
position | ExportPosition | The position for the merged content, by default AGENTS | DEFAULT_EXPORT_POSITION |
Source code in waldiez/exporting/core/result.py
merge_with ¶
merge_with(other: ExportResult) -> None
Merge another ExportResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ExportResult | The other result to merge. | required |
Source code in waldiez/exporting/core/result.py
ExportResultBuilder dataclass
¶
ExportResultBuilder(_result: ExportResult = ExportResult())
Builder pattern for constructing ExportResult objects.
build ¶
build() -> ExportResult
with_content ¶
with_content(
content: str,
position: ExportPosition = DEFAULT_EXPORT_POSITION,
order: ContentOrder = MAIN_CONTENT,
agent_id: Optional[str] = None,
agent_position: Optional[AgentPosition] = None,
) -> ExportResultBuilder
Add positioned content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The content to add. | required |
position | ExportPosition | The content position, by default AGENTS | DEFAULT_EXPORT_POSITION |
order | int | The order within position, by default 0 | MAIN_CONTENT |
agent_id | Optional[str] | Agent ID for agent-relative positioning, by default None | None |
agent_position | Optional[AgentPosition] | Position relative to agent, by default None | None |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_env_var ¶
with_env_var(
name: str, value: str, description: Optional[str] = None
) -> ExportResultBuilder
Add environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Variable name. | required |
value | str | Variable value. | required |
description | Optional[str] | Variable description, by default None | None |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_import ¶
with_import(
statement: str,
position: ImportPosition = DEFAULT_IMPORT_POSITION,
) -> ExportResultBuilder
Add an import statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement | str | The import statement. | required |
position | ImportPosition | The import position, by default THIRD_PARTY | DEFAULT_IMPORT_POSITION |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_main_content ¶
with_main_content(content: str) -> ExportResultBuilder
Set the main content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content | str | The main content to set. | required |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
with_metadata ¶
with_metadata(key: str, value: Any) -> ExportResultBuilder
Add metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | Metadata key. | required |
value | Any | Metadata value. | required |
Returns:
Type | Description |
---|---|
ExportResultBuilder | Self for method chaining. |
Source code in waldiez/exporting/core/result.py
create_empty_result ¶
create_empty_result() -> ExportResult
create_result_with_content ¶
create_result_with_content(
main_content: str, imports: Optional[list[str]] = None
) -> ExportResult
Create an ExportResult with basic content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_content | str | The main content. | required |
imports | Optional[list[str]] | list of import statements, by default None | None |
Returns:
Type | Description |
---|---|
ExportResult | The created ExportResult. |
Source code in waldiez/exporting/core/result.py
merge_export_results ¶
merge_export_results(
*results: ExportResult,
) -> ExportResult
Merge multiple ExportResult objects into one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*results | ExportResult | Variable number of ExportResult objects to merge. | () |
Returns:
Type | Description |
---|---|
ExportResult | A new ExportResult containing all merged content. |
Source code in waldiez/exporting/core/result.py
types ¶
Core dataclasses for the exporting system.
EnvironmentVariable dataclass
¶
EnvironmentVariable(
name: str,
value: str,
description: Optional[str] = None,
required: bool = True,
)
ExportConfig dataclass
¶
ExportConfig(
name: str = "Waldiez Flow",
description: str = "Make AG2 Agents Collaborate: Drag, Drop, and Orchestrate with Waldiez",
requirements: list[str] = list[str](),
tags: list[str] = list[str](),
output_extension: str = "py",
is_async: bool = False,
output_directory: Optional[str | Path] = None,
uploads_root: Optional[Path] = None,
cache_seed: Optional[int] = None,
structured_io: bool = False,
skip_patch_io: bool = True,
)
Configuration for export operations.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of the export. |
description | str | A brief description of the export. |
requirements | list[str] | A list of requirements for the export. |
tags | list[str] | A list of tags associated with the export. |
output_directory | Optional[str | Path] | The directory where the exported content will be saved. |
uploads_root | Optional[str | Path] | The root directory for uploads, if applicable. |
cache_seed | Optional[int] | The seed for caching, if applicable. |
structured_io | bool | Whether the export should use structured I/O. |
output_extension | str | The file extension for the exported content. |
is_async | bool | Whether the exported content should be asynchronous. |
skip_patch_io | bool | Whether to skip patching I/O operations. |
create classmethod
¶
create(**kwargs: Any) -> ExportConfig
Create a new ExportConfig instance with the provided values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Keyword arguments to initialize the ExportConfig. | {} |
Returns:
Type | Description |
---|---|
ExportConfig | A new instance of ExportConfig. |
Source code in waldiez/exporting/core/types.py
for_notebook property
¶
for_notebook: bool
Check if the export is intended for a notebook environment.
Returns:
Type | Description |
---|---|
bool | True if the output extension is 'ipynb', otherwise False. |
update ¶
update(**kwargs: Any) -> None
Update the export configuration with new values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Keyword arguments to update the configuration. | {} |
Raises:
Type | Description |
---|---|
ValueError | If an invalid configuration key is provided. |
Source code in waldiez/exporting/core/types.py
ImportStatement dataclass
¶
ImportStatement(
statement: str,
position: ImportPosition = THIRD_PARTY,
metadata: Optional[dict[str, Any]] = None,
)
Represents an import statement with its position.
InstanceArgument dataclass
¶
InstanceArgument(
instance_id: str,
name: str,
value: Any,
tabs: int = 0,
tabs_length: int = 4,
with_new_line_before: bool = False,
with_new_line_after: bool = False,
with_new_line_if_empty: bool = False,
skip_if_empty_string: bool = True,
comment: Optional[str] = None,
)
Represents an instance argument for an agent, model or tool.
get_content ¶
Get the content representation of the instance argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prepend_new_line | bool | Whether to prepend a new line before the content, by default False. | False |
append_new_line | bool | Whether to append a new line at the end of the content, by default False. | False |
Returns:
Type | Description |
---|---|
str | The formatted content string for the instance argument. |
Source code in waldiez/exporting/core/types.py
has_content ¶
has_content() -> bool
Check if the instance argument has content.
Returns:
Type | Description |
---|---|
bool | True if the instance argument has content, otherwise False. |
Source code in waldiez/exporting/core/types.py
utils ¶
Utility functions for Waldiez exporting.
comment ¶
Get comment string for scripts or notebooks.
get_comment ¶
Get a comment for the script or notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comment | str | The comment to add. | required |
for_notebook | bool | Whether the comment is for a notebook, by default False | False |
md_headings | int | The number of markdown headings to use (if for_notebook is True), by default 2 | 3 |
Returns:
Type | Description |
---|---|
str | The formatted comment. |
Source code in waldiez/exporting/core/utils/comment.py
get_agent_llm_config_arg ¶
get_agent_llm_config_arg(
agent: WaldiezAgent,
all_models: list[WaldiezModel],
model_names: dict[str, str],
cache_seed: int | None,
as_dict: bool = False,
tabs: int = 1,
) -> str
Get the string representation of the agent's llm config argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_models | list[WaldiezModel] | All the models in the flow. | required |
model_names | dict[str, str] | A mapping of model ids to model names. | required |
cache_seed | Optional[int] | The cache seed. | required |
as_dict | bool | Whether to return the argument as a dictionary, by default False. | False |
tabs | int | The number of tabs for indentation, by default 1. | 1 |
Returns:
Type | Description |
---|---|
str | The agent's llm config argument to use. |
Source code in waldiez/exporting/core/utils/llm_config.py
get_comment ¶
Get a comment for the script or notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comment | str | The comment to add. | required |
for_notebook | bool | Whether the comment is for a notebook, by default False | False |
md_headings | int | The number of markdown headings to use (if for_notebook is True), by default 2 | 3 |
Returns:
Type | Description |
---|---|
str | The formatted comment. |
Source code in waldiez/exporting/core/utils/comment.py
llm_config ¶
LLM config argument utility functions for Waldiez agents.
get_agent_llm_config_arg ¶
get_agent_llm_config_arg(
agent: WaldiezAgent,
all_models: list[WaldiezModel],
model_names: dict[str, str],
cache_seed: int | None,
as_dict: bool = False,
tabs: int = 1,
) -> str
Get the string representation of the agent's llm config argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_models | list[WaldiezModel] | All the models in the flow. | required |
model_names | dict[str, str] | A mapping of model ids to model names. | required |
cache_seed | Optional[int] | The cache seed. | required |
as_dict | bool | Whether to return the argument as a dictionary, by default False. | False |
tabs | int | The number of tabs for indentation, by default 1. | 1 |
Returns:
Type | Description |
---|---|
str | The agent's llm config argument to use. |
Source code in waldiez/exporting/core/utils/llm_config.py
validation ¶
Validation types and results for Waldiez exporting core.
ValidationError dataclass
¶
ValidationError(
message: str,
severity: str = "error",
location: Optional[str] = None,
suggestion: Optional[str] = None,
)
Represents a validation error.
ValidationResult dataclass
¶
ValidationResult(
is_valid: bool,
errors: list[ValidationError] = list[ValidationError](),
warnings: list[ValidationError] = list[
ValidationError
](),
)
Result of validation operations.
add_error ¶
add_error(
message: str,
location: Optional[str] = None,
suggestion: Optional[str] = None,
) -> None
Add a validation error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | str | The error message to add. | required |
location | Optional[str] | The location in the code where the error occurred, by default None | None |
suggestion | Optional[str] | A suggestion for fixing the error, by default None | None |
Source code in waldiez/exporting/core/validation.py
add_warning ¶
Add a validation warning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | str | The warning message to add. | required |
location | Optional[str] | The location in the code where the warning occurred, by default None | None |
Source code in waldiez/exporting/core/validation.py
has_errors ¶
has_errors() -> bool
Check if there are any errors.
Returns:
Type | Description |
---|---|
bool | True if there are validation errors, otherwise False. |
has_warnings ¶
has_warnings() -> bool
Check if there are any warnings.
Returns:
Type | Description |
---|---|
bool | True if there are validation warnings, otherwise False. |
merge ¶
merge(other: ValidationResult) -> None
Merge another ValidationResult into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | ValidationResult | The other validation result to merge. | required |