3  Agent

library(rtemis.llm)
  .:rtemis.llm v.0.8.0 🌊 aarch64-apple-darwin20

3.1 Create an Agent object

create_agent + config_ functions allow you to create Agent objects using different backends:

  • config_Ollama() for Ollama
  • config_OpenAI() for OpenAI and OpenAI-compatible endpoints
  • config_Anthropic() for Claude and Anthropic-compatible endpoints

Learn more about Ollama here

Let’s create an Agent with an Ollama backend for local, private LLM use:

agent <- create_agent(
  config_Ollama(
    model_name = "gemma4:e4b",
    temperature = 0.5
  ),
  system_prompt = "You are an expert music producer with in-depth knowledge of music theory and digital audio workstations.",
  name = "MusicProducer"
)
agent
<Agent>
         Name: MusicProducer
System Prompt: You are an expert music producer with in-depth knowledge of ...
       Memory: Enabled
        Tools: (None)
   LLM Config:
               <OllamaConfig>
                model_name: gemma4:e4b
               temperature: 0.50
                   backend: ollama
                  base_url: http://localhost:11434
                     think: NULL
 

3.2 Generate a response

res <- generate(agent, "What is the drum pattern of a classic drum and bass beat? Respond with no more than 2 sentences.")
2026-04-24 08:34:41 [gemma4:e4b] working... [generate]
2026-04-24 08:34:56 [gemma4:e4b] done. [generate]
res
$system
[MusicProducer System] You are an expert music producer with in-depth knowledge of music theory and digital audio workstations. 

$user
[Input] What is the drum pattern of a classic drum and bass beat? Respond with no more than 2 sentences. 

$assistant
[MusicProducer Reasoning] Here's a thinking process to arrive at the suggested response:

1.  **Analyze the Request:** The user is asking for the "drum pattern of a classic drum and bass beat." The response must be concise (no more than two sentences).
2.  **Identify the Core Subject:** Drum and Bass (DnB) is characterized by high tempo (typically 160-180 BPM) and a specific rhythmic feel.
3.  **Deconstruct the Pattern (The "Sound"):**
    *   *Tempo:* Fast, driving.
    *   *Kick:* Punchy, often syncopated, driving the rhythm.
    *   *Snare/Clap:* Sharp, usually hitting on the 2 and 4 (the backbeat), but often layered or heavily processed.
    *   *Hi-Hats:* The defining element. They are fast, intricate, and often utilize complex, rapid-fire rolls (often 1/16th or 1/32nd notes) to create energy and groove.
4.  **Synthesize into a Technical Description (The "How"):** I need to describe this pattern using musical terminology that sounds authoritative (expert producer voice).
    *   *Focus:* The complexity and the groove.
    *   *Sentence 1 (The Structure):* Address the main components (kick, snare, hats) and the tempo.
    *   *Sentence 2 (The Feel/Signature Element):* Highlight the defining characteristic—the rapid, complex hi-hat work.
5.  **Draft and Refine (Checking Constraints):**
    *   *Draft:* It's a high-tempo, syncopated pattern featuring a heavy, punchy kick drum on the downbeats. The signature element is the rapid, complex hi-hat work, which utilizes intricate rolls and syncopation to drive the energy.
    *   *Review:* (2 sentences? Yes. Expert tone? Yes. Accurate? Yes.)

6.  **Final Output Generation.** (This matches the provided good response.)

[MusicProducer Response] A classic DnB beat is high-tempo and highly syncopated, featuring a deep, punchy kick drum pattern that drives the rhythm, complemented by a sharp snare or clap on the 2 and 4. The defining characteristic is the rapid, intricate hi-hat work, which utilizes fast rolls and complex subdivisions (often 1/16th or 1/32nd notes) to build intense, propulsive energy. 

3.3 Batch generation

  1. Create an Agent object:
agent <- create_agent(
  config_Ollama(
    model_name = "gemma4:e4b",
    temperature = 0.2
  ),
  system_prompt = "Return the notes in the minor chord built on the following root note, in format [root, minor third, perfect fifth]"
)
x <- c("A", "B", "C")
  1. Use map to batch generate responses to multiple prompts:
hex <- map(x, agent)
2026-04-24 08:34:56 [gemma4:e4b] working... [map]
2026-04-24 08:34:58 [gemma4:e4b] done. [map]
hex
[[1]]
[[1]]$system
[System] Return the notes in the minor chord built on the following root note, in format [root, minor third, perfect fifth] 

[[1]]$user
[Input] A 

[[1]]$assistant
[Response] [A, C, E] 


[[2]]
[[2]]$system
[System] Return the notes in the minor chord built on the following root note, in format [root, minor third, perfect fifth] 

[[2]]$user
[Input] A 

[[2]]$assistant
[Response] [A, C, E] 

[[2]]$user
[Input] B 

[[2]]$assistant
[Response] [B, D, F#] 


[[3]]
[[3]]$system
[System] Return the notes in the minor chord built on the following root note, in format [root, minor third, perfect fifth] 

[[3]]$user
[Input] A 

[[3]]$assistant
[Response] [A, C, E] 

[[3]]$user
[Input] B 

[[3]]$assistant
[Response] [B, D, F#] 

[[3]]$user
[Input] C 

[[3]]$assistant
[Response] [C, Eb, G] 

Extract the assistant responses as a character vector:

responses(hex)
[1] "[A, C, E]"  "[B, D, F#]" "[C, Eb, G]"
© 2026 E.D. Gennatas