feat(llm-observability): $ai_tools capture in Langchain#199
Merged
Conversation
Contributor
There was a problem hiding this comment.
PR Summary
This PR enhances LLM observability in the Langchain callback handler by adding support for capturing tools as $ai_tools, which are important components of LLM input prompts that were previously not being tracked.
- Added
toolsfield toGenerationMetadataclass inposthog/ai/langchain/callbacks.pyto store tool configurations provided to the model - Implemented tool extraction from invocation parameters in
_set_llm_metadatamethod to capture tool data during LLM calls - Added
$ai_toolsproperty to event properties when capturing generation events for complete tool visibility - Created new test case
test_metadata_toolsinposthog/test/ai/langchain/test_callbacks.pyto verify proper tool data capture and retrieval - Focused implementation only affects Langchain callback handler without modifying SDK wrappers
2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
| "type": "string", | ||
| }, | ||
| }, | ||
| "required": ["query_description", "query_kind"], |
Contributor
There was a problem hiding this comment.
logic: The 'required' array references 'query_description' and 'query_kind' parameters that don't exist in the properties object, which only has 'bar'.
Suggested change
| "required": ["query_description", "query_kind"], | |
| "required": ["bar"], |
k11kirky
approved these changes
Feb 27, 2025
933ebf6 to
6623d18
Compare
We really need lint-staged here.
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.
Tools are part of the LLM input prompt, and we haven't been capturing them at all in LLM observability!
This PR adds capturing of tools as
$ai_toolsto the Langchain callback handler. Does not touch SDK wrappers.