Skip to content

Add generic RSA (Recursive Self-Aggregation) algorithm framework#124

Open
shashankk42 wants to merge 11 commits into
FLASK-LLNL:mainfrom
shashankk42:feature/rsa-generic-algorithm
Open

Add generic RSA (Recursive Self-Aggregation) algorithm framework#124
shashankk42 wants to merge 11 commits into
FLASK-LLNL:mainfrom
shashankk42:feature/rsa-generic-algorithm

Conversation

@shashankk42
Copy link
Copy Markdown

@shashankk42 shashankk42 commented Apr 12, 2026

Summary

Add generic Recursive Self-Aggregation (RSA) algorithm with 3-part prompt structure.

Changes

  • Add charge/algorithms/rsa.py with N-K-T RSA implementation
  • New 3-part prompt structure:
    • system_prompt: Domain expert definition (same for proposals and aggregations)
    • proposal_prompt: Task instructions for generating solutions
    • aggregation_prompt: Task instructions for evaluating/synthesizing solutions
  • Add RSAConfig, RSAPrompts, RSACallbacks, RSATaskFactories
  • Add run_rsa_loop() with parallel proposal generation and recursive aggregation
  • Add minimal working example to README

API

  • Works out-of-box with generic defaults
  • Customizable for domain-specific tasks (chemistry, LMO, etc.)
  • Supports custom schemas, formatters, validators, and tools

Testing

  • Standalone test with generic defaults
  • Chemistry-specific test (aspirin synthesis)
  • Correct N-K-T workflow execution

Related PRs

@shashankk42 shashankk42 marked this pull request as draft April 16, 2026 22:28
@shashankk42 shashankk42 force-pushed the feature/rsa-generic-algorithm branch from 83e7a55 to cdc9fa2 Compare April 24, 2026 00:04
@shashankk42 shashankk42 marked this pull request as ready for review April 24, 2026 01:50
@shashankk42 shashankk42 marked this pull request as draft April 24, 2026 04:51
@shashankk42 shashankk42 marked this pull request as ready for review April 24, 2026 05:02
@shashankk42 shashankk42 marked this pull request as draft April 24, 2026 06:30
@shashankk42 shashankk42 marked this pull request as ready for review April 24, 2026 06:34
@bvanessen bvanessen force-pushed the feature/rsa-generic-algorithm branch from 9b73603 to ffbe801 Compare May 1, 2026 20:47
Comment thread charge/algorithms/rsa.py Outdated
Copy link
Copy Markdown
Contributor

@tbennun tbennun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the code. I think this PR needs to be refactored to the Task interface as we discussed. Maybe even have FLASK-Copilot use that interface directly with its prompts.

Comment thread charge/algorithms/rsa.py
_DEFAULT_AGGREGATION_TEMPLATE = _PROMPTS_DIR / "default_aggregation_template.txt"


# Generic default output schema
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code and all the classes seem quite excessive. Why do we need a class for RSAPrompts? If RSA extends a Task we should add those fields there?

Comment thread charge/algorithms/rsa.py
)


class RSACallbacks:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary to put in a separate class

Comment thread charge/algorithms/rsa.py
return task


class RSATaskFactories(Generic[T]):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make a generic RSA task factory? What is the need for the factory design pattern? I thought that there should just be an RSATask that extends Task

Comment thread charge/algorithms/rsa.py
k = config.k

# Helper function to run a single proposal
async def run_single_proposal(proposal_index: int, proposal_runner: Any):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long nested functions... Hard to understand the flow.

Comment thread charge/algorithms/rsa.py
await callbacks.logger_info(f"Generated {len(proposals)} valid proposals")

# Helper function to run a single aggregation
async def run_single_aggregation(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, please refactor out

Shashank Kushwaha and others added 11 commits May 13, 2026 07:19
Create charge/algorithms/ with RSAConfig, RSACallbacks, RSATaskFactories to make RSA reusable for any task type.
Add task-agnostic default prompts that users can swap out for domain-specific needs.
Document how to use default prompts and swap them for domain-specific needs.
Add GenericRSAOutput schema, default_format_candidates, and default task factories so RSA works immediately without customization.
Allows domain-specific prompts to be passed to aggregation tasks,
enabling clean separation between generic RSA and domain customization.
- system_prompt: Domain expert definition (constant across proposal and aggregation)
- proposal_prompt: Task instructions for generating proposals
- aggregation_prompt: Task instructions for evaluating/aggregating

This provides cleaner separation: expertise (system) vs task (user prompt).
- Add minimal working example using ChARGe only
- Document 3-part prompt structure (system, proposal, aggregation)
- Remove stale 2-part prompt references
- Clear progression from basic to advanced usage
- Remove flask-copilot dependencies from examples
- Enforce N, K, T >= 2 (T=1 would skip aggregation)
- Enforce K <= N at construction time in RSAConfig.__post_init__
- Remove redundant K validation in run_rsa_loop
- Improve error messages with actionable guidance
- Add logging when K is adjusted due to proposal failures
@bvanessen bvanessen force-pushed the feature/rsa-generic-algorithm branch from 79c870e to 4435b50 Compare May 13, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants