ArchitectAgent: ArchitectAgent: An Agent that Designs and Builds Multi-Agent...

ArchitectAgentR Documentation

ArchitectAgent: An Agent that Designs and Builds Multi-Agent Workflows

Description

An 'ArchitectAgent' interviews you about what you need, then designs and builds the agents and the [Workflow] that does it. It works in three steps:

1. **Interview** ($interview()): it asks one question at a time about the task and the prompts the workflow will receive, the expected output, what matters most (low cost, reliability, speed or a balance), which of your models it may use, how many agents you want, a budget, whether a review step is wanted and whether steps may run in parallel. It skips what you have already answered and stops once it knows enough. 2. **Blueprint** ($draft_blueprint()): it designs the agents. Each one gets a name, a system prompt, its task in the workflow, one of your models, an effort level ('"low"', '"medium"' or '"high"'), its tools and the agents whose results it needs. Agents that do not depend on each other are put in the same stage and can run in parallel. When no tool you gave fits a need, it proposes a new one. 3. **Build** ($build()): it writes the R code of the new tools, creates the agents (a [ReActAgent] for each agent with tools, an [Agent] otherwise) and wires them into a [Workflow], stage by stage.

$design() runs the three steps in a row. It shows you the blueprint, and then the code of any new tool, before building, so you can ask for changes first.

Details

**Models.** The architect can only assign the models you give it in 'models', a named list of ellmer chat objects; the names are the labels it chooses from. It reads each model's provider, name and price (from [set_prices()] or ellmer's price table) to weigh cost against capability, plus any note you give in 'model_notes'.

**Effort.** An agent's effort level shapes its system prompt: a '"low"' effort agent is told to answer directly and briefly, a '"high"' effort agent to reason step by step and check its work. Effort also guides the choice of model: when cost matters most, the architect favours cheap models and low effort; when reliability matters most, strong models and high effort for the critical steps. To also set a provider-level reasoning effort, pass the same model several times with different 'params', eg. '"gpt-5-mini (low)" = ellmer::chat_openai(model = "gpt-5-mini", params = ellmer::params(reasoning_effort = "low"))', and describe them in 'model_notes'.

**Tools.** The architect assigns the ellmer tools you give it in 'toolbox', reading their names, descriptions and arguments. When a task needs a tool that is not there (fetching data, computing, reading a file), it proposes a new one in the blueprint: a name, what it does, its arguments and what it returns. $write_tools() then writes each new tool's R code, a function wrapped in 'ellmer::tool()', into '$tool_code'. The code only runs when $build() creates the tools, and $design() shows it to you and asks first. You can edit '$tool_code' before building. Created tools are added to '$toolbox', so later designs can reuse them. Set 'allow_new_tools = FALSE' to restrict the architect to your 'toolbox'.

**The built workflow.** Its first station, '"intake"', receives your request. Every agent is then sent the request, its own task and the results of the agents it depends on, and nothing else. A stage of several agents runs as a parallel group (between a '"fork_<n>"' and a '"join_<n>"' station) when 'parallel = TRUE', and one agent after another otherwise. The workflow's result is the last stage's output. It is built with 'use_cache = FALSE', since each agent reads the current request rather than only its station input.

The interview and design calls go through the architect's own 'llm_object', so they add to its turn history and its cost, like any [Agent]'s.

Super class

mini007::Agent -> ArchitectAgent

Public fields

models

Named list of ellmer chat objects the architect may assign to the agents it designs.

model_notes

Named character vector of notes about the models (eg. '"fast but weak at reasoning"'), keyed by model label.

toolbox

Named list of ellmer tools the architect may assign, including the new tools it created.

allow_new_tools

Whether the architect may propose and write new tools.

tool_code

Named character vector: the R code of each new tool, written by $write_tools().

transcript

The interview so far: a list of question/answer pairs, each with 'question', 'options' and 'answer'.

blueprint

The latest design, a 'mini007_blueprint', or 'NULL'.

workflow

The latest [Workflow] built by $build(), or 'NULL'.

built_agents

Named list of the [Agent]s created by the latest $build().

Methods

Public methods

Inherited methods

Method new()

Creates a new ArchitectAgent.

Usage
ArchitectAgent$new(
  name,
  llm_object,
  models = NULL,
  model_notes = NULL,
  toolbox = NULL,
  allow_new_tools = TRUE,
  budget = NA
)
Arguments
name

A short name for the architect (eg. '"architect"').

llm_object

The ellmer chat object the architect itself uses to interview and design. It must support structured output.

models

A named list of ellmer chat objects that the designed agents may use. Each name is the label the architect sees and assigns. Defaults to 'llm_object' alone, labelled with its model name.

model_notes

Optional named character vector of notes about the models, keyed by label: strengths, limits, speed, reasoning effort.

toolbox

Optional list of ellmer tools ('ellmer::tool()') the designed agents may use, or a single one.

allow_new_tools

'[logical(1)]' Whether the architect may propose new tools and write their code. Defaults to 'TRUE'.

budget

Budget in US$ for the architect's own calls, as in [Agent].

Examples
\dontrun{
architect <- ArchitectAgent$new(
  name = "architect",
  llm_object = ellmer::chat_openai(model = "gpt-4.1", echo = "none"),
  models = list(
    "gpt-4.1-mini" = ellmer::chat_openai(model = "gpt-4.1-mini", echo = "none"),
    "gpt-4.1" = ellmer::chat_openai(model = "gpt-4.1", echo = "none")
  ),
  toolbox = list(
    ellmer::tool(
      function(wilaya) paste("Population data for", wilaya),
      name = "wilaya_population",
      description = "Population of an Algerian wilaya.",
      arguments = list(wilaya = ellmer::type_string("The wilaya's name."))
    )
  )
)

# Asks its questions in the console, shows the blueprint and the code of
# any new tool, then builds it
wf <- architect$design(
  "Write a short, well-sourced travel guide for any Algerian wilaya."
)
wf$visualize()
wf$run("Tamanrasset, with a focus on the Hoggar mountains")
}

Method add_tools()

Adds ellmer tools to the toolbox the architect assigns from.

Usage
ArchitectAgent$add_tools(tools)
Arguments
tools

An ellmer tool ('ellmer::tool()') or a list of them.

Returns

The architect, invisibly.


Method design()

Runs the whole design: interviews you, drafts a blueprint, shows it and, once you approve it, builds the workflow.

After showing the blueprint, it asks whether to build it. Answer '"yes"' to build, '"cancel"' to stop without building, or describe the changes you want and it revises the blueprint and asks again. When the blueprint has new tools, it then writes their code, shows it and asks again in the same way before running it.

Usage
ArchitectAgent$design(
  goal = NULL,
  max_questions = 8,
  ask = NULL,
  confirm = TRUE,
  parallel = TRUE
)
Arguments
goal

Optional description of what the workflow should do. When 'NULL', the interview starts by asking for it.

max_questions

'[integer(1)]' The largest number of interview questions. Defaults to 8.

ask

'[function | NULL]' How questions are put to you: a function(question, options) returning the answer as a string. 'options' is a character vector of suggested answers, possibly empty. Defaults to a console prompt, which needs an interactive session.

confirm

'[logical(1)]' Whether to show the blueprint and the code of new tools, and ask before building. With 'FALSE', the new tools' code runs without review. Defaults to 'TRUE'.

parallel

'[logical(1)]' Passed to $build().

Returns

The built [Workflow], or 'NULL' (invisibly) when cancelled.


Method interview()

Interviews you about the workflow you need, one question at a time, until the architect knows enough or 'max_questions' is reached. Answer '"done"' to stop early; an empty answer leaves that choice to the architect. Calling it again continues the same interview.

Usage
ArchitectAgent$interview(goal = NULL, max_questions = 8, ask = NULL)
Arguments
goal

Optional description of what the workflow should do.

max_questions

'[integer(1)]' The largest number of questions.

ask

'[function | NULL]' See $design().

Returns

The transcript (a list of question/answer pairs), invisibly.


Method draft_blueprint()

Designs the agents and their stages from the interview.

Usage
ArchitectAgent$draft_blueprint()
Returns

The blueprint, a 'mini007_blueprint': a list with 'name', 'summary', 'priority', 'rationale', 'agents' (one list per agent, with 'name', 'instruction', 'task', 'model', 'effort', 'budget', 'tools', 'depends_on' and 'reason'), 'new_tools' (one list per tool to create, with 'name', 'description', 'arguments' and 'returns') and 'stages' (a list of character vectors of agent names; the agents of one stage can run in parallel).


Method revise()

Revises the blueprint following your feedback (eg. '"use only two agents"' or '"put the reviewer on the strongest model"').

Usage
ArchitectAgent$revise(feedback)
Arguments
feedback

What to change, in plain words.

Returns

The revised blueprint.


Method write_tools()

Writes the R code of the blueprint's new tools into '$tool_code', without running it. Each tool is a function wrapped in 'ellmer::tool()'. Tools already in '$toolbox' are skipped.

Usage
ArchitectAgent$write_tools(feedback = NULL)
Arguments
feedback

Optional changes to make to the code already written, in plain words. All the new tools are then rewritten.

Returns

'$tool_code', invisibly.


Method build()

Creates the blueprint's agents and wires them into a [Workflow].

New tools are created first: their code is written with $write_tools() if it has not been yet, then run, and each tool is added to ‘$toolbox'. When a tool’s code fails to run, the architect is given the error and rewrites it, up to twice. Agents with tools are built as [ReActAgent]s.

Usage
ArchitectAgent$build(blueprint = self$blueprint, parallel = TRUE)
Arguments
blueprint

The blueprint to build. Defaults to '$blueprint'.

parallel

'[logical(1)]' Whether a stage of several agents runs as a parallel group. If so, daemons are started (one per agent of the widest stage) unless the session already has enough; shut them down with wf$set_daemons(0). With 'FALSE', its agents run one after another. Defaults to 'TRUE'.

Returns

The [Workflow]. The agents are in '$built_agents'.


Method clone()

The objects of this class are cloneable with this method.

Usage
ArchitectAgent$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `ArchitectAgent$new`
## ------------------------------------------------

## Not run: 
architect <- ArchitectAgent$new(
  name = "architect",
  llm_object = ellmer::chat_openai(model = "gpt-4.1", echo = "none"),
  models = list(
    "gpt-4.1-mini" = ellmer::chat_openai(model = "gpt-4.1-mini", echo = "none"),
    "gpt-4.1" = ellmer::chat_openai(model = "gpt-4.1", echo = "none")
  ),
  toolbox = list(
    ellmer::tool(
      function(wilaya) paste("Population data for", wilaya),
      name = "wilaya_population",
      description = "Population of an Algerian wilaya.",
      arguments = list(wilaya = ellmer::type_string("The wilaya's name."))
    )
  )
)

# Asks its questions in the console, shows the blueprint and the code of
# any new tool, then builds it
wf <- architect$design(
  "Write a short, well-sourced travel guide for any Algerian wilaya."
)
wf$visualize()
wf$run("Tamanrasset, with a focus on the Hoggar mountains")

## End(Not run)

mini007 documentation built on Dec. 3, 2026, 5:10 p.m.