Module: AgentC::Agent::Chats::AnthropicBedrock

Defined in:
lib/agent_c/agent/chats/anthropic_bedrock.rb

Class Method Summary collapse

Class Method Details

.create(project:, run_id:, prompts:, agent_store:, ruby_llm_context:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
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
# File 'lib/agent_c/agent/chats/anthropic_bedrock.rb', line 7

def self.create(project:, run_id:, prompts:, agent_store:, ruby_llm_context:)
  ruby_llm_config = ruby_llm_context.config

  chat = agent_store.chat
    .create!(
      model: agent_store.model.find_or_create_by!(
        model_id: ruby_llm_config.default_model,
        provider: "bedrock"
      ) { |m|
        m.name = "Claude Sonnet 4.5"
        m.family = "claude"
      },
      project: project,
      run_id: run_id
    )

  # Set the context on the chat record so to_llm can use it
  chat.define_singleton_method(:context) { ruby_llm_context }

  chat.tap { |chat|
    if prompts.any?
      # WARN -- RubyLLM: Anthropic's Claude implementation only supports
      # a single system message. Multiple system messages will be
      # combined into one.
      shared_prompt = prompts.join("\n---\n")
      chat.messages.create!(
        role: :system,
        content_raw: [
          {
            "type" => "text",
            "text" => shared_prompt,
            "cache_control" => { "type" => "ephemeral" }
          }
        ]
      )
    end
  }
end