Class: SignalWire::Skills::Builtin::DatasphereSkill

Inherits:
SkillBase
  • Object
show all
Defined in:
lib/signalwire/skills/builtin/datasphere.rb

Instance Attribute Summary

Attributes inherited from SkillBase

#agent, #logger, #params, #swaig_fields

Instance Method Summary collapse

Methods inherited from SkillBase

#cleanup, #get_hints, #get_param, #initialize, #required_env_vars, #version

Constructor Details

This class inherits a constructor from SignalWire::Skills::SkillBase

Instance Method Details

#descriptionObject



16
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 16

def description; 'Search knowledge using SignalWire DataSphere RAG stack'; end

#get_global_dataObject



63
64
65
66
67
68
69
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 63

def get_global_data
  {
    'datasphere_enabled'  => true,
    'document_id'         => @document_id,
    'knowledge_provider'  => 'SignalWire DataSphere'
  }
end

#get_parameter_schemaObject



86
87
88
89
90
91
92
93
94
95
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 86

def get_parameter_schema
  {
    'space_name'  => { 'type' => 'string', 'required' => true },
    'project_id'  => { 'type' => 'string', 'required' => true, 'env_var' => 'SIGNALWIRE_PROJECT_ID' },
    'token'       => { 'type' => 'string', 'required' => true, 'hidden' => true, 'env_var' => 'SIGNALWIRE_TOKEN' },
    'document_id' => { 'type' => 'string', 'required' => true },
    'count'       => { 'type' => 'integer', 'default' => 1, 'min' => 1, 'max' => 10 },
    'distance'    => { 'type' => 'number', 'default' => 3.0 }
  }
end

#get_prompt_sectionsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 71

def get_prompt_sections
  [
    {
      'title' => 'Knowledge Search Capability',
      'body' => "You can search a knowledge base for information using the #{@tool_name} tool.",
      'bullets' => [
        "Use the #{@tool_name} tool when users ask for information that might be in the knowledge base",
        'Search for relevant information using clear, specific queries',
        'Summarize search results in a clear, helpful way',
        'If no results are found, suggest the user try rephrasing their question'
      ]
    }
  ]
end

#instance_keyObject



48
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 48

def instance_key; "datasphere_#{@tool_name}"; end

#nameObject



15
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 15

def name;        'datasphere'; end

#register_toolsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 50

def register_tools
  [
    {
      name: @tool_name,
      description: 'Search the knowledge base for information on any topic and return relevant results',
      parameters: {
        'query' => { 'type' => 'string', 'description' => 'The search query' }
      },
      handler: method(:handle_search)
    }
  ]
end

#setupObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 19

def setup
  @space_name  = get_param('space_name')
  @project_id  = get_param('project_id', env_var: 'SIGNALWIRE_PROJECT_ID')
  @token       = get_param('token', env_var: 'SIGNALWIRE_TOKEN')
  @document_id = get_param('document_id')
  @count       = (get_param('count', default: 1)).to_i
  @distance    = (get_param('distance', default: 3.0)).to_f
  @tool_name   = get_param('tool_name', default: 'search_knowledge')
  @tags        = get_param('tags')
  @no_results_msg = get_param('no_results_message',
    default: "I couldn't find any relevant information in the knowledge base. Try rephrasing your question.")

  %w[space_name project_id token document_id].each do |k|
    return false if instance_variable_get("@#{k}").nil? || instance_variable_get("@#{k}").to_s.empty?
  end

  # Default to {space}.signalwire.com host; DATASPHERE_BASE_URL
  # overrides the host (the `/api/datasphere/...` path is preserved
  # so the audit can match on `datasphere` in req.path).
  override = ENV['DATASPHERE_BASE_URL']
  host_url = if override.nil? || override.empty?
               "https://#{@space_name}.signalwire.com"
             else
               override.sub(/\/$/, '')
             end
  @api_url = "#{host_url}/api/datasphere/documents/search"
  true
end

#supports_multiple_instances?Boolean

Returns:

  • (Boolean)


17
# File 'lib/signalwire/skills/builtin/datasphere.rb', line 17

def supports_multiple_instances?; true; end