Class: Chorus::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/chorus/agent.rb

Overview

Base class for every Chorus agent. A concrete agent only needs to define its name and system_prompt — the call to the LLM is factored out here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Agent

Returns a new instance of Agent.

Parameters:



14
15
16
# File 'lib/chorus/agent.rb', line 14

def initialize(client:)
  @client = client
end

Instance Attribute Details

#nameSymbol (readonly)

Returns the agent's identifier, e.g. :coder.

Returns:

  • (Symbol)

    the agent's identifier, e.g. :coder



8
9
10
# File 'lib/chorus/agent.rb', line 8

def name
  @name
end

#system_promptString (readonly)

Returns the system prompt describing this agent's role and limits.

Returns:

  • (String)

    the system prompt describing this agent's role and limits



11
12
13
# File 'lib/chorus/agent.rb', line 11

def system_prompt
  @system_prompt
end

Instance Method Details

#call(context_slice) ⇒ String

Sends a context slice to the LLM and returns its text response.

Parameters:

  • context_slice (Array<Hash>)

    messages formatted as {role:, content:}, as produced by Chorus::Context#slice_for.

Returns:

  • (String)

    the agent's response text



23
24
25
# File 'lib/chorus/agent.rb', line 23

def call(context_slice)
  @client.chat(system_prompt: system_prompt, messages: context_slice)
end