Skip to content

[BUG] memory tool is NOT returning complete data from Knowledgebase #140

Description

@kanump

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

v0.3.0

Tools Package Version

v0.1.9

Tools used

  1. memory tool

Python Version

3.13

Operating System

macOS 15.5

Installation Method

pip

Steps to Reproduce

  1. install strands-tools
  2. Call the memory agent to retrieve data from a knowledgebase
  3. check the knowledgebase response traces from memory tool - [it is incomplete documents and text]

Expected Behavior

memory tool response after retrieving data from knowledgebase should be complete, currently there is only partial data.
This is happening due to the bug in format_retrieve_response method.

content from KB -> [{'text': 'Retrieved 9 results with score >= 0.4:\n\nScore: 0.6792\nDocument ID: unknown**_content_text: This is arguably a trickier situation than the discrete case, since if we place a non-zero amount of mass on each of the values, the total mass will add up to infinity, which violates the requirement that the total probaiblity must sum up to one. To define a continuous distribution, we will make use of probability density function (PDF). A probability density function, f , is a non-negative, integrable function such that ∫ V al(X) f(x)dx = 1 The probability of a random variable X distributed according to a PDF f is computed as follows P (a ≤ X ≤ b) = ∫ b a f(x)dx Note that this, in particular, implies that the probability of a continuously distributed random variable taking on any given single value is zero. Example 8 (Uniform distribution). Let’s consider a random variable X that is uniformly distributed in the range [0, 1]. The corresponding PDF would be f(x) = { 1 if 0 ≤ x ≤ 1 0 otherwise We can verify that ∫ 1 0 1 dx is indeed 1, and therefore f is a PDF.\n\nScore: 0.6468\nDocument ID: unknowncontent_text: The corresponding PDF would be f(x) = { 1 if 0 ≤ x ≤ 1 0 otherwise We can verify that ∫ 1 0 1 dx is indeed 1, and therefore f is a PDF. To compute the probability of X smaller than a half, P (X ≤ 1/2) = ∫ 1/2 0 1 dx = [x] 1/2 0 = 1/2 More generally, suppose X is distributed uniformly over the range [a, b], then the PDF would be f(x) = { 1 b−a if a ≤ x ≤ b 0 otherwise 7Sometimes we will also speak about cumulative distribution function. It is a function that gives the probability of a random variable being smaller than some value. A cumulative distribution function F is related to the underlying probability density func_**tion f as follows: F (b) = P (X ≤ b) = ∫ b −∞ f(x)dx and hence F (x) = ∫ f(x)dx (in the sense of indefinite integral).\n\nScore: 0.5856\nDocument ID: unknowncontent_text: In order to specify a probability distribution over functions f(·) ∈ H, we must associate some “probability density” with each function in H. One natural way to do this is to exploit the one-to-one correspondence between functions f(·) ∈ H and their vector representations, ~f . In particular, if we specify that ~f ∼ N (~µ, σ2I), then this in turn implies a probability distribution over functions f(·), whose probability density function is given by p(h) = m ∏ i=1 1√ 2πσ exp ( − 1 2σ2 (f(xi) − µi) 2 ) . 6For the complete derivation, see, for instance, [1]. Alternatively, read the Appendices, which gives a number of arguments based on the “completion-of-squares” trick, and derive this formula yourself! 7Let H be a class of functions mapping from X → Y. A random function f(·) from H is a function which is randomly drawn from H, according to some probability distribution over H. One potential source of confusion is that you may be tempted to think of random functions as functions whose outputs are in some way stochastic; this is not the case.\n\nScore: 0.5769\nDocument ID: unknowncontent_text: Through application of analysis, we can show that the PDF, f(y|x), underlying the distribution P (Y |X) is given by f(y|x) = f(x, y) f(x) For example, P (a ≤ Y ≤ b|X = c) = ∫ b a f(y|c)dy = ∫ b a f(c, y) f(c) dy 3 Expectations and Variance 3.1 Expectations One of the most common operations we perform on a random variable is to compute its expectation, also known as its mean, expected value, or first moment. The expectation of a random variable, denoted by E(X), is given by E(X) = ∑ a∈V al(X) aP (X = a) o

Actual Behavior

memory tool response after retrieving data from knowledgebase should be complete, currently there is only partial data.
This is happening due to the bug in format_retrieve_response method. check the response from the memory tool getting truncated

content from KB -> [{'text': 'Retrieved 9 results with score >= 0.4:\n\nScore: 0.6724\nDocument ID: unknown\nContent Preview: This is arguably a trickier situation than the discrete case, since if we place a non-zero amount of mass on each of the values, the total mass will a...\n\nScore: 0.6490\nDocument ID: unknown\n**_Content Preview: The corresponding PDF would be     f(x) =     { 1 if 0 ≤ x ≤ 1     0 otherwise     We can verify that ∫ 1     0 1 dx is indeed 1, and therefore f is a...\_**n\nScore: 0.5811\nDocument ID: unknown\nContent Preview: In order to specify a probability distribution over functions f(·) ∈ H, we must associate some “probability density” with each function in H. One natu...\n\nScore: 0.5756\nDocument ID: unknown\nContent Preview: The topic of efficient representation of probability distribution is in fact a very important and active research area that deserves its own course. I...\n\nScore: 0.5736\nDocument ID: unknown\nContent Preview: Through application of analysis, we can show that the PDF, f(y|x), underlying the distribution P (Y |X) is given by     f(y|x) = f(x, y)     f(x)     ...\n\nScore: 0.5629\nDocument ID: unknown\nContent Preview: Normalization. The density function normalizes, i.e., ∫     x     p(x; µ, Σ)dx = 1.     This property, though seemingly trivial at first glance, turns...\n\nScore: 0.5319\nDocument ID: unknown\nContent Preview: To extend the definition of continuous distribution to joint distribution, the probability     density function is extended to take multiple arguments...\n\nScore: 0.5305\nDocument ID: unknown\nContent Preview: We’ll see the problem of defining a distribution from statistics (measurements). We’ll see that often there are often many probability distributions t...\n\nScore: 0.5298\nDocument ID: unknown\nContent Preview: One potential source of confusion is that you may be tempted to think of random functions as functions whose outputs are in some way stochastic; this ...'}]
result -> {'status': 'success', 'content': [{'text': 'Retrieved 9 results with score >= 0.4:\n\nScore: 0.6724\nDocument ID: unknown\nContent Preview: This is arguably a trickier situation than the discrete case, since if we place a non-zero amount of mass on each of the values, the total mass will a...\n\nScore: 0.6490\nDocument ID: unknown\nContent Preview: The corresponding PDF would be     f(x) =     { 1 if 0 ≤ x ≤ 1     0 otherwise     We can verify that ∫ 1     0 1 dx is indeed 1, and therefore f is a...\n\nScore: 0.5811\nDocument ID: unknown\nContent Preview: In order to specify a probability distribution over functions f(·) ∈ H, we must associate some “probability density” with each function in H. One natu...\n\nScore: 0.5756\nDocument ID: unknown\nContent Preview: The topic of efficient representation of probability distribution is in fact a very important and active research area that deserves its own course. I...\n\nScore: 0.5736\nDocument ID: unknown\nContent Preview: Through application of analysis, we can show that the PDF, f(y|x), underlying the distribution P (Y |X) is given by     f(y|x) = f(x, y)     f(x)     ...\n\nScore: 0.5629\nDocument ID: unknown\nContent Preview: Normalization. The density function normalizes, i.e., ∫     x     p(x; µ, Σ)dx = 1.     This property, though seemingly trivial at first glance, turns...\n\nScore: 0.5319\nDocument ID: unknown\nContent Preview: To extend the definition of continuous distribution to joint distribution, the probability     density function is extended to take multiple arguments...\n\nScore: 0.5305\nDocument ID: unknown\nContent Preview: We’ll see the problem of defining a distribution from statistics (measurements). We’ll see that often there are often many probability distributions t...\n\nScore: 0.5298\nDocument ID: unknown\nContent Preview: One potential source of confusion is that you may be tempted to think of random functions as functions whose outputs are in some way stochastic; this ...'}], 'toolUseId': 'tooluse_memory_294812835'}

Additional Context

No response

Possible Solution

happening due to issue with format_retrieve_response method, line 509 through and 512 needs to be commented and
result_text += f"content_text: {text}" needs to be added at line 498

https://github.com/strands-agents/tools/blame/e5223bce67611cb7f83743fde26adaacfcad09c7/src/strands_tools/memory.py#L509

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Language

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions