Class: NitroIntelligence::Assistant

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro_intelligence/assistant.rb

Overview

One assistant resolved by name: the client for its deployment, plus the id every run has to carry.

Credentials are supplied by the host. Where they come from is the host's business -- an environment variable its deployment mounts, a secrets store, a literal in configuration -- so nothing here encodes one deployment's wiring.

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

DEFAULT_USER_ID =
Assistants::DEFAULT_USER_ID
REQUIRED =

base_url is not among them: the client defaults it, so it cannot be missing.

%w[api_key assistant_id].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, base_url: nil, api_key: nil, assistant_id: nil, user_id: nil, **_kwargs) ⇒ Assistant

The key is positional so that splatting an entry cannot overwrite it, whatever the entry happens to carry.

Extra keys are accepted and ignored for the same reason: an entry carries fields the application has no use for, such as the graph or the observability project it reports to.



30
31
32
33
34
35
36
37
38
# File 'lib/nitro_intelligence/assistant.rb', line 30

def initialize(key, base_url: nil, api_key: nil, assistant_id: nil, user_id: nil, **_kwargs)
  @key = key.to_s
  @base_url = base_url.presence || Assistants::DEFAULT_BASE_URL
  @api_key = api_key.presence
  @assistant_id = assistant_id.presence
  @user_id = user_id.presence || DEFAULT_USER_ID

  validate!
end

Instance Attribute Details

#assistant_idObject (readonly)

Returns the value of attribute assistant_id.



23
24
25
# File 'lib/nitro_intelligence/assistant.rb', line 23

def assistant_id
  @assistant_id
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



23
24
25
# File 'lib/nitro_intelligence/assistant.rb', line 23

def base_url
  @base_url
end

#keyObject (readonly)

The key an assistant is filed and looked up under. Not its name: an entry usually carries a name of its own, a human-readable label for the assistant's record, and the two are different things.



21
22
23
# File 'lib/nitro_intelligence/assistant.rb', line 21

def key
  @key
end

#user_idObject (readonly)

Returns the value of attribute user_id.



23
24
25
# File 'lib/nitro_intelligence/assistant.rb', line 23

def user_id
  @user_id
end

Instance Method Details

#await_run(thread_id:, messages:, **kwargs) ⇒ Object

The two calls that identify an assistant take it from here rather than from the caller. Everything else is thread-scoped and delegates untouched.



46
47
48
49
# File 'lib/nitro_intelligence/assistant.rb', line 46

def await_run(thread_id:, messages:, **kwargs)
  reject_assistant_id!(kwargs)
  client.await_run(thread_id:, assistant_id:, messages:, **kwargs)
end

#clientObject



40
41
42
# File 'lib/nitro_intelligence/assistant.rb', line 40

def client
  @client ||= Assistants.new(base_url: @base_url, api_key: @api_key, user_id: @user_id)
end

#review_tool_calls(thread_id:, reviewer_id:, tool_calls:, **kwargs) ⇒ Object



51
52
53
54
# File 'lib/nitro_intelligence/assistant.rb', line 51

def review_tool_calls(thread_id:, reviewer_id:, tool_calls:, **kwargs)
  reject_assistant_id!(kwargs)
  client.review_tool_calls(thread_id:, assistant_id:, reviewer_id:, tool_calls:, **kwargs)
end