feat: add a resolve tool

This commit is contained in:
Shivam Mishra
2025-12-09 18:17:27 +05:30
parent 863c033699
commit bb9f07d662
2 changed files with 51 additions and 0 deletions
+5
View File
@@ -34,3 +34,8 @@
title: 'Handoff to Human'
description: 'Hand off the conversation to a human agent'
icon: 'user-switch'
- id: resolve
title: 'Resolve Conversation'
description: 'Mark the conversation as resolved'
icon: 'checkmark-circle'
@@ -0,0 +1,46 @@
class Captain::Tools::ResolveTool < Captain::Tools::BasePublicTool
description 'Mark the conversation as resolved when the issue has been addressed'
param :reason, type: 'string', desc: 'The reason why the conversation is being resolved (optional)', required: false
def perform(tool_context, reason: nil)
conversation = find_conversation(tool_context.state)
return 'Conversation not found' unless conversation
return 'Conversation is already resolved' if conversation.resolved?
log_tool_usage('tool_resolve', {
conversation_id: conversation.id,
reason: reason || 'Agent resolved conversation'
})
resolve_conversation(conversation, reason)
"Conversation marked as resolved#{" (Reason: #{reason})" if reason.present?}"
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
'Failed to resolve conversation'
end
private
def resolve_conversation(conversation, reason)
# Add a private note with the reason if provided
if reason.present?
conversation.messages.create!(
message_type: :outgoing,
private: true,
sender: @assistant,
account: conversation.account,
inbox: conversation.inbox,
content: "Resolved: #{reason}"
)
end
# Mark conversation as resolved
conversation.resolved!
end
def permissions
%w[conversation_manage conversation_unassigned_manage conversation_participating_manage]
end
end