mini007 is a lightweight and extensible R framework for building
multi-agent AI systems. It lets you create specialised LLM-backed
agents, orchestrate them through a lead agent that decomposes and
delegates complex tasks, and wire them together into explicit sequential
pipelines called Workflows, all built on top of the excellent
ellmer package and compatible with
any chat model it supports.
library(mini007)
retrieve_open_ai_credential <- function() {
Sys.getenv("OPENAI_API_KEY")
}
llm <- ellmer::chat(
name = "openai/gpt-4.1-mini",
credentials = retrieve_open_ai_credential,
echo = "none"
)
Agent a stateful LLM-backed workerAn Agent wraps an ellmer chat object and adds identity, persistent
message history, budget tracking, and tool support.
researcher <- Agent$new(
name = "researcher",
instruction = "You are a research assistant. Answer factual questions concisely.",
llm_object = llm
)
researcher$invoke("What is the capital of Algeria?")
Agents remember the full conversation, so follow-up questions work naturally:
researcher$invoke("And what is its population?")
Key capabilities:
$messages, trimming
via $keep_last_n_messages(), export/import via
$export_messages_history() / $load_messages_history().$share_context_with(other_agent).$set_budget() and
choose a policy ("abort", "warn", or "ask") via
$set_budget_policy().ellmer tool objects with $register_tools(),
generate new ones from a natural-language description with
$generate_and_register_tool().$generate_execute_r_code().$validate_response().$clone_agent().LeadAgent multi-agent orchestrationA LeadAgent extends Agent with the ability to decompose a complex
prompt into subtasks and automatically delegate each one to the most
suitable registered agent.
summariser <- Agent$new(
name = "summariser",
instruction = "Summarise text into three bullet points.",
llm_object = llm
)
translator <- Agent$new(
name = "translator",
instruction = "Translate text from English to German.",
llm_object = llm
)
lead <- LeadAgent$new(name = "Lead", llm_object = llm)
lead$register_agents(c(summariser, translator))
lead$invoke("Summarise the history of the Roman Empire, then translate it into German.")
Key capabilities:
$generate_plan().$visualize_plan().$broadcast().$judge_and_choose_best_response().$agents_dialog().$set_hitl(steps).Workflow explicit sequential pipelinesA Workflow lets you build a predefined pipeline of Stations
connected by Routes. Each Station’s output becomes the next one’s
input. Unlike LeadAgent, the execution path is fully explicit, you
control the order and branching logic.
wf <- Workflow$new(name = "article-pipeline")
wf$add_station("research", Agent$new(
name = "researcher",
instruction = "Gather concise facts on the topic.",
llm_object = llm
))
wf$add_station("write", Agent$new(
name = "writer",
instruction = "Turn the facts into an engaging paragraph.",
llm_object = llm
))
wf$add_station("edit", Agent$new(
name = "editor",
instruction = "Polish the paragraph for grammar and clarity.",
llm_object = llm
))
wf$add_route("research", "write")
wf$add_route("write", "edit")
wf$run("The history of the printing press")
Key capabilities:
Agent objects, WorkflowAgent
objects, or plain R functions, making it easy to mix LLM calls with
deterministic pre/post-processing steps.add_route(from, to, condition) gates a
route on a function of the previous Station’s output, enabling
branching pipelines.use_cache = TRUE (default), each Station’s result
is stored by (name, input). Re-running the same input serves the
cache instantly. Use $clear_cache() to reset.$set_hitl(steps) pauses execution at
specified steps so a human can review, edit, or stop the output before
it flows into the next Station.$as_agent() converts any Workflow into a
WorkflowAgent that can be registered with a LeadAgent or embedded
as a Station inside another Workflow.$visualize() renders the pipeline as an
interactive directed graph via DiagrammeR.$set_daemons() and $add_parallel_group()
enable multiple independent Stations to run concurrently, providing
2-4x speedup for independent tasks like multi-agent analysis.Agent, Workflow, and LeadAgent can all stream their progress
instead of blocking until the final answer is ready. stream = TRUE
prints tokens as they are generated; an on_event callback receives
typed events (token deltas, tool calls, station and task progress, HITL
requests), including those of nested agents. The return value is the
same as without streaming.
researcher$invoke("Explain photosynthesis in two sentences.", stream = TRUE)
wf$run("The history of the printing press", on_event = function(event) {
if (event$type == "station_started") cat("\n>", event$data$station, "\n")
if (event$type == "text_delta") cat(event$text)
})
Raising an error inside on_event cancels the run cleanly. See the
Streaming
article for the
full event reference.
You can install mini007 from CRAN with:
install.packages("mini007")
The documentation is available here
Please note that the mini007 project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.