feat: Add ReasoningBank for reusable reasoning strategies#702
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @nebrass, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational ReasoningBank feature, designed to enhance agent capabilities by allowing them to learn from and reuse successful problem-solving approaches. By providing mechanisms to store and retrieve distilled reasoning strategies and raw execution traces, agents can apply proven methods to new, similar tasks, thereby improving their efficiency and effectiveness. The implementation includes core data models, a service interface with an in-memory prototype, and seamless integration into the existing tool and invocation contexts. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
e874b9e to
37a1f5c
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a ReasoningBank feature, which is a significant and well-implemented addition. The new components, including data models, services, and tool integrations, are clearly defined and follow the existing architectural patterns of the project. The code is well-documented and accompanied by a comprehensive set of unit tests, ensuring the new functionality is robust. I have a couple of minor suggestions for code refinement in the InMemoryReasoningBankService to improve conciseness and use more idiomatic Java constructs, but overall, this is excellent work.
37a1f5c to
c29b9c6
Compare
|
Do you think you could move the contribution in the |
|
Thanks @glaforge, that makes sense. I've moved the entire ReasoningBank contribution to
|
067c700 to
e49198b
Compare
087e713 to
373fe3d
Compare
|
Looks like the paper has been updated? |
8357b94 to
e80d9c0
Compare
|
Thanks @glaforge — good catch, and yes. Looking into it turned into a proper alignment plus building out the rest of the loop. On the paper: arXiv:2509.25140 now has a camera-ready v2 (16 Mar 2026) and was accepted to ICLR 2026, and the blog accompanies the public release of the official reference implementation (google-research/reasoning-bank) — which didn't exist when I first opened this PR. One correction to my own PR while I was at it: the title was always "ReasoningBank: Scaling Agent Self-Evolving with Reasoning Memory" (v1 and v2 match on that) — the "Learning from the Traces of Thought" title in my original description was simply wrong, and I've fixed the description. What it changed for the implementation — the official code + the blog's crystallized Title / Description / Content schema let me align the port and then realize the full closed loop:
Kept dependency-free (the LLM impls use core's This did grow the PR a fair bit — happy to split it (e.g. the schema alignment first, then the judge/extractor/plugin) if that's easier to review. |
|
@glaforge — quick follow-up: I added a proof of completeness for the closed loop (the 68 unit tests cover the components in isolation, but nothing drove the full cycle through a real
Honest scope: this proves the loop's wiring, persistence, and de-privileged placement, and that a real model yields a real failure verdict + usable guardrail — not a benchmark success-rate lift (out of scope here). Details are in the updated PR description. The PR has grown fairly large — happy to split it (schema alignment / judge+extractor / plugin / proof) if that's easier to review. |
|
Hi @nebrass, thanks for the comprehensive updates. To make the review process more manageable, could you please squash your changes into a single commit? |
9b7a1e7 to
c369270
Compare
|
Hello @hemasekhar-p squash is done now, the PR is now into a single commit. |
c369270 to
0d0c84d
Compare
Introduce reasoning memory services, LLM extraction and trajectory judging, plugin integration, retrieval tools, tests, and a sample.
0d0c84d to
b7a42eb
Compare
|
@nebrass, thank you for addressing the comments and squashing the changes. Currently this PR is under review by our team, we will keep you posted if any additional information is required. thank you. |
Summary
This PR implements ReasoningBank in ADK Java — a memory framework that lets agents distill
reusable reasoning strategies from their past task executions (both successful and failed)
and retrieve them to guide new, similar tasks.
The design mirrors ADK's existing Memory feature (
BaseMemoryService,InMemoryMemoryService,LoadMemoryTool).What is ReasoningBank?
Unlike memory mechanisms that store raw trajectories (Synapse) or only successful workflows (Agent
Workflow Memory), ReasoningBank distills compact, transferable memory items from both successes
and failures. Failure-derived items become preventative "guardrails" — e.g. "verify the page
identifier before loading more results to avoid infinite-scroll traps."
Components (
com.google.adk.reasoning)Data models
ReasoningMemoryItem— immutable memory item with the paper's canonicaltitle/description/contentschema, plussourceTraceSuccessfulso failure-derived preventative lessons are first-class (alsoid,tags,createdAt).ReasoningTrace— a raw task trajectory (task, output, intermediate reasoning steps,successfulflag) retained for later distillation.SearchReasoningResponse— search result wrapper.Service layer
BaseReasoningBankService— storage/retrieval contract:storeMemoryItem,storeTrace,searchMemoryItems.InMemoryReasoningBankService— prototype implementation using bag-of-words keyword scoring (title>description>tags>content). Not production-grade — the reference implementation uses embedding-based retrieval.Extraction SPI
MemoryExtractor(+NoOpMemoryExtractor) — extension point for the "judge & extract" step of the loop;extract(query, List<ReasoningTrace>)accommodates parallel/sequential MaTTS distillation later without an API break. LLM-backed extractors are intentionally left to downstream modules to keep this contrib module dependency-free.Tool integration (
com.google.adk.tools)LoadReasoningMemoryTool— aFunctionToolexposing retrieval to agents asloadReasoningMemory(query).LoadReasoningMemoryResponse— tool response record.The closed loop
searchMemoryItems→ retrieve · the agent runtime → act ·MemoryExtractor→ judge & extract ·storeMemoryItem→ consolidate (append).Integration
The module is self-contained and does not modify
InvocationContextorToolContext.Agents use it by constructing
LoadReasoningMemoryTool(reasoningBankService, appName)and adding itto their tool list (constructor injection). No core ADK changes are required.
Out of scope (documented in the module README)
SUCCESSFUL_SI,FAILED_SI,PARALLEL_SI, …).Usage
Test Plan
ReasoningMemoryItemTest(4)ReasoningTraceTest(5)InMemoryReasoningBankServiceTest(12) — includes retrieval of failure-derived itemsNoOpMemoryExtractorTest(2)Proof of completeness
The closed loop is validated end-to-end three ways — the component unit tests, a deterministic integration test, and a live real-model run.
Deterministic integration test —
ReasoningBankClosedLoopTest(runs in CI, no API key). Drives a realInMemoryRunner+LlmAgent+ReasoningBankPlugin(via scripted models) and asserts the full cycle:TrajectoryJudgereturns FAILURE →FAILED_SIextraction → guardrail stored → retrieved and injected into a later run as a de-privileged user turn (asserted present in the user channel and absent from the system instruction);Runnable sample —
contrib/samples/reasoningbank(mvn -pl contrib/samples/reasoningbank exec:java, needsGOOGLE_API_KEY). Runs one failure-leaning task and prints the judge verdict + rationale, the distilled guardrail(s), and a retrieval precheck. Validated live againstgemini-2.5-flash: the agent's ungroundable answer was judged FAILURE, and two generalizable preventative guardrails were distilled from the failure and retrieved — the paper's learn-from-failure behavior, end-to-end.Scope: this proves the loop's wiring, persistence, and de-privileged placement, and that a real model emits a real failure verdict + usable guardrail — not a benchmark success-rate lift.
Related
BaseMemoryService,InMemoryMemoryService,LoadMemoryTool).