Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #384.
truncate_by_length()can return 534 characters for a 500-character limit because its JSON path omits the truncation marker and JSON escaping from its length calculation. The text fallback also appends its marker after taking the full character budget.Account for each field's serialized JSON length, including its marker, and use a binary search to retain the longest fitting prefix. Preserve the existing minimum retained field length and process further fields when needed. Reserve marker space in the fallback, handle zero-sized budgets, and return content that already fits unchanged.
The existing training challenges are preserved. If JSON cannot fit while keeping minimum field lengths, the helper continues to fall back to text, now within the requested limit. Small limits that cannot hold a marker retain only the content prefix.
Testing
On Windows with Python 3.10:
PYTHONPATH=services/chatbot/src python -m pytest services/chatbot/src/chatbot/tests/test_agent_utils.py -q: 34 passed, including all 15 pre-existing tests.git diff --check: passed.Tested independently from the Helm fix. Tests use the existing dependency stubs and do not require LLM credentials or databases. A live chatbot session and the full container stack were not run. Added a focused CI job for this utility suite and formatting checks.
Documentation
Added utility test instructions and truncation behavior to
services/chatbot/README.md, and added pytest to the development requirements. The existing test module was formatted with Black.Checklist: