Add background-workers agent example with Node.js Worker Threads#27
Open
Add background-workers agent example with Node.js Worker Threads#27
Conversation
This commit adds a new sample demonstrating how to use Node.js Worker Threads to handle CPU-blocking operations without freezing the agent's main thread. New Features: - Background worker agent using worker_threads for CPU-intensive tasks - Fire-and-forget pattern: agent returns immediately without waiting for workers - get_task_status tool using app.getAsyncTaskInfo() for monitoring active tasks - Non-blocking architecture allowing concurrent request handling - Comprehensive documentation on blocking vs non-blocking operations Changes: - primitives/runtime/background-workers/: New sample with agent, worker, and docs - primitives/runtime/async-agent/: Added get_task_status tool for consistency - primitives/runtime/README.md: Added link to new background-workers sample The example demonstrates: - Worker threads for blocking operations (loops, dataset processing, calculations) - Main thread stays responsive while workers process in background - Multiple concurrent workers can run simultaneously - Health status tracking (Healthy/HealthyBusy) - Message passing between main thread and worker threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds a new sample demonstrating how to use Node.js Worker Threads to handle CPU-blocking operations without freezing the agent's main thread. Due to the single-thread nature of Node JS, any blocking operation such as file operations and loop will block the AI agent from receiving new incoming requests.
New Features:
Changes:
The example demonstrates:
Worker threads for blocking operations (loops, dataset processing, calculations)
Main thread stays responsive while workers process in background
Multiple concurrent workers can run simultaneously
Health status tracking (Healthy/HealthyBusy)
Message passing between main thread and worker threads
New example
Bug fix
Documentation update
Configuration/tooling update
Other (describe below)
Related Issues
Closes #16
Checklist
npm run validatelocally and it passes