# Pull Request Template ~~Note: merge only after https://github.com/chatwoot/ai-agents/pull/74 has been merged~~ ## Description Before: <img width="436" height="617" alt="image" src="https://github.com/user-attachments/assets/fd5be8dc-abab-4e01-b251-366648b998ea" /> After: <img width="446" height="577" alt="image" src="https://github.com/user-attachments/assets/8d96d2f2-c126-4cca-b3a2-f2a62b204adf" /> <img width="441" height="558" alt="image" src="https://github.com/user-attachments/assets/89da4157-48a5-4fdc-9c67-9bf987e31638" /> ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. locally and specs ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sony Mathew <sony@chatwoot.com>
33 lines
791 B
Ruby
33 lines
791 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Captain::Assistant::InstrumentationAttributeProvider
|
|
include Integrations::LlmInstrumentationConstants
|
|
|
|
def initialize(service)
|
|
@service = service
|
|
end
|
|
|
|
def call(context_wrapper)
|
|
@service.send(:dynamic_trace_attributes, context_wrapper)
|
|
end
|
|
|
|
def generation_attributes(_context_wrapper, _chat, message)
|
|
{
|
|
format(ATTR_LANGFUSE_OBSERVATION_METADATA, 'generation_stage') => generation_stage(message)
|
|
}
|
|
end
|
|
|
|
private
|
|
|
|
def generation_stage(message)
|
|
message_has_tool_calls?(message) ? 'tool_call' : 'final_response'
|
|
end
|
|
|
|
def message_has_tool_calls?(message)
|
|
return false unless message.respond_to?(:tool_calls)
|
|
|
|
tool_calls = message.tool_calls
|
|
tool_calls.respond_to?(:any?) && tool_calls.any?
|
|
end
|
|
end
|