Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Feature] ReasoningBank - Learning from Traces of Thought #703

nebrass started this conversation in Ideas
Discussion options

Overview

I'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 Components

Data Models (com.google.adk.reasoning)

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:

  1. Mirrors Memory Feature: The architecture closely follows BaseMemoryService / InMemoryMemoryService / LoadMemoryTool pattern
  2. Immutable Data Models: Uses @AutoValue for thread-safe, immutable data structures
  3. Reactive Streams: Uses RxJava3 (Single, Completable) for async operations
  4. Context Integration: Integrated into InvocationContext and ToolContext for 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:

  • ReasoningStrategy builder and immutability (5 tests)
  • ReasoningTrace builder and immutability (5 tests)
  • InMemoryReasoningBankService store/search/ranking (10 tests)

All 793 existing tests continue to pass.

Future Enhancements

Potential areas for future development:

  1. Semantic Search: Replace keyword matching with embedding-based semantic similarity
  2. Strategy Distillation: Add SimpleReasoningDistiller to automatically convert traces into strategies
  3. Persistence: Add database-backed implementations for production use
  4. Strategy Versioning: Support for evolving strategies over time

Related Work


I'd love to hear feedback on this feature! Are there specific use cases or enhancements you'd like to see?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /