HiveLang v4Advanced
Parallel Execution & Error Handling
Build fast, resilient agents with concurrency and error boundaries.
Parallel Blocks
The parallel keyword allows multiple tool calls to execute concurrently. This dramatically reduces latency when calling multiple APIs.
Performance: If you have 3 API calls that each take 1 second, running them in parallel takes ~1 second total instead of 3 seconds sequentially.
parallel-example.hive
bot "FastSearcher"
on input
say "Starting parallel search..."
parallel
call integrations.google.search(query: input) as web_results
call integrations.news.search(query: input) as news_results
call integrations.scholar.search(query: input) as academic_results
end
say f"Web: {web_results}"
say f"News: {news_results}"
say f"Academic: {academic_results}"
end
end
Error Handling (try/onerror)
Use try/onerror blocks to catch failures and provide fallback behavior. This prevents your bot from crashing when external services fail.
try-example.hive
bot "ResilientBot"
on input
try
call unstable.external_api(data: input) as response
say f"Success: {response}"
onerror
say "⚠️ External API failed. Using fallback..."
set response = "Default value"
end
say f"Final result: {response}"
end
end
Combining Parallel + Error Handling
You can nest try/onerror inside parallel blocks for maximum resilience and speed.
combined-example.hive
bot "ProBot"
on input
say "Processing with resilience..."
parallel
try
call api.fast_service(query: input) as fast
onerror
set fast = "Fallback fast"
end
try
call api.slow_service(query: input) as slow
onerror
set slow = "Fallback slow"
end
end
say f"Fast: {fast}, Slow: {slow}"
end
end