c = RSACandidate(id='c1', loop_id=0, prompt='Hi')
c.response = 'Hey'
test_eq(c.id, 'c1')
test_eq(c.prompt, 'Hi')
cid:c1
loop_id:0
prompt:
Hi
response:
Hey
parent_ids:
None
A candidate response in the RSA algorithm
id:c1
loop_id:0
prompt:
Hi
response:
Hey
parent_ids:
None
def RSA(
task_prompt:str, # The main task/question to solve
agg_prompt:str=None, # Custom aggregation prompt
model:str='openrouter/google/gemini-3-flash-preview', # LLM model to use
M:int=8, # Number of candidates per loop
k:int=4, # Number of candidates to aggregate
loops:int=3, # Number of aggregation loops
history:list=None, # History of all candidates
temperature:float=1.0, # LLM temperature
n_workers:int=4, # Parallel workers
):
Recursive Self-Aggregation algorithm for LLM response aggregation
RSA(model='openrouter/google/gemini-3-flash-preview',
M=8,
k=4,
loops=3,
history=0 candidates,
task_prompt=A bat and ball cost $1.10 total. The bat costs $1 more than the ball. How much does the ball cost?)
'The ball costs **$0.05** (5 cents).\n\n**Here is the algebraic breakdown:**\n\n1. Let $x$ be the price of the ball.\n2. The bat costs $1 more than the ball, so the bat is $x + $1.00$.\n3. Together, they cost $1.10:\n $x + (x + 1.00) = 1.10$\n4. Simplify the equation:\n $2x + 1.00 = 1.10$\n5. Subtract 1.00 from both sides:\n $2x = 0.10$\n6. Divide by 2:\n $x = 0.05$\n\n**Check the math:**\nThe ball ($0.05) + the bat ($1.05) = $1.10.'
You are given question with training examples and a test input.
You are also provided several candidate solutions. Some candidates may be incorrect...,
Aggregate/consider all the candidates and use their help to produce the improved correct solution...
A bat and ball cost $1.10 total. The bat costs $1 more than the ball. How much does the ball cost?
CANDIDATE ANSWERS (may contain mistakes):
---- Candidate 1 ----
Answer A
---- Candidate 2 ----
Answer B
Your response:
You are given question with training examples and a test input.
You are also provided several candidate solutions. Some candidates may be incorrect...,
Aggregate/consider all the candidates and use their help to produce the improved correct solution...
A bat and ball cost $1.10 total. The bat costs $1 more than the ball. How much does the ball cost?
CANDIDATE ANSWERS (may contain mistakes):
---- Candidate 1 ----
Answer 3
---- Candidate 2 ----
Answer 0
---- Candidate 3 ----
Answer 2
---- Candidate 4 ----
Answer 6
Your response:
Call self as a function.