Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agents with memory dont work in playground #1449

Closed
nikhil-pandey opened this issue Nov 15, 2024 · 5 comments · Fixed by #1583
Closed

Agents with memory dont work in playground #1449

nikhil-pandey opened this issue Nov 15, 2024 · 5 comments · Fixed by #1583
Labels

Comments

@nikhil-pandey
Copy link
Contributor

Repro Steps

memory_db = SqliteMemoryDb(table_name="memories", db_file="tmp/agents.db")
agent = Agent(
    name="my_agent",
    agent_id="my_agent",
    model=models["gpt-4o"],
    debug_mode=True,
    memory=AgentMemory(
        db=memory_db,
        create_user_memories=True,
        create_session_summary=True,
        classifier=MemoryClassifier(
            model=models["gpt-4o-mini"],
        ),
        summarizer=MemorySummarizer(
            model=models["gpt-4o-mini"],
        ),
        manager=MemoryManager(
            model=models["gpt-4o-mini"],
        ),
    ),
    storage=agent_storage,
)

# This works
agent.print_response(
    "Who am i?",
    stream=True,
)

With playground, fails to deepcopy in the router.py

File "phi/playground/router.py", line 269, in agent_run
    new_agent_instance = agent.deep_copy(update={"session_id": body.session_id})
  File "phi/agent/agent.py", line 277, in deep_copy
    fields_for_new_agent[field_name] = self._deep_copy_field(field_name, field_value)
  File "phi/agent/agent.py", line 294, in _deep_copy_field
    return field_value.deep_copy()
  File "phi/memory/agent.py", line 361, in deep_copy
    new_memory = self.model_copy(deep=True, update=update)
  File ".venv/lib/python3.9/site-packages/pydantic/main.py", line 337, in model_copy
    copied = self.__deepcopy__() if deep else self.__copy__()
  File ".venv/lib/python3.9/site-packages/pydantic/main.py", line 805, in __deepcopy__
    _object_setattr(m, '__dict__', deepcopy(self.__dict__, memo=memo))
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/copy.py", line 161, in deepcopy
    rv = reductor(4)
@manthanguptaa
Copy link
Contributor

Hey @nikhil-pandey, did you push a fix for this in your PR? or are you still countering this issue?

@fireharp
Copy link

@manthanguptaa I have same issue

  File "/Users/fireharp/.pyenv/versions/3.11.9/lib/python3.11/copy.py", line 161, in deepcopy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle 'module' object
Exception ignored in: <function SqliteMemoryDb.__del__ at 0x1086cca40>
Traceback (most recent call last):
  File "/Users/fireharp/Prog/Playgrounds/phidata/.venv/lib/python3.11/site-packages/phi/memory/db/sqlite.py", line 192, in __del__
    self.Session.remove()
    ^^^^^^^^^^^^
AttributeError: 'SqliteMemoryDb' object has no attribute 'Session'
INFO:     127.0.0.1:59086 - "GET /v1/playground/status HTTP/1.1" 200 OK

@manthanguptaa
Copy link
Contributor

@fireharp allow me some time. I will take a look at it

Copy link

This issue has been automatically marked as stale due to 14 days of inactivity and will now be closed.

@github-actions github-actions bot added the stale label Dec 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@manthanguptaa manthanguptaa reopened this Dec 16, 2024
@manthanguptaa
Copy link
Contributor

Hey @nikhil-pandey @fireharp, sorry for the delayed resolution on this but now I have raised a PR for it! Thank you so much for raising this issue

dirkbrnd pushed a commit that referenced this issue Dec 17, 2024
## Description
When running an agent with agent memory on the playground it failed deep
copying un-pickle-able field.

Fixes #1449
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants