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
4 changes: 4 additions & 0 deletions src/rai_core/rai/agents/langchain/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def __init__(
self.stream_response = stream_response
self.splitting_chars = splitting_chars or ["\n", ".", "!", "?"]
self.chunks_buffer = ""
if not isinstance(max_buffer_size, int) or isinstance(max_buffer_size, bool):
raise ValueError("max_buffer_size must be a positive int")
if max_buffer_size <= 0:
raise ValueError("max_buffer_size must be a positive int")
self.max_buffer_size = max_buffer_size
self._buffer_lock = threading.Lock()
self.logger = logger or logging.getLogger(__name__)
Expand Down
18 changes: 18 additions & 0 deletions tests/agents/langchain/test_hri_callback_max_buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2026 Robotec.AI
import pytest

from rai.agents.langchain.callback import HRICallbackHandler


def test_hri_callback_rejects_non_positive_max_buffer_size():
with pytest.raises(ValueError, match="max_buffer_size"):
HRICallbackHandler(connectors={}, max_buffer_size=0)
with pytest.raises(ValueError, match="max_buffer_size"):
HRICallbackHandler(connectors={}, max_buffer_size=-5)
with pytest.raises(ValueError, match="max_buffer_size"):
HRICallbackHandler(connectors={}, max_buffer_size=True) # type: ignore[arg-type]


def test_hri_callback_accepts_positive_max_buffer_size():
h = HRICallbackHandler(connectors={}, max_buffer_size=16)
assert h.max_buffer_size == 16
Loading