| LeadAgent | R Documentation |
'LeadAgent' extends 'Agent' to coordinate a group of specialized agents. It decomposes complex prompts into subtasks using LLMs and assigns each subtask to the most suitable registered agent. The lead agent handles response chaining, where each agent can consider prior results.
This class builds intelligent multi-agent workflows by delegating sub-tasks using 'delegate_prompt()', executing them with 'invoke()', and storing the results in the 'agents_interaction' list.
mini007::Agent -> LeadAgent
agentsA named list of registered sub-agents (by UUID).
agents_interactionA list of delegated task history with agent IDs, prompts, and responses.
planA list containing the most recently generated task plan.
hitl_stepsThe steps where the workflow should be stopped in order to allow for a human interaction
prompt_for_planThe prompt used to generate the plan.
agents_for_planThe agents used for the plan
dialog_historyA list storing the history of agent dialogs
broadcast_historyA list storing the history of broadcast interactions
mini007::Agent$add_message()mini007::Agent$clear_and_summarise_messages()mini007::Agent$clear_tools()mini007::Agent$clone_agent()mini007::Agent$export_messages_history()mini007::Agent$generate_and_register_tool()mini007::Agent$generate_execute_r_code()mini007::Agent$get_usage_stats()mini007::Agent$keep_last_n_messages()mini007::Agent$list_tools()mini007::Agent$load_messages_history()mini007::Agent$register_tools()mini007::Agent$remove_tools()mini007::Agent$reset_conversation_history()mini007::Agent$set_budget()mini007::Agent$set_budget_policy()mini007::Agent$update_instruction()mini007::Agent$validate_response()new()Initializes the LeadAgent with a built-in task-decomposition prompt.
LeadAgent$new(name, llm_object)
nameA short name for the coordinator (e.g. '"lead"').
llm_objectThe LLM object generate by ellmer (eg. output of ellmer::chat_openai)
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
clear_agents()Clear out the registered Agents
LeadAgent$clear_agents()
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = paste0(
"You are an agent designed to summarise ",
"a given text into 3 distinct bullet points."
),
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
lead_agent$clear_agents()
lead_agent$agents
remove_agents()Remove registered agents by IDs
LeadAgent$remove_agents(agent_ids)
agent_idsThe Agent ID to remove from the registered Agents
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
# deleting the translator agent
id_translator_agent <- translator$agent_id
lead_agent$remove_agents(id_translator_agent)
lead_agent$agents
register_agents()Register one or more agents for delegation.
LeadAgent$register_agents(agents)
agentsA vector of 'Agent' objects to register.
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
visualize_plan()Visualizes the orchestration plan Each agent node is shown in sequence (left → right), with tooltips showing the actual prompt delegated to that agent.
LeadAgent$visualize_plan()
invoke()Executes the full prompt pipeline: decomposition → delegation → invocation.
LeadAgent$invoke(prompt, force_regenerate_plan = FALSE)
promptThe complex user instruction to process.
force_regenerate_planIf TRUE, regenerate a plan even if one exists, defaults to FALSE.
The final response (from the last agent in the sequence).
\dontrun{
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed ",
"and accurate information. Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$invoke(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
}
generate_plan()Generates a task execution plan without executing the subtasks. It returns a structured list containing the subtask, the selected agent, and metadata.
LeadAgent$generate_plan(prompt)
promptA complex instruction to be broken into subtasks.
A list of lists containing agent_id, agent_name, model_name, model_provider, and the assigned prompt.
\dontrun{
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. Your job is to answer factual questions ",
"with detailed and accurate information. Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$generate_plan(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
}
broadcast()Broadcasts a prompt to all registered agents and collects their responses. This does not affect the main agent orchestration logic or history.
LeadAgent$broadcast(prompt)
promptA user prompt to send to all agents.
A list of responses from all agents.
\dontrun{
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1 <- ellmer::chat(
name = "openai/gpt-4.1",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_agent <- Agent$new(
name = "openai_4_1_agent",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_nano_agent <- Agent$new(
name = "openai_4_1_nano_agent",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1_nano
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(openai_4_1_agent, openai_4_1_nano_agent))
lead_agent$broadcast(
prompt = paste0(
"If I were Algerian, which song would I like to sing ",
"when running under the rain? how about a flower?"
)
)
}
set_hitl()Set Human In The Loop (HITL) interaction at determined steps within the workflow
LeadAgent$set_hitl(steps)
stepsAt which steps the Human In The Loop is required?
A list of responses from all agents.
\dontrun{
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = paste0(
"You are agent designed to summarise a give text ",
"into 3 distinct bullet points."
),
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
# setting a human in the loop in step 2
lead_agent$set_hitl(1)
# The execution will stop at step 2 and a human will be able
# to either accept the answer, modify it or stop the execution of
# the workflow
lead_agent$invoke(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
}
judge_and_choose_best_response()The Lead Agent send a prompt to its registered agents and choose the best response from the agents' responses
LeadAgent$judge_and_choose_best_response(prompt)
promptThe prompt to send to the registered agents
A list of responses from all agents, including the chosen response
\dontrun{
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1 <- ellmer::chat(
name = "openai/gpt-4.1",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
stylist <- Agent$new(
name = "stylist",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
stylist2 <- Agent$new(
name = "stylist2",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1_nano
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(stylist, stylist2))
lead_agent$judge_and_choose_best_response("what's the best way to war a kalvin klein shirt?")
}
agents_dialog()Facilitates a collaborative dialog between two agents to refine a response. The agents take turns building on each other's responses until they reach consensus or the maximum iterations are reached. Agents can signal consensus by starting their response with "CONSENSUS:". If max iterations is reached without consensus, the lead agent synthesizes a final response.
LeadAgent$agents_dialog(prompt, agent_1_id, agent_2_id, max_iterations = 5)
promptThe initial task or question for the agents to discuss.
agent_1_idThe ID of the first agent to participate in the dialog.
agent_2_idThe ID of the second agent to participate in the dialog.
max_iterationsMaximum number of back-and-forth exchanges (default: 5).
A list containing the final response, consensus status, and complete dialog history.
\dontrun{
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
creative_writer <- Agent$new(
name = "creative_writer",
instruction = "You are a creative writer. Focus on engaging storytelling.",
llm_object = openai_4_1_nano
)
editor <- Agent$new(
name = "editor",
instruction = "You are an editor. Focus on clarity and conciseness.",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(creative_writer, editor))
result <- lead_agent$agents_dialog(
prompt = "Write a compelling opening sentence for a sci-fi novel.",
agent_1_id = creative_writer$agent_id,
agent_2_id = editor$agent_id,
max_iterations = 3
)
# Access the final response
result$final_response
# View the dialog history
result$dialog_history
}
clone()The objects of this class are cloneable with this method.
LeadAgent$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `LeadAgent$new`
## ------------------------------------------------
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
## ------------------------------------------------
## Method `LeadAgent$clear_agents`
## ------------------------------------------------
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = paste0(
"You are an agent designed to summarise ",
"a given text into 3 distinct bullet points."
),
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
lead_agent$clear_agents()
lead_agent$agents
## ------------------------------------------------
## Method `LeadAgent$remove_agents`
## ------------------------------------------------
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
# deleting the translator agent
id_translator_agent <- translator$agent_id
lead_agent$remove_agents(id_translator_agent)
lead_agent$agents
## ------------------------------------------------
## Method `LeadAgent$register_agents`
## ------------------------------------------------
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$agents
## ------------------------------------------------
## Method `LeadAgent$invoke`
## ------------------------------------------------
## Not run:
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed ",
"and accurate information. Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$invoke(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
## End(Not run)
## ------------------------------------------------
## Method `LeadAgent$generate_plan`
## ------------------------------------------------
## Not run:
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. Your job is to answer factual questions ",
"with detailed and accurate information. Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = "You are agent designed to summarise a given text into 3 distinct bullet points.",
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
lead_agent$generate_plan(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
## End(Not run)
## ------------------------------------------------
## Method `LeadAgent$broadcast`
## ------------------------------------------------
## Not run:
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1 <- ellmer::chat(
name = "openai/gpt-4.1",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_agent <- Agent$new(
name = "openai_4_1_agent",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_nano_agent <- Agent$new(
name = "openai_4_1_nano_agent",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1_nano
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(openai_4_1_agent, openai_4_1_nano_agent))
lead_agent$broadcast(
prompt = paste0(
"If I were Algerian, which song would I like to sing ",
"when running under the rain? how about a flower?"
)
)
## End(Not run)
## ------------------------------------------------
## Method `LeadAgent$set_hitl`
## ------------------------------------------------
## Not run:
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
researcher <- Agent$new(
name = "researcher",
instruction = paste0(
"You are a research assistant. ",
"Your job is to answer factual questions with detailed and accurate information. ",
"Do not answer with more than 2 lines"
),
llm_object = openai_4_1_mini
)
summarizer <- Agent$new(
name = "summarizer",
instruction = paste0(
"You are agent designed to summarise a give text ",
"into 3 distinct bullet points."
),
llm_object = openai_4_1_mini
)
translator <- Agent$new(
name = "translator",
instruction = "Your role is to translate a text from English to German",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(researcher, summarizer, translator))
# setting a human in the loop in step 2
lead_agent$set_hitl(1)
# The execution will stop at step 2 and a human will be able
# to either accept the answer, modify it or stop the execution of
# the workflow
lead_agent$invoke(
paste0(
"Describe the economic situation in Algeria in 3 sentences. ",
"Answer in German"
)
)
## End(Not run)
## ------------------------------------------------
## Method `LeadAgent$judge_and_choose_best_response`
## ------------------------------------------------
## Not run:
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1 <- ellmer::chat(
name = "openai/gpt-4.1",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
stylist <- Agent$new(
name = "stylist",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
stylist2 <- Agent$new(
name = "stylist2",
instruction = "You are an AI assistant. Answer in 1 sentence max.",
llm_object = openai_4_1_nano
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(stylist, stylist2))
lead_agent$judge_and_choose_best_response("what's the best way to war a kalvin klein shirt?")
## End(Not run)
## ------------------------------------------------
## Method `LeadAgent$agents_dialog`
## ------------------------------------------------
## Not run:
# An API KEY is required in order to invoke the agents
openai_4_1_mini <- ellmer::chat(
name = "openai/gpt-4.1-mini",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
openai_4_1_nano <- ellmer::chat(
name = "openai/gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
echo = "none"
)
creative_writer <- Agent$new(
name = "creative_writer",
instruction = "You are a creative writer. Focus on engaging storytelling.",
llm_object = openai_4_1_nano
)
editor <- Agent$new(
name = "editor",
instruction = "You are an editor. Focus on clarity and conciseness.",
llm_object = openai_4_1_mini
)
lead_agent <- LeadAgent$new(
name = "Leader",
llm_object = openai_4_1_mini
)
lead_agent$register_agents(c(creative_writer, editor))
result <- lead_agent$agents_dialog(
prompt = "Write a compelling opening sentence for a sci-fi novel.",
agent_1_id = creative_writer$agent_id,
agent_2_id = editor$agent_id,
max_iterations = 3
)
# Access the final response
result$final_response
# View the dialog history
result$dialog_history
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.