Skip to main content

waldiez

Project description

Waldiez

CI Build Coverage Status PyPI version

Translate a Waldiez flow:

Flow

To a python script or a jupyter notebook with the corresponding ag2 agents and chats.

Features

  • Export .waldiez flows to .py or .ipynb
  • Run a .waldiez flow
  • Include a logs folder with the logs of the flow in csv format
  • Provide a custom IOSStream to handle input and output.

Installation

On PyPI:

python -m pip install waldiez

From the repository:

python -m pip install git+https://github.com/waldiez/waldiez.git

Usage

CLI

# Export a Waldiez flow to a python script or a jupyter notebook
waldiez --export /path/to/a/flow.waldiez --output /path/to/an/output/flow[.py|.ipynb]
# Export and run the script, optionally force generation if the output file already exists
waldiez /path/to/a/flow.waldiez --output /path/to/an/output/flow[.py] [--force]

Using docker/podman

CONTAINER_COMMAND=docker # or podman
# pull the image
$CONTAINER_COMMAND pull waldiez/waldiez
# Export a Waldiez flow to a python script or a jupyter notebook
$CONTAINER_COMMAND run \
  --rm \
  -v /path/to/a/flow.waldiez:/flow.waldiez \
  -v /path/to/an/output:/output \
  waldiez/waldiez --export /flow.waldiez --output /output/flow[.py|.ipynb]

# with selinux and/or podman, you might get permission (or file not found) errors, so you can try:
$CONTAINER_COMMAND run \
  --rm \
  -v /path/to/a/flow.waldiez:/flow.waldiez \
  -v /path/to/an/output:/output \
  --userns=keep-id \
  --security-opt label=disable \
  waldiez/waldiez --export /flow.waldiez --output /output/flow[.py|.ipynb]
# Export and run the script
$CONTAINER_COMMAND run --rm -v /path/to/a/flow.waldiez:/flow.waldiez -v /path/to/an/output:/output waldiez/waldiez /flow.waldiez --output /output/output[.py]

As a library

Export a flow

# Export a Waldiez flow to a python script or a jupyter notebook
from waldiez import WaldiezExporter
flow_path = "/path/to/a/flow.waldiez"
output_path = "/path/to/an/output.py"  # or .ipynb
exporter = WaldiezExporter.load(flow_path)
exporter.export(output_path)

Run a flow

# Run a flow
from waldiez import WaldiezRunner
flow_path = "/path/to/a/flow.waldiez"
output_path = "/path/to/an/output.py"
runner = WaldiezRunner.load(flow_path)
runner.run(output_path=output_path)

Run a flow with a custom IOStream

# Run the flow with a custom IOStream
# In case the standard 'input' and 'print' functions cannot be used
import time
import threading

from typing import Any

from waldiez import WaldiezRunner
from waldiez.io import WaldiezIOStream

flow_path = "/path/to/a/flow.waldiez"
output_path = "/path/to/an/output.py"


def custom_print_function(*args: Any, sep: str = " ", **kwargs: Any) -> None:
    """Custom print function."""
    print(*args, sep=sep, **kwargs)


# Custom input handler
class InputProcessorWrapper:
    """Wrapper input processor.
    
    To manage the interaction between the custom input processor and IOStream.
    """

    def __init__(self):
        self.stream = None  # Placeholder for the WaldiezIOStream instance
        self.lock = threading.Lock()  # Ensure thread-safe operations

    def custom_input_processor(self, prompt: str) -> None:
        """Simulate external input and send it back to the IOStream."""
        def external_input_simulation():
            with self.lock:  # Ensure thread-safe access
                time.sleep(2)  # Simulate delay for network input
                if self.stream:
                    self.stream.set_input("Simulated external input")
                else:
                    raise RuntimeError("Stream reference not set!")

        threading.Thread(target=external_input_simulation, daemon=True).start()

    def set_stream(self, stream: "WaldiezIOStream"):
        """Set the WaldiezIOStream instance."""
        with self.lock:  # Ensure thread-safe setting of the stream
            self.stream = stream

processor_wrapper = InputProcessorWrapper()

stream = WaldiezIOStream(
    input_timeout=30,
    print_function=
    on_prompt_input=processor_wrapper.custom_input_processor,
)

# Link the processor wrapper to the WaldiezIOStream instance
processor_wrapper.set_stream(custom_stream)

with WaldiezIOStream.set_default(io_stream):
    runner = WaldiezRunner.load(flow_path)
    runner.run(stream=io_stream, output_path=output_path)

Tools

Known Conflicts

  • autogen-agentchat: This package conflicts with ag2. Ensure that autogen-agentchat is uninstalled before installing waldiez. If you have already installed autogen-agentchat, you can uninstall it with the following command:

    pip uninstall autogen-agentchat -y
    

    If already installed waldiez you might need to reinstall it after uninstalling autogen-agentchat:

    pip install --force --no-cache waldiez
    

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

waldiez-0.1.11.tar.gz (62.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

waldiez-0.1.11-py3-none-any.whl (98.3 kB view details)

Uploaded Python 3

File details

Details for the file waldiez-0.1.11.tar.gz.

File metadata

  • Download URL: waldiez-0.1.11.tar.gz
  • Upload date:
  • Size: 62.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for waldiez-0.1.11.tar.gz
Algorithm Hash digest
SHA256 7de8936ec842d516b1e47d174a78aa6a5e559f8e4e6eb72c604f6a812ac42278
MD5 218454c4d2ca75d347c380391aca0618
BLAKE2b-256 77e880e7a9f7d76b45a8410937a63ef40b39c56c6ea28d96fc75fb29f295c0ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for waldiez-0.1.11.tar.gz:

Publisher: release.yaml on waldiez/waldiez

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file waldiez-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: waldiez-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 98.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for waldiez-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 81451e0778ba4834c89fd4a2729d999e310976d117b747221b09cae9ae4bcdaa
MD5 e238ce2d3b81db6d676479466acee525
BLAKE2b-256 dfc6704a94bc79f7517f6af12c7e841d8af90fc0e954263d65035970ae92fcf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for waldiez-0.1.11-py3-none-any.whl:

Publisher: release.yaml on waldiez/waldiez

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page