Repository: Standard-Labs/real-intent
Issue category: Performance Issue

Issue:
Improve integration efficiency
Multithreading


Hints:

Patch:
diff --git a/real_intent/deliver/followupboss/vanilla.py b/real_intent/deliver/followupboss/vanilla.py
index 2db5ad1..6795ebb 100644
--- a/real_intent/deliver/followupboss/vanilla.py
+++ b/real_intent/deliver/followupboss/vanilla.py
@@ -3,6 +3,7 @@
 
 from enum import StrEnum
 import base64
+from concurrent.futures import ThreadPoolExecutor
 
 from real_intent.deliver.base import BaseOutputDeliverer
 from real_intent.schemas import MD5WithPII
@@ -122,13 +123,8 @@ def _deliver(self, pii_md5s: list[MD5WithPII]) -> list[dict]:
         # Log if any of the leads are on the DNC list
         self._warn_dnc(pii_md5s)
 
-        responses: list[dict] = []
-
-        for md5_with_pii in pii_md5s:
-            response = self._deliver_single_lead(md5_with_pii)
-            responses.append(response)
-
-        return responses
+        with ThreadPoolExecutor(max_workers=5) as executor:
+            return list(executor.map(self._deliver_single_lead, pii_md5s))
 
     def _deliver_single_lead(self, md5_with_pii: MD5WithPII) -> dict:
         """
diff --git a/real_intent/deliver/kvcore/__init__.py b/real_intent/deliver/kvcore/__init__.py
index a1a7a48..4c67f56 100644
--- a/real_intent/deliver/kvcore/__init__.py
+++ b/real_intent/deliver/kvcore/__init__.py
@@ -2,6 +2,7 @@
 import requests
 
 from typing import Any
+from concurrent.futures import ThreadPoolExecutor
 
 from real_intent.internal_logging import log
 from real_intent.deliver.base import BaseOutputDeliverer
@@ -47,13 +48,8 @@ def _deliver(self, pii_md5s: list[MD5WithPII]) -> bool:
         Returns True if all leads were delivered successfully.
         Otherwise, returns False.
         """
-        all_good: bool = True
-        for pii_md5 in pii_md5s:
-            if not self._deliver_one(pii_md5):
-                all_good = False
-                continue
-
-        return all_good
+        with ThreadPoolExecutor(max_workers=5) as executor:
+            return all(executor.map(self._deliver_one, pii_md5s))
 
     def _deliver_one(self, pii_md5: MD5WithPII) -> bool:
         """


Test patch: