A thin, opinionated wrapper around an ellmer::Chat object. Adds identity
(name, role), conversation management helpers, and cumulative cost tracking.
All LLM logic is delegated to ellmer.
Arguments
- name
Character. Unique identifier for this agent within a workflow.
- chat
An
ellmer::Chatobject (e.g.ellmer::chat_anthropic()).- role
Character or
NULL. Short role description.- instructions
Character or
NULL. Detailed system instructions.- tools
List of
ellmer::tool()objects.- handoffs
Character vector of agent names for handoffs.
- max_retries
Integer. Retries on transient API errors (default
3L).- retry_wait
Numeric. Seconds between retries (default
5).
Value
A new Agent object.
The assistant's response as a character string.
Parsed R object matching type.
A coro generator yielding text chunks.
A new Agent with the same configuration but no turns.
List of turn objects from ellmer.
Numeric, total USD spent so far.
Named list with input and output integer elements.
An Agent R6 object.
Functions
agent(): Construct anAgentfrom anellmer::Chatobject.
Active bindings
nameAgent name (read-only).
roleAgent role description (read-only).
handoffsNames of agents this agent may hand off to (read-only).
Methods
Method new()
Create a new Agent.
Arguments
nameCharacter. Unique identifier used in graph node configs.
chatAn
ellmer::Chatobject (e.g. fromellmer::chat_anthropic()).roleCharacter or
NULL. Short role description prepended to the system prompt.instructionsCharacter or
NULL. Detailed instructions appended to the system prompt.toolsList of
ellmer::tool()objects to register on the chat.handoffsCharacter vector of agent names this agent may hand off to.
max_retriesInteger. Number of times to retry a failed API call before raising an error (default
3L). Set to0Lto disable retries.retry_waitNumeric. Seconds to wait between retries (default
5).
Method chat()
Send a message to the agent, retrying on transient errors.
Examples
if (FALSE) { # \dontrun{
ag <- agent(
name = "researcher",
chat = ellmer::chat_anthropic(),
role = "Senior researcher",
instructions = "Be thorough and cite sources.",
max_retries = 3L,
retry_wait = 5
)
} # }