Factory function to create a CodeActModule that can use both tools and
R code execution to solve problems.
Use run() to execute it. run_async() supports factory-backed modules;
async streaming and module $stream() reject CodeAct. run_stream()
preserves the synchronous forward() fallback unless a matching
token-stream request is active; that request is rejected first.
Usage
code_act(
signature,
tools = list(),
runner = NULL,
max_iterations = 10L,
...,
interpreter_factory = NULL
)Arguments
- signature
A Signature object or string notation defining inputs/outputs
- tools
List of ellmer ToolDef objects for the agent to use. Non-empty list element names become the registered tool names; unnamed elements keep their ToolDef name. Effective names may contain only letters, numbers, hyphens, and underscores.
- runner
Optional caller-owned code runner implementing
execute()andpolicy(). It is retained, never automatically closed, and must not be shared concurrently when persistent.- max_iterations
Maximum outer agent iterations and maximum tool calls within one invocation (default 10). Exceeding the inner tool-call budget raises a
dsprrr_codeact_iteration_limiterror.- ...
Additional arguments passed to the module
- interpreter_factory
Optional zero-argument function returning a fresh runner with
execute(),policy(), optionalstart(), and idempotent terminalshutdown()orclose(). Supply exactly one ofrunnerandinterpreter_factory.
Examples
if (FALSE) { # \dontrun{
runner <- r_code_runner(timeout = 30)
agent <- code_act(
"question -> answer",
tools = list(),
runner = runner
)
result <- run(agent, question = "Calculate 2^10", .llm = llm)
} # }