diff --git a/enterprise/app/models/captain/assistant.rb b/enterprise/app/models/captain/assistant.rb index bf4691e2c..dc0969cd4 100644 --- a/enterprise/app/models/captain/assistant.rb +++ b/enterprise/app/models/captain/assistant.rb @@ -98,7 +98,8 @@ class Captain::Assistant < ApplicationRecord def agent_tools [ self.class.resolve_tool_class('faq_lookup').new(self), - self.class.resolve_tool_class('handoff').new(self) + self.class.resolve_tool_class('handoff').new(self), + *account.captain_custom_tools.enabled.map { |custom_tool| custom_tool.tool(self) } ] end diff --git a/spec/enterprise/models/captain/assistant_spec.rb b/spec/enterprise/models/captain/assistant_spec.rb new file mode 100644 index 000000000..e282124ae --- /dev/null +++ b/spec/enterprise/models/captain/assistant_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +RSpec.describe Captain::Assistant do + describe '#agent_tools' do + let(:account) { create(:account) } + let(:assistant) { create(:captain_assistant, account: account) } + + it 'includes enabled custom tools from the assistant account' do + custom_tool = create(:captain_custom_tool, account: account) + + tools = assistant.send(:agent_tools) + + expect(tools.map(&:name)).to include(custom_tool.slug) + expect(tools.find { |tool| tool.name == custom_tool.slug }).to be_a(Captain::Tools::HttpTool) + end + + it 'excludes disabled custom tools' do + custom_tool = create(:captain_custom_tool, :disabled, account: account) + + tools = assistant.send(:agent_tools) + + expect(tools.map(&:name)).not_to include(custom_tool.slug) + end + + it 'excludes custom tools from other accounts' do + custom_tool = create(:captain_custom_tool) + + tools = assistant.send(:agent_tools) + + expect(tools.map(&:name)).not_to include(custom_tool.slug) + end + + it 'keeps the built-in FAQ lookup and handoff tools' do + tools = assistant.send(:agent_tools) + + expect(tools).to include( + an_instance_of(Captain::Tools::FaqLookupTool), + an_instance_of(Captain::Tools::HandoffTool) + ) + end + end +end