Skip to content

Conversation

@vellanki-santhosh
Copy link

I TIRED TO FIX THE BUG , PLS REVIEW THE CHANGES

…ad; pass full output to analytics so Langfuse can display tokens and cost\n\n- Map Flowise usage metadata to Langfuse usage fields (promptTokens, completionTokens, totalTokens)\n- Include model from response metadata when available for cost mapping\n- Send complete output objects from LLM/Agent/ConditionAgent to analytics\n- No functional behavior change outside analytics payloads
Track usage and cost information in langfuse traces even when LLM calls result in errors. This ensures complete cost/usage analytics for all LLM operations, including failed attempts.

- Extract usage metadata (promptTokens, completionTokens, totalTokens) from error objects
- Extract model information from response metadata
- Set error level to 'ERROR' in langfuse generation end payload
- Maintain consistency with onLLMEnd handling of usage metadata
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vellanki-santhosh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug related to Langfuse trace usage cost by enhancing the data sent to Langfuse for LLM interactions. The changes ensure that detailed usage metrics and model information are accurately captured and reported, providing better observability and cost analysis for LLM applications.

Highlights

  • Enhanced Langfuse Integration: The pull request significantly improves the integration with Langfuse by sending more comprehensive data for LLM completions and errors, including usage metadata (prompt, completion, total tokens) and model information.
  • Updated onLLMEnd and onLLMError Signatures: The onLLMEnd function in AnalyticHandler now accepts an any type for its output parameter, allowing it to receive detailed objects instead of just a string. Similar changes are applied to onLLMError.
  • Detailed Usage and Model Tracking: The AnalyticHandler now parses usage_metadata and response_metadata from the LLM output/error objects to populate Langfuse's usage and model fields, providing richer analytics.
  • Consistent Data Passing Across Agent Nodes: Agent nodes (Agent, ConditionAgent, LLM) have been updated to pass a more complete output object to analyticHandlers.onLLMEnd, ensuring that the necessary metadata is available for Langfuse tracking.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix an issue with Langfuse cost and usage tracking by passing more detailed output objects to the analytics handler. The changes are generally in the right direction. However, I've identified a redundant function call in Agent.ts that should be removed for better performance and maintainability. More critically, there's a bug in handler.ts where token counts of 0 are not being correctly handled, which would lead to inaccurate usage tracking. I've provided suggestions to fix these issues. Additionally, there is some code duplication between the onLLMEnd and onLLMError methods in handler.ts that could be a candidate for future refactoring.

@vellanki-santhosh
Copy link
Author

Thanks for the review! 🙏
Good catch on the usage check — I’ll update it to use !== undefined so 0 tokens are handled correctly.
Also noted the redundant call in Agent.ts; I’ll clean that up. Refactor for onLLMEnd / onLLMError duplication can be a follow‑up.

@vellanki-santhosh
Copy link
Author

Thanks for the feedback!

  • Fixed token usage check to handle 0 correctly.
  • Removed redundant call in Agent.ts.
    Refactor of onLLMEnd/onLLMError duplication will be done in a separate PR.
    Ready for re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant