When building bots that perform lengthy operations, it’s important to keep users informed about the bot’s progress. The lil’bots platform provides a simple yet powerful progress reporting mechanism that displays a progress bar to users while your bot is running.
Progress reporting works by allowing your bot to send updates about its completion status. These updates are displayed to the user as a progress bar, helping them understand how far along the bot is in completing its task.Progress is represented as a decimal value between 0 (not started) and 1 (completed).
Update progress at meaningful intervals. Updating too frequently (e.g., in tight loops) can create unnecessary network traffic, while updating too infrequently can leave users wondering if the bot is still working.
Copy
// Good practice in a loopfor (let i = 0; i < 100; i++) { await processItem(i); // Update every 10 items or use a percentage calculation if (i % 10 === 0 || i === 99) { updateProgress(i / 99); }}
In some cases, you might want to provide additional context alongside the progress update:
Copy
from lilbots import update_progressdef main(inputs, params): files_to_process = get_files_list(inputs.get("source_dir")) total_files = len(files_to_process) for index, file in enumerate(files_to_process): process_file(file) # Update progress with fraction complete current_progress = (index + 1) / total_files update_progress(current_progress) # Note: While the lilbots platform currently only displays # the progress bar, future versions might support additional # status information return [{"title": "Processing Complete", "message": f"Processed {total_files} files"}]
Progress values must be between 0 and 1 (inclusive). Values outside this range will be clamped.
The progress bar is a visual indicator only and doesn’t affect the execution of your bot.
Progress updates are best-effort and might be delayed or dropped in case of network issues.
Remember that the progress reporting feature is particularly useful for bots that perform long-running tasks, helping to provide users with confidence that your bot is working as expected.