waldiez
Project description
Waldiez
Translate a Waldiez flow:
To a python script or a jupyter notebook with the corresponding ag2 agents and chats.
Features
- Convert .waldiez flows to .py or .ipynb
- Run a .waldiez flow
- 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
# Convert a Waldiez flow to a python script or a jupyter notebook
waldiez convert --file /path/to/a/flow.waldiez --output /path/to/an/output/flow[.py|.ipynb]
# Convert and run the script, optionally force generation if the output file already exists
waldiez run --file /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
# Convert 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 convert --file /flow.waldiez --output /output/flow[.py|.ipynb] [--force]
# 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 convert --file /flow.waldiez --output /output/flow[.py|.ipynb] [--force]
# Convert and run the script
$CONTAINER_COMMAND run \
--rm \
-v /path/to/a/flow.waldiez:/flow.waldiez \
-v /path/to/an/output:/output \
waldiez/waldiez run --file /flow.waldiez --output /output/output[.py]
UI
For creating-only (no exporting or running) waldiez flows, you can use the playground at https://waldiez.github.io.
The repo for the js library is here.
We are currently working on waldiez-studio to provide a visual interface for creating and running Waldiez flows (you can find more here).
Until then, you can use our Jupyter or the VSCode extension to create and run Waldiez flows.
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/pyautogen. Ensure thatautogen-agentchatis uninstalled before installingwaldiez. If you have already installedautogen-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 pyautogen
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file waldiez-0.1.16.tar.gz.
File metadata
- Download URL: waldiez-0.1.16.tar.gz
- Upload date:
- Size: 63.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94cc2f166a1f7cfb5062ad6a4da38ac183d332c431aded01cc3d20c42b5afda
|
|
| MD5 |
74f221def26ba06a4ee85967daa121ee
|
|
| BLAKE2b-256 |
34c2749e367a305c8d0edc67a9ea7e25fcc61dbd4617765cf0442966e19b13c7
|
Provenance
The following attestation bundles were made for waldiez-0.1.16.tar.gz:
Publisher:
release.yaml on waldiez/waldiez
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waldiez-0.1.16.tar.gz -
Subject digest:
d94cc2f166a1f7cfb5062ad6a4da38ac183d332c431aded01cc3d20c42b5afda - Sigstore transparency entry: 154499760
- Sigstore integration time:
-
Permalink:
waldiez/waldiez@d25235a10437dd13c76f07adec6b06958e72ed41 -
Branch / Tag:
refs/tags/v0.1.16 - Owner: https://github.com/waldiez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@d25235a10437dd13c76f07adec6b06958e72ed41 -
Trigger Event:
push
-
Statement type:
File details
Details for the file waldiez-0.1.16-py3-none-any.whl.
File metadata
- Download URL: waldiez-0.1.16-py3-none-any.whl
- Upload date:
- Size: 99.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c45a0418556b2ebb5bd3a2967dd4dc4892d304e91e723c4beccb054f8b3a431
|
|
| MD5 |
f46df94eda24de4b604656e2b708a834
|
|
| BLAKE2b-256 |
4bbe3efc43d2012acee198dca625499f7e1a975512d1462d7da55bd1facede16
|
Provenance
The following attestation bundles were made for waldiez-0.1.16-py3-none-any.whl:
Publisher:
release.yaml on waldiez/waldiez
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waldiez-0.1.16-py3-none-any.whl -
Subject digest:
0c45a0418556b2ebb5bd3a2967dd4dc4892d304e91e723c4beccb054f8b3a431 - Sigstore transparency entry: 154499761
- Sigstore integration time:
-
Permalink:
waldiez/waldiez@d25235a10437dd13c76f07adec6b06958e72ed41 -
Branch / Tag:
refs/tags/v0.1.16 - Owner: https://github.com/waldiez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@d25235a10437dd13c76f07adec6b06958e72ed41 -
Trigger Event:
push
-
Statement type: