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 that leads to the suggested response:
1. **Analyze the Request:** The user is asking for the "drum pattern of a classic drum and bass beat."
2. **Analyze the Constraints:** The response must be "no more than 2 sentences."
3. **Determine the Core Knowledge (Expert Persona):** As an expert music producer, I need to describe the *feel* and *structure* of DnB, not just list generic drum sounds.
4. **Identify Key Elements of Classic DnB:**
* Tempo: Fast (usually 160-180 BPM).
* Rhythm: Highly syncopated, aggressive, and complex.
* The Kick/Snare/Hat Pattern: The hallmark is the rapid, driving, and often slightly swung breakbeat (e.g., the Amen break influence).
* Focus: The emphasis is on the rapid, complex interplay of the hi-hats and the punchy, often distorted kick.
5. **Drafting - Attempt 1 (Mental Outline):** It's fast and complex. It uses a heavily syncopated breakbeat, focusing on rapid, rolling hi-hats and a punchy, driving kick drum that locks into the rapid tempo. (Too dry, maybe two sentences but lacks flair).
6. **Refining and Condensing (Focusing on the 'Vibe' and the 'Technique'):** I need to capture the *energy* and the *rhythmic complexity* in two sentences.
* *Sentence 1 (The Core):* Describe the tempo and the breakbeat nature.
* *Sentence 2 (The Detail/Feel):* Focus on the specific interplay of the elements (hats and kick).
7. **Final Polish (Expert Tone):** (Self-Correction: Ensure the language is technical but accessible.)
**(Result matches the final provided answer.)**
[MusicProducer Response] A classic DnB pattern is characterized by a fast, highly syncopated breakbeat, typically utilizing a complex, rapid-fire rhythm derived from classic breaks like the Amen. The pattern emphasizes a driving, punchy kick drum paired with aggressively rolled and heavily quantized hi-hats, creating a relentless, propulsive energy that defines the genre's signature momentum.
attr(,"agent_output")
[1] TRUE
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]
attr(,"agent_output")
[1] TRUE
[[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#]
attr(,"agent_output")
[1] TRUE
[[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]
attr(,"agent_output")
[1] TRUE
attr(,"elapsed")
[1] 0.645 0.669 0.862
attr(,"errors")
[1] index message
<0 rows> (or 0-length row.names)
Extract the assistant responses as a character vector:
responses(hex)[1] "[A, C, E]" "[B, D, F#]" "[C, Eb, G]"