From fc7cebb99173ea1f06dfea1bb99575babbd1ca02 Mon Sep 17 00:00:00 2001 From: Saaketh Sodanapalli Date: Wed, 29 Jul 2026 14:44:52 -0700 Subject: [PATCH 1/2] added bedrock llm connection --- ventis/llm/__init__.py | 0 ventis/llm/bedrock.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 ventis/llm/__init__.py create mode 100644 ventis/llm/bedrock.py diff --git a/ventis/llm/__init__.py b/ventis/llm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ventis/llm/bedrock.py b/ventis/llm/bedrock.py new file mode 100644 index 0000000..d91c942 --- /dev/null +++ b/ventis/llm/bedrock.py @@ -0,0 +1,51 @@ +import os + +try: + from ventis.utils.redis_client import RedisClient + import ventis.ventis_context as ventis_context +except ImportError: + from redis_client import RedisClient + import ventis_context + +_redis = RedisClient( + host=os.environ.get("VENTIS_REDIS_HOST", "localhost"), + port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)), +) + + +def call_bedrock(model_id: str, messages: list, inference_config: dict, region: str = "us-east-1") -> dict: + """Call Bedrock's converse() API and log token/error telemetry onto the + currently executing future's Redis hash (future:).""" + import boto3 + + client = boto3.client("bedrock-runtime", region_name=region) + future_id = ventis_context.get_current_future_id() + error_count = 0 + response = None + try: + response = client.converse( + modelId=model_id, messages=messages, inferenceConfig=inference_config + ) + return response + except Exception: + # Counts failed attempts for this call. With no retry logic today this is + # always 0 or 1, matching `failed`; once retries are added, a call that + # eventually succeeds can still report error_count > 0 while failed stays 0. + error_count += 1 + agent_id = ventis_context.get_current_agent_id() + if agent_id: + _redis.client.incr(f"{agent_id}:llm_errors") + raise + finally: + if future_id: + usage = (response or {}).get("usage", {}) + _redis.hset_multiple(f"future:{future_id}", { + "model": model_id, + "input_token_count": str(usage.get("inputTokens", "")), + "output_token_count": str(usage.get("outputTokens", "")), + "token_count": str(usage.get("totalTokens", "")), + "errors": str(error_count), + "input_cache_tokens": str(usage.get("cacheReadInputTokens", "")), + "input_cache_write_tokens": str(usage.get("cacheWriteInputTokens", "")), + }) + From 8f7a48d25d070c1d50a842815ca7784aacff1a0f Mon Sep 17 00:00:00 2001 From: Saaketh Sodanapalli Date: Wed, 29 Jul 2026 16:41:22 -0700 Subject: [PATCH 2/2] forgot to add addition to stub_generator --- ventis/stub_generator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ventis/stub_generator.py b/ventis/stub_generator.py index eb7f1b7..b8196b5 100644 --- a/ventis/stub_generator.py +++ b/ventis/stub_generator.py @@ -313,6 +313,7 @@ def generate_docker( "local_controller_frontend.py", ), (os.path.join(script_dir, "utils", "redis_client.py"), "redis_client.py"), + (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py,"), ] # Copy provided agent stubs