Class: RubyLLM::Chat

Inherits:
Object
  • Object
show all
Includes:
ConcurrentToolExecution, MultiSubscriberCallbacks
Defined in:
lib/swarm_sdk/ruby_llm_patches/responses_api_patch.rb,
lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb,
lib/swarm_sdk/ruby_llm_patches/tool_concurrency_patch.rb,
lib/swarm_sdk/ruby_llm_patches/message_management_patch.rb

Defined Under Namespace

Modules: ConcurrentToolExecution, MultiSubscriberCallbacks Classes: Subscription

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MultiSubscriberCallbacks

#after_tool_calls, #around_llm_request, #around_tool_execution, #callback_count, #clear_callbacks, #complete, #initialize, #on_end_message, #on_new_message, #on_tool_call, #on_tool_result, #once, #subscribe

Methods included from ConcurrentToolExecution

#initialize, #with_tool_concurrency

Instance Attribute Details

#max_concurrencyObject (readonly)

Returns the value of attribute max_concurrency.



133
134
135
# File 'lib/swarm_sdk/ruby_llm_patches/tool_concurrency_patch.rb', line 133

def max_concurrency
  @max_concurrency
end

#responses_sessionResponsesSession? (readonly)

Get the current Responses API session

Returns:



597
598
599
# File 'lib/swarm_sdk/ruby_llm_patches/responses_api_patch.rb', line 597

def responses_session
  @responses_session
end

#tool_concurrencyObject (readonly)

Returns the value of attribute tool_concurrency.



133
134
135
# File 'lib/swarm_sdk/ruby_llm_patches/tool_concurrency_patch.rb', line 133

def tool_concurrency
  @tool_concurrency
end

Instance Method Details

#reset_messages!(preserve_system_prompt: true) ⇒ self

Override reset_messages! to support preserve_system_prompt option

Parameters:

  • preserve_system_prompt (Boolean) (defaults to: true)

    If true (default), keeps system messages

Returns:

  • (self)

    for chaining



14
15
16
17
18
19
20
21
# File 'lib/swarm_sdk/ruby_llm_patches/message_management_patch.rb', line 14

def reset_messages!(preserve_system_prompt: true)
  if preserve_system_prompt
    @messages.select! { |m| m.role == :system }
  else
    @messages.clear
  end
  self
end

#responses_api_enabled?Boolean

Check if Responses API is enabled

Returns:

  • (Boolean)

    true if Responses API is enabled



590
591
592
# File 'lib/swarm_sdk/ruby_llm_patches/responses_api_patch.rb', line 590

def responses_api_enabled?
  @responses_api_enabled == true
end

#restore_responses_session(session_hash) ⇒ self

Restore a Responses API session from saved state

Parameters:

  • session_hash (Hash)

    Session state from ResponsesSession#to_h

Returns:

  • (self)

    for chaining



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/swarm_sdk/ruby_llm_patches/responses_api_patch.rb', line 571

def restore_responses_session(session_hash)
  @responses_session = ResponsesSession.from_h(session_hash)

  if @provider.is_a?(Providers::OpenAIResponses)
    # Re-create provider with restored session
    @provider = Providers::OpenAIResponses.new(
      @config,
      @responses_session,
      @provider.responses_config,
    )
    @connection = @provider.connection
  end

  self
end

#with_responses_api(stateful: false, store: true, truncation: :disabled, include: []) ⇒ self

Enable OpenAI Responses API for this chat

Parameters:

  • stateful (Boolean) (defaults to: false)

    Enable stateful mode (uses previous_response_id)

  • store (Boolean) (defaults to: true)

    Store responses for retrieval

  • truncation (Symbol) (defaults to: :disabled)

    Truncation strategy (:disabled, :auto)

  • include (Array) (defaults to: [])

    Additional data to include in responses

Returns:

  • (self)

    for chaining



552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/swarm_sdk/ruby_llm_patches/responses_api_patch.rb', line 552

def with_responses_api(stateful: false, store: true, truncation: :disabled, include: [])
  responses_config = {
    stateful: stateful,
    store: store,
    truncation: truncation,
    include: include,
  }

  @responses_session ||= ResponsesSession.new
  @provider = Providers::OpenAIResponses.new(@config, @responses_session, responses_config)
  @connection = @provider.connection
  @responses_api_enabled = true
  self
end