Apply an Agent over a vector of prompts
agentapply.Rdagentapply is the lapply-style entry point for running a single prompt against an Agent
repeatedly over a vector of inputs. Pass either a model name (in which case an Agent is built
on the fly using backend, system_prompt, tools, use_memory, max_tool_rounds,
output_schema) or a pre-built Agent object.
Usage
agentapply(
x,
model_or_agent,
backend = c("ollama", "openai", "anthropic"),
system_prompt = SYSTEM_PROMPT_DEFAULT,
tools = NULL,
use_memory = FALSE,
max_tool_rounds = 3L,
output_schema = NULL,
verbosity = 1L,
extract_responses = TRUE,
...
)Arguments
- x
Character or list: Values to iterate over.
- model_or_agent
Character or Agent: Either the name of a model (a string) or a pre-built
Agentobject from create_agent.- backend
Character {"ollama", "openai", "anthropic"}: Backend to use when
model_or_agentis a string. Ignored whenmodel_or_agentis anAgentobject.- system_prompt
Character: System prompt for the on-the-fly
Agent.- tools
Optional list of Tool objects: Tools available to the on-the-fly
Agent.- use_memory
Logical: Whether the on-the-fly
Agentshould keep conversation memory.- max_tool_rounds
Integer [1, Inf): Maximum number of tool call rounds per query.
- output_schema
Optional Schema: Output schema for the on-the-fly
Agent.- verbosity
Integer [0, Inf): Verbosity level.
- extract_responses
Logical: If
TRUE, return a character vector of assistant responses. IfFALSE, return the raw list of lists ofMessageobjects.- ...
Additional per-call arguments forwarded to generate.
Value
If extract_responses = TRUE, a character vector the same length as x. Otherwise, a
list of lists of Message objects.
Details
Unlike llmapply, this function can carry tools and memory. The default is use_memory = FALSE
because the common case for vectorized calls is independent queries.