feat: implement Reflection agentic design pattern#231
Merged
lijingrs merged 2 commits intomofa-org:mainfrom Feb 23, 2026
Merged
feat: implement Reflection agentic design pattern#231lijingrs merged 2 commits intomofa-org:mainfrom
lijingrs merged 2 commits intomofa-org:mainfrom
Conversation
Contributor
Author
|
@BH3GEI Please review it. |
lijingrs
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
Implements the Reflection agentic design pattern (Chapter 4 of Agentic Design Patterns) in MoFA. The pattern runs a generate → critique → refine loop where an agent produces a draft, critiques it, and iteratively improves it — addressing Open Task 8.
🔗 Related Issues
Closes #179
🧠 Context
The Reflection pattern was missing from MoFA's agentic pattern library. While
ThoughtStepType::ReflectionandThoughtStep::reflection()already existed inmofa-kernel, there was no implementation of the actual critique–refine loop. This PR fills that gap by implementing the full pattern inmofa-foundationand wiring it into the existing react module and SDK.🛠️ Changes
reflection.rsinmofa-foundation/src/react/— types, config, agent, builder, and run loopreact/mod.rs— registered module, exported types, added to preludeexamples/reflection_agent/— end-to-end example working with any LLM providerexamples/Cargo.toml— added reflection_agent to workspace members🧪 How you Tested
cargo test -p mofa-foundation reflection— 3 unit tests passcd examples/reflection_agent && cargo run— tested end-to-end with OpenAI GPT-4, ran 3 rounds of generate → critique → refine successfully📸 Screenshots / Logs (if applicable)
🧹 Checklist
Code Quality
cargo fmtruncargo clippypasses without warningsTesting
cargo testpasses locally without any errorDocumentation
PR Hygiene
🧩 Additional Notes for Reviewers
.with_critic(Arc<LLMAgent>)ThoughtStep::reflection()from kernel for trace consistency