Factory function to create a ProgramOfThoughtModule that generates and
executes R code to solve problems.
Use run() to execute it. run_async() supports factory-backed modules;
async streaming and module $stream() entry points reject ProgramOfThought.
run_stream() preserves the synchronous forward() fallback unless a
matching token-stream request is active; that request is rejected first.
Usage
program_of_thought(
signature,
runner = NULL,
interpreter_factory = NULL,
max_iters = 3L,
extract_answer = TRUE,
config = list(),
chat = NULL,
...
)Arguments
- signature
A Signature object or string notation defining inputs/outputs
- runner
Optional caller-owned code runner implementing
execute()andpolicy(). It is retained, never automatically shut down, and must not be shared concurrently when persistent.- interpreter_factory
Optional zero-argument function returning a fresh runner with
execute(),policy(), optionalstart(), and idempotent terminalshutdown(). Supply exactly one ofrunnerandinterpreter_factory.- max_iters
Maximum code generation/repair iterations (default 3)
- extract_answer
Logical. If TRUE (default), use LLM to extract final answer from execution result. If FALSE, return execution result directly.
- config
Optional prediction configuration.
- chat
Optional ellmer Chat object.
- ...
Must be empty.
Examples
if (FALSE) { # \dontrun{
runner <- r_code_runner(timeout = 30)
pot <- program_of_thought("question -> answer", runner = runner)
result <- run(pot, question = "Calculate 847 * 293", .llm = llm)
} # }