diff --git a/enterprise/lib/captain/tools/add_contact_note_tool.rb b/enterprise/lib/captain/tools/add_contact_note_tool.rb index 95246015a..e1475abf0 100644 --- a/enterprise/lib/captain/tools/add_contact_note_tool.rb +++ b/enterprise/lib/captain/tools/add_contact_note_tool.rb @@ -1,33 +1,23 @@ class Captain::Tools::AddContactNoteTool < Captain::Tools::BasePublicTool description 'Add a note to a contact profile' - param :contact_id, type: 'string', desc: 'The ID of the contact' param :note, type: 'string', desc: 'The note content to add to the contact' - def perform(_tool_context, note:, contact_id:) - log_tool_usage('add_contact_note', { contact_id: contact_id, note_length: note.length }) - - return 'Missing required parameters: contact_id, note' if note.blank? || contact_id.blank? - - contact = find_contact(contact_id) + def perform(tool_context, note:) + contact = find_contact(tool_context.state) return 'Contact not found' unless contact + return 'Note content is required' if note.blank? + + log_tool_usage('add_contact_note', { contact_id: contact.id, note_length: note.length }) + create_contact_note(contact, note) "Note added successfully to contact #{contact.name} (ID: #{contact.id})" end private - def find_contact(contact_id) - account_scoped(::Contact).find_by(id: contact_id) - end - def create_contact_note(contact, note) - contact.notes.create!( - account: @assistant.account, - contact: contact, - content: note, - user: @user - ) + contact.notes.create!(content: note) end def permissions diff --git a/enterprise/lib/captain/tools/base_public_tool.rb b/enterprise/lib/captain/tools/base_public_tool.rb index 27fa59ac4..e53f7a0f1 100644 --- a/enterprise/lib/captain/tools/base_public_tool.rb +++ b/enterprise/lib/captain/tools/base_public_tool.rb @@ -30,6 +30,13 @@ class Captain::Tools::BasePublicTool < Agents::Tool account_scoped(::Conversation).find_by(id: conversation_id) end + def find_contact(state) + contact_id = state[:contact][:id] + return nil unless contact_id + + account_scoped(::Contact).find_by(id: contact_id) + end + def log_tool_usage(action, details = {}) Rails.logger.info do "#{self.class.name}: #{action} for assistant #{@assistant&.id} - #{details.inspect}"