feat(ruby_llm): capture prompt, completion, and tool I/O when capture_bodies is enabled - #2
Merged
Conversation
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.
The
capture_bodiesflag existed but the RubyLLM adapter never read it, so every trace recorded only shape: spans, tokens, cost, latency. A trace could show that a turn called a tool and what it cost, but not what was asked, what came back, or what the tool returned — which is most of what makes a trace worth reading when a turn goes wrong.This implements the flag and releases it as 0.2.0.
What is captured
With
capture_bodiesenabled, the root span carriesllm.prompt,llm.instructionsandllm.completion, and each tool span carriestool.argumentsandtool.result. Each value is truncated to 4,000 characters (RubyLLM::CONTENT_LIMIT).Two details worth calling out:
llm.instructionsjoins every system message. RubyLLM'swith_instructionsappends by default, so a chat can carry several; reporting only the last would hide a layered base prompt and misrepresent what the model actually saw.record_errorpath.Capture stays off by default
Prompts and tool results carry whatever the application sends the model, so enabling this is a data-handling decision for the app, not a default. Worth being explicit that the 4,000-character limit is a cap on trace size, not a redaction boundary — a tool result naming a person still names them within its first 4,000 characters.
Verification
13 runs, 41 assertions, 0 failures, including two new cases: one asserting that nothing is captured by default, and one asserting the full attribute set, the joined instructions, and the truncation limit when the flag is on.Also exercised end to end from a Rails app against a live dashboard: with the flag set, all five attributes arrive populated and the tool result truncates at exactly 4,000 characters; with it unset, traces still deliver with every one of those keys absent.