handle action key

This commit is contained in:
aakashb95
2026-01-05 18:13:06 +05:30
parent 548360583e
commit 2cbc14e366
3 changed files with 10 additions and 6 deletions
@@ -78,7 +78,7 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
end
def handoff_requested?
@response['response'] == 'conversation_handoff'
@response['action'] == 'handoff'
end
def process_action(action)
@@ -97,9 +97,10 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
end
def create_handoff_message
create_outgoing_message(
@assistant.config['handoff_message'].presence || I18n.t('conversations.captain.handoff')
)
handoff_message = @response['response'].presence ||
@assistant.config['handoff_message'].presence ||
I18n.t('conversations.captain.handoff')
create_outgoing_message(handoff_message)
end
def create_messages
@@ -95,7 +95,8 @@ class Captain::Assistant::AgentRunnerService
def error_response(error_message)
{
'response' => 'conversation_handoff',
'reasoning' => "Error occurred: #{error_message}"
'reasoning' => "Error occurred: #{error_message}",
'action' => 'handoff'
}
end
@@ -57,11 +57,13 @@ module Enterprise::MessageTemplates::HookExecutionService
return unless conversation.pending?
Rails.logger.info("Captain limit exceeded, performing handoff mid-conversation for conversation: #{conversation.id}")
handoff_message = inbox.captain_assistant&.config&.dig('handoff_message').presence ||
'Transferring to another agent for further assistance.'
conversation.messages.create!(
message_type: :outgoing,
account_id: conversation.account.id,
inbox_id: conversation.inbox.id,
content: 'Transferring to another agent for further assistance.'
content: handoff_message
)
conversation.bot_handoff!
send_out_of_office_message_after_handoff