library(rtemis.llm)3 Agent
3.1 Create an Agent object
create_agent + config_ functions allow you to create Agent objects using different backends:
config_Ollama()for Ollamaconfig_OpenAI()for OpenAI and OpenAI-compatible endpointsconfig_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.")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."
2. **Identify the Persona/Expertise:** I must respond as an expert music producer with deep knowledge of music theory and DAWs.
3. **Determine the Core Characteristic of DnB Drums:** Classic DnB (especially the Jungle/early DnB sound) is defined by its tempo (usually 160β180 BPM) and its complex, syncopated, and often heavily swung breakbeats, most famously the Amen break.
4. **Structure the Answer (Constraint Check):** The response must be no more than two sentences.
5. **Drafting Content (Focusing on technical description):**
* *Attempt 1 (Too vague):* It's fast and syncopated. It uses lots of reverb. (Not expert enough).
* *Attempt 2 (Too long/detailed):* The pattern is built around highly syncopated, chopped breakbeats, most notably the Amen break. It emphasizes rapid hi-hat sixteenth notes and a heavily swung kick/snare pattern that drives the rhythm forward at high BPMs. (Getting closer, but maybe slightly over two sentences).
* *Refining for Brevity and Impact (The Expert Voice):* Focus on the *source* (the breakbeat) and the *feel* (the syncopation/tempo).
6. **Final Polish (The Two-Sentence Rule):**
* *Sentence 1:* Define the core element (the breakbeat and tempo).
* *Sentence 2:* Describe the characteristic rhythmic feel (syncopation, hats, energy).
7. **Final Output Generation.** (This matches the provided good response.)
[MusicProducer Response] The foundation is typically a heavily chopped and syncopated breakbeat, most famously the Amen break, played at high tempos (160β180 BPM). This pattern emphasizes rapid, complex hi-hat sixteenth notes and a powerful, swung kick/snare backbone that drives the relentless energy.
3.3 Batch generation
- Create an
Agentobject:
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]",
use_memory = FALSE
)
x <- c("A", "B", "C")- Use
mapto batch generate responses to multiple prompts:
hex <- map(x, agent)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] 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] 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]"