Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added ventis/llm/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions ventis/llm/bedrock.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +3 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Fix the import block so CI passes.

Ruff reports I001 and PLR0402 here. Use the canonical package import and format both branches while preserving the intended fallback.

Proposed fix
 try:
-    from ventis.utils.redis_client import RedisClient
-    import ventis.ventis_context as ventis_context
+    from ventis import ventis_context
+    from ventis.utils.redis_client import RedisClient
 except ImportError:
-    from redis_client import RedisClient
     import ventis_context
+    from redis_client import RedisClient
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
try:
from ventis import ventis_context
from ventis.utils.redis_client import RedisClient
except ImportError:
import ventis_context
from redis_client import RedisClient
🧰 Tools
🪛 GitHub Actions: CI / 0_test.txt

[error] 5-7: Ruff (PLR0402): Use from ventis import ventis_context in lieu of alias.

🪛 GitHub Actions: CI / test

[error] 4-6: Ruff I001: Import block is un-sorted or un-formatted.


[error] 5-5: Ruff PLR0402: Use from ventis import ventis_context in lieu of alias.


[error] 7-8: Ruff I001: Import block is un-sorted or un-formatted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/llm/bedrock.py` around lines 3 - 8, Update the import block in
bedrock.py to use the canonical package import consistently, while retaining the
fallback imports for environments where the package import is unavailable.
Format both try and except branches according to Ruff’s import-order and
formatting rules so I001 and PLR0402 are resolved.

Source: Pipeline failures


_redis = RedisClient(
host=os.environ.get("VENTIS_REDIS_HOST", "localhost"),
port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use a string environment default.

Ruff PLW1508 flags the integer default passed to os.environ.get; convert the environment string after retrieval.

Proposed fix
-    port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)),
+    port=int(os.environ.get("VENTIS_REDIS_PORT", "6379")),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)),
port=int(os.environ.get("VENTIS_REDIS_PORT", "6379")),
🧰 Tools
🪛 GitHub Actions: CI / test

[error] 12-12: Ruff PLW1508: Invalid type for environment variable default; expected str or None.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/llm/bedrock.py` at line 12, Update the Redis port configuration in the
Bedrock initialization to use a string default when calling os.environ.get, then
convert the retrieved value to an integer for the port argument.

Source: Pipeline failures

)


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:<future_id>)."""
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", "")),
})
Comment on lines +35 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locate file and relevant symbols"
fd -a 'bedrock.py|redis.py|context.py' . | sed 's#^\./##' | head -100

echo
echo "Relevant source outline"
ast-grep outline ventis/llm/bedrock.py --view expanded || true

echo
echo "Relevant bedrock.py"
cat -n ventis/llm/bedrock.py | sed -n '1,140p'

echo
echo "Search for _redis usage"
rg -n "_redis\\.(incr|hset_multiple|get_client|client)|hset_multiple\\(" ventis -S

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 3622


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "ventis/utils/redis_client.py"
cat -n ventis/utils/redis_client.py | sed -n '1,180p'

echo
echo "Search import and exception handling around call_bedrock"
rg -n "call_bedrock\\(|Bedrock|bedrock" ventis -S

echo
echo "Python exception semantics probe: exception in except/finally blocks and finally exception suppresses original"
python3 - <<'PY'
def original_error():
    try:
        raise RuntimeError("bedrock")
    except RuntimeError as e:
        raise RuntimeError("redis")
    finally:
        try:
            original_error()
        except RuntimeError:
            ...

try:
    original_error()
except Exception as exc:
    print(type(exc).__name__, str(exc))
    print("has __cause__:", hasattr(exc, "__cause__"), getattr(exc, "__cause__", None))
PY

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 4042


Make Redis telemetry best-effort and preserve Bedrock errors.

_redis.client.incr(...) and hset_multiple(...) currently run without protection, so Redis failures can suppress or replace the original Bedrock result/exception. Catch and log Redis telemetry errors separately so the caller still receives the primary Bedrock outcome.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/llm/bedrock.py` around lines 35 - 50, Make the Redis telemetry calls
in the exception and finally paths best-effort: wrap _redis.client.incr and
_redis.hset_multiple in separate protection that catches and logs telemetry
failures, while preserving the original Bedrock exception or result for the
caller. Keep the existing telemetry fields and agent/future conditions
unchanged.


1 change: 1 addition & 0 deletions ventis/stub_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Remove the trailing comma from the destination filename.

This copies the module as bedrock.py,, so import bedrock will fail in the generated Docker context.

🐛 Proposed fix
-        (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py,"),
+        (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py"),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py,"),
(os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py"),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/stub_generator.py` at line 316, Update the destination filename in the
stub generator’s source-to-destination mapping to remove the trailing comma,
ensuring the Bedrock module is generated as bedrock.py so it remains importable.

]

# Copy provided agent stubs
Expand Down
Loading