sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] from strands_tools import use_llm,mem0_memory is not working

Open rajib76 opened this issue 1 year ago • 9 comments

Checks

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

Strands Version

0.1.0

Python Version

3.11

Operating System

windows

Installation Method

pip

Steps to Reproduce

from strands_tools import use_llm,mem0_memory - It says mem0_memory is not available

Expected Behavior

I should be able to import mem0_memory

Actual Behavior

not able to import

Additional Context

No response

Possible Solution

No response

Related Issues

No response

rajib76 avatar May 18 '25 23:05 rajib76

Even the KB based memory is not working. Says agent has no module "memory"

from strands import Agent
from strands_tools.memory import memory

agent = Agent(tools=[memory])

# Store content in Knowledge Base
agent.memory(
    action="store",
    content="Important information to remember",
    title="Meeting Notes",
    STRANDS_KNOWLEDGE_BASE_ID="my1234kb"
)

# Retrieve content using semantic search
agent.memory(
    action="retrieve",
    query="meeting information",
    min_score=0.7,
    STRANDS_KNOWLEDGE_BASE_ID="my1234kb"
)

# List all documents
agent.memory(
    action="list",
    max_results=50,
    STRANDS_KNOWLEDGE_BASE_ID="my1234kb"
)

rajib76 avatar May 19 '25 01:05 rajib76

Thank you for reporting this issue @rajib76.

We just released v0.1.1 of strands-agents-tools that includes the mem0_memory tool. Upgrade your version with:

pip install strands-agents-tools -U

You will then be able to use the mem0_memory tool in your Strands agents:

from strands import Agent
from strands_tools import mem0_memory

agent = Agent(tools=[mem0_memory])

For the second issue, your import path is incorrect. It should be:

from strands_tools import memory

arronbailiss avatar May 19 '25 01:05 arronbailiss

Changed to from strands_tools import memory

Still getting the error

/Users/joyeed/strands_examples/aws_strands_examples/venv/bin/python /Users/joyeed/strands_examples/aws_strands_examples/examples/07_memory_kb.py Warning: Input is not a terminal (fd=0). Traceback (most recent call last): File "/Users/joyeed/strands_examples/aws_strands_examples/examples/07_memory_kb.py", line 12, in memory_agent.memory( ^^^^^^^^^^^^^^^^^^^ AttributeError: 'Agent' object has no attribute 'memory'

rajib76 avatar May 19 '25 04:05 rajib76

@rajib76 please share the full updated code paste that reproduces the issue.

arronbailiss avatar May 19 '25 05:05 arronbailiss

from strands import Agent
from strands_tools import use_llm
from strands_tools import memory

agent = Agent(tools=[memory])

memory_agent = Agent(
    tools=[memory, use_llm],
)

# Store content in Knowledge Base
memory_agent.memory(
    action="store",
    content="Important information to remember",
    title="Meeting Notes",
    STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH"
)

# Retrieve content using semantic search
memory_agent.memory(
    action="retrieve",
    query="meeting information",
    min_score=0.7,
    STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH"
)

# List all documents
memory_agent.memory(
    action="list",
    max_results=50,
    STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH"
)

rajib76 avatar May 19 '25 05:05 rajib76

Got it - thank you!

Direct tool calls are made with agent.tool.<tool_name>(), for example memory_agent.tool.memory(). The .tool is missing in your sample.

https://strandsagents.com/0.1.x/user-guide/concepts/tools/tools_overview/#direct-method-calls

arronbailiss avatar May 19 '25 05:05 arronbailiss

This is the working version

`from strands import Agent from strands_tools import use_llm from strands_tools import memory

agent = Agent(tools=[memory])

memory_agent = Agent( tools=[memory, use_llm], )

memory_agent.tool.memory( action="store", content="Important information to remember", title="Meeting Notes", STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH" )

memory_agent.tool.memory( action="retrieve", query="meeting information", min_score=0.7, STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH" )

memory_agent.tool.memory( action="list", max_results=50, STRANDS_KNOWLEDGE_BASE_ID="BDRKXXIEYH" ) `

This is a design choice to namespace tool methods and avoid conflicts with other agent methods.

D1EE7P2U9 avatar May 19 '25 17:05 D1EE7P2U9

Awesome, pleased to hear that it's working 🚀

arronbailiss avatar May 20 '25 07:05 arronbailiss

I noticed our direct tool call inserts and docstrings indicates old agent.X pattern instead of agent.tool.X pattern.

That leads to direct tool calls announced as agent.tool_name ... which agents tend to use as context, which is clearly misleading to old version here ^^.

PR for fix: https://github.com/strands-agents/sdk-python/pull/56

cagataycali avatar May 20 '25 09:05 cagataycali