-
Notifications
You must be signed in to change notification settings - Fork 359
-
OverviewI've implemented a new ReasoningBank feature for ADK-Java, based on the paper "Reasoning-Bank: Learning from the Traces of Thought" (arXiv:2509.25140). Pull Request: #702 What is ReasoningBank?ReasoningBank enables agents to store and retrieve proven reasoning strategies, allowing them to learn from past successful task executions and apply those approaches to new, similar problems. This is analogous to how the existing Memory feature works, but focused on reasoning patterns rather than factual information. Key ComponentsData Models (
|
| Class | Description |
|---|---|
ReasoningStrategy |
Immutable model representing a distilled reasoning approach with problem pattern, steps, and tags |
ReasoningTrace |
Captures raw task execution data (task, output, reasoning steps) for later distillation |
SearchReasoningResponse |
Response model for strategy search results |
Service Layer
| Class | Description |
|---|---|
BaseReasoningBankService |
Interface defining storeStrategy(), storeTrace(), and searchStrategies() operations |
InMemoryReasoningBankService |
In-memory implementation using keyword matching with weighted scoring |
Tool Integration (com.google.adk.tools)
| Class | Description |
|---|---|
LoadReasoningStrategyTool |
Function tool enabling agents to search and load relevant strategies |
LoadReasoningStrategyResponse |
Tool response record |
Design Philosophy
The implementation follows ADK's established patterns:
- Mirrors Memory Feature: The architecture closely follows
BaseMemoryService/InMemoryMemoryService/LoadMemoryToolpattern - Immutable Data Models: Uses
@AutoValuefor thread-safe, immutable data structures - Reactive Streams: Uses RxJava3 (
Single,Completable) for async operations - Context Integration: Integrated into
InvocationContextandToolContextfor seamless access
Usage Example
// Create and configure the reasoning bank service BaseReasoningBankService reasoningBank = new InMemoryReasoningBankService(); // Store a reasoning strategy ReasoningStrategy strategy = ReasoningStrategy.builder() .id("math-problem-solving") .name("Mathematical Problem Solving") .problemPattern("Word problems involving rates, distances, or quantities") .steps(ImmutableList.of( "Identify known quantities and unknowns", "Translate word problem into mathematical equations", "Solve the equations systematically", "Verify the answer makes sense in context")) .tags(ImmutableList.of("math", "word-problems", "algebra")) .build(); reasoningBank.storeStrategy("myApp", strategy).blockingAwait(); // Configure agent with reasoning bank InvocationContext context = InvocationContext.builder() .reasoningBankService(reasoningBank) .sessionService(sessionService) .artifactService(artifactService) // ... other configuration .build(); // Agent can now use LoadReasoningStrategyTool to retrieve relevant strategies
Testing
The implementation includes 20 unit tests covering:
ReasoningStrategybuilder and immutability (5 tests)ReasoningTracebuilder and immutability (5 tests)InMemoryReasoningBankServicestore/search/ranking (10 tests)
All 793 existing tests continue to pass.
Future Enhancements
Potential areas for future development:
- Semantic Search: Replace keyword matching with embedding-based semantic similarity
- Strategy Distillation: Add
SimpleReasoningDistillerto automatically convert traces into strategies - Persistence: Add database-backed implementations for production use
- Strategy Versioning: Support for evolving strategies over time
Related Work
- Paper: Reasoning-Bank: Learning from the Traces of Thought
- Similar implementation in LangChain4j: langchain4j/langchain4j#4364
I'd love to hear feedback on this feature! Are there specific use cases or enhancements you'd like to see?
Beta Was this translation helpful? Give feedback.