Repository navigation
Conversation
… tool truncation (openlit#2030) Signed-off-by: Dr. Mohammed Lubbad <[email protected]>
Reviewer's GuideImplementationNormalize and truncate tool arguments, extract readable text from block outputs, and map role-less Responses API calls, outputs, and reasoning into GenAI messages.
Apply the coding content-capture setting throughout observer hooks and span creation so message and tool bodies are exported only in full mode.
Format turn-start user content as structured message parts and truncate captured tool arguments and results to the configured content limit.
TestsTest Responses API item mapping, argument and result truncation, multimodal turn prompts, and capture-mode suppression and registration.
Mirror the main plugin tests in the CLI marketplace test suite to verify that the synchronized copy behaves identically.
Lock files and vendored codeSynchronize the embedded CLI marketplace Hermes plugin with the main implementation so both copies share the same capture and input-handling behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix Hermes Responses API capture, multimodal prompts, and tool truncation
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
Linked issuesChecked at commit 29a61c9 #2030 Bug: Hermes plugin drops Responses API tool/reasoning items, stringifies multimodal user_message, and skips tool truncation · 3 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="plugins/hermes/__init__.py" line_range="176-201" />
<code_context>
+def _responses_input_item(item: dict[str, Any]) -> dict[str, Any] | None:
</code_context>
<issue_to_address>
**Responses content bypasses capture mode**
When `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` while `OPENLIT_CODING_CONTENT_CAPTURE` is `metadata_only` or `minimal`, hermes’s Responses-item parser adds tool arguments, tool results, and reasoning to input messages, but the capture setup only checks `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` and does not enforce `OPENLIT_CODING_CONTENT_CAPTURE`. With content capture enabled and coding capture set to `metadata_only` or `minimal`, those bodies reach exported spans despite the configured mode.
Gate these body-bearing message parts on the configured full capture mode before adding them to exported spans.
Also at `cli/internal/coding/install/marketplace/plugins/hermes/__init__.py:176-201`.
</issue_to_address>
### Comment 2
<location path="plugins/hermes/__init__.py" line_range="184" />
<code_context>
+ call = {
+ "id": item.get("call_id") or item.get("id") or "",
+ "name": item.get("name") or "",
+ "arguments": arguments,
+ }
+ return {"role": "assistant", "parts": _tool_call_parts([call])}
</code_context>
<issue_to_address>
**Tool arguments exceed the content limit**
When content capture is enabled and a valid JSON tool argument exceeds `max_content_length`, `_tool_call_parts()` parses the arguments without truncating them, and `_set_llm_content()` serializes the full message into `gen_ai.input.messages`; oversized arguments are exported in full.
Enforce `max_content_length` on the serialized message content, including parsed tool arguments, before exporting it.
Also at `cli/internal/coding/install/marketplace/plugins/hermes/__init__.py:184`, `cli/internal/coding/install/marketplace/plugins/hermes/__init__.py:186`, `plugins/hermes/__init__.py:185-186`.
</issue_to_address>
### Comment 3
<location path="plugins/hermes/__init__.py" line_range="179" />
<code_context>
+def _responses_input_item(item: dict[str, Any]) -> dict[str, Any] | None:
+ """OTel GenAI message for a role-less Responses API input item, or None for chat messages."""
+ kind = item.get("type")
+ if kind in ("function_call", "custom_tool_call"):
+ arguments = item.get("arguments") if kind == "function_call" else item.get("input")
+ call = {
</code_context>
<issue_to_address>
**Shell calls disappear from captured history**
When a Responses input contains a role-less `local_shell_call` or its corresponding output item, `_responses_input_item()` does not handle these items, so `_input_messages()` falls back to an empty user message and drops the shell command and output from captured history.
Handle role-less `local_shell_call` and its output item in `_responses_input_item()`.
</issue_to_address>
### Comment 4
<location path="plugins/hermes/__init__.py" line_range="180-184" />
<code_context>
+ """OTel GenAI message for a role-less Responses API input item, or None for chat messages."""
+ kind = item.get("type")
+ if kind in ("function_call", "custom_tool_call"):
+ arguments = item.get("arguments") if kind == "function_call" else item.get("input")
+ call = {
+ "id": item.get("call_id") or item.get("id") or "",
+ "name": item.get("name") or "",
+ "arguments": arguments,
+ }
+ return {"role": "assistant", "parts": _tool_call_parts([call])}
</code_context>
<issue_to_address>
**Custom tool inputs are altered**
When a custom tool sends input that is valid JSON, including a falsey value such as `false` or `0`, `_tool_call_parts()` parses `custom_tool_call.input` as JSON, changing JSON-looking text and replacing falsey decoded values with `{}`; telemetry records altered custom tool input.
Preserve `custom_tool_call.input` as its original string instead of parsing it as JSON.
Also at `cli/internal/coding/install/marketplace/plugins/hermes/__init__.py:180-184`.
</issue_to_address>
### Comment 5
<location path="plugins/hermes/tests/test_openlit_plugin.py" line_range="662-663" />
<code_context>
+ observer.tool_call(**tool_payload(args={"command": "0123456789abcdef"}, result="0123456789abcdef"))
+
+ span = by_name(exporter)["execute_tool terminal"]
+ assert span.attributes[SC.GEN_AI_TOOL_CALL_ARGUMENTS].endswith("...")
+ assert len(span.attributes[SC.GEN_AI_TOOL_CALL_ARGUMENTS]) == 13
+ assert span.attributes[SC.GEN_AI_TOOL_CALL_RESULT] == "0123456789..."
+
</code_context>
<issue_to_address>
**Wrong tool arguments pass truncation check**
When argument capture emits a 10-character string unrelated to the supplied arguments, followed by `...`, `test_tool_call_respects_max_content_length` accepts any 13-character argument value ending in `...`: its assertions at lines 662–663 never check that the prefix comes from the supplied `args`, so incorrect argument capture passes.
Assert the exact expected truncated serialized arguments, including their prefix.
Also at `cli/internal/coding/install/marketplace/plugins/hermes/tests/test_openlit_plugin.py:662-663`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 5 findings to address first, and when content capture is enabled, this now exports tool arguments, tool results, and Responses API reasoning/output content into telemetry; those values can contain secrets or private data, and truncation only limits their length. Reverting stops future exports, but data already sent to an exporter cannot be recalled.
Blocking findings: plugins/hermes/__init__.py:201, plugins/hermes/__init__.py:184, plugins/hermes/__init__.py:179, plugins/hermes/__init__.py:184, plugins/hermes/tests/test_openlit_plugin.py:663
…ll items, and None tool results Signed-off-by: Dr. Mohammed Lubbad <[email protected]>
|
Addressed the review findings in commit
|
Issue number: Closes #2030
Change description:
Fixes three content-capture edge cases in the Hermes Agent observer plugin (
plugins/hermes/__init__.py) and syncs the embedded CLI marketplace copy viacli/scripts/sync-plugins.sh:codex_responses) input items: Parses role-lessfunction_call/custom_tool_call,function_call_output/custom_tool_call_output, andreasoningitems inrequest["body"]["input"]into OTel GenAIassistant(tool_call/reasoning) andtool(tool_call_response) messages instead of falling back to emptyusertext messages.user_messageonturn_start(): Formatsuser_messagevia_message("user", ...)instead offormat_input_message("user", ...)so multimodal content-block lists emit structured parts without copying base64 image payloads or Pythonreprstrings ontoinvoke_agent hermesspans.truncate_content()togen_ai.tool.call.argumentsandgen_ai.tool.call.resultintool_call()soOpenlitConfig.max_content_lengthis honored consistently across turn, LLM, and tool spans.Verified with
pytest -q plugins/hermes/testsagainst both./sdk/pythonandopenlit==1.45.0(72 passed), pluscli/scripts/sync-plugins.shparity check.Checklist
If your change doesn't seem to apply, please leave them unchecked.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.
Summary by Sourcery
Improve Hermes observability by accurately representing Responses API content, safely handling multimodal prompts, and enforcing configurable content-capture controls.
Bug Fixes:
Enhancements:
Tests:
Chores: