Documentation Index
Fetch the complete documentation index at: https://docs.blastproject.org/llms.txt
Use this file to discover all available pages before exploring further.
What you need to knowSince BLAST automatically runs tasks concurrently, the only thing you may need to set is constraints:from blastai import Engine, Constraints
engine = await Engine.create(
constraints=Constraints(
allow_parallelism=True, # Enable/disable parallel execution
max_concurrent_browsers=4 # Maximum number of parallel browsers
)
)
Task Lifecycle
Every task in BLAST goes through several stages:
- Creation: Task is scheduled and assigned a unique ID
- Resource Allocation: Browser and other resources are assigned
- Execution: Task runs and streams progress updates
- Completion: Results are stored and resources are freed
Task Relationships
BLAST supports two types of task relationships:
Prerequisites
Tasks can depend on other tasks completing first:
from blastai import Engine
async with Engine() as engine:
# Task B won't start until Task A completes
task_a = await engine.run("Go to python.org")
task_b = await engine.run(
"Click on Documentation",
previous_response_id=task_a.id # Set prerequisite
)
Parent/Child Tasks
Tasks can spawn subtasks that run concurrently:
# Parent task can create multiple subtasks
results = await engine.run("Launch subtasks to visit each of these websites: bloomberg.com, wsj.com, and nytimes.com")
Task Priorities
BLAST prioritizes tasks in this order:
- Tasks with cached results
- Tasks with cached execution plans
- Subtasks of running tasks
- Tasks with paused executors
- Remaining tasks (FIFO order)
Concurrent Execution
BLAST can execute multiple tasks concurrently when resources allow:
async with Engine(
constraints=Constraints(
max_concurrent_browsers=4, # Allow 4 parallel browsers
allow_parallelism=True # Enable parallel execution
)
) as engine:
# These tasks will run in parallel
task1 = engine.run("Search Python docs", stream=True)
task2 = engine.run("Search JavaScript docs", stream=True)
task3 = engine.run("Search Rust docs", stream=True)
# Process streams concurrently
async def process_stream(stream):
async for update in stream:
if isinstance(update, AgentReasoning):
print(update.content)
await asyncio.gather(
process_stream(task1),
process_stream(task2),
process_stream(task3)
)
Resource Management
BLAST automatically manages resources for concurrent tasks:
- Limits concurrent browser instances
- Reuses browsers when possible
- Manages memory usage
- Handles cleanup on task completion
Monitor resource usage:
metrics = await engine.get_metrics()
print(f"Running tasks: {metrics['tasks']['running']}")
print(f"Active browsers: {metrics['concurrent_browsers']}")
print(f"Memory usage: {metrics['memory_usage_gb']} GB")
Task State Management
Track task states through the API:
metrics = await engine.get_metrics()
task_states = metrics['tasks']
print(f"Scheduled: {task_states['scheduled']}") # Waiting to start
print(f"Running: {task_states['running']}") # Currently executing
print(f"Completed: {task_states['completed']}") # Finished tasks
Next Steps