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

jinja2.exceptions.UndefinedError: 'lumen.ai.memory._Memory object' has no attribute 'sql' #1032

Open
MarcSkovMadsen opened this issue Feb 2, 2025 · 5 comments

Comments

@MarcSkovMadsen
Copy link

lumen==0.8.0rc1

Reproduce

  • Upload single csv file
  • Ask "Please explain what I can find in the table of delivery forward prices"
  • Ask "Please make an informative plot of the data"

Watch the chat repeat the steps a few times and error.

Image

Traceback (most recent call last):

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/coordinator.py", line 380, in _execute_graph_node
    raise e

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/coordinator.py", line 369, in _execute_graph_node
    result = await subagent.respond(
             ^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/agents.py", line 266, in respond
    system_prompt = await self._render_prompt("main", messages, **context)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/actor.py", line 144, in _render_prompt
    prompt = render_template(
             ^^^^^^^^^^^^^^^^

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/utils.py", line 65, in render_template
    return template.render(**context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/prompts/AnalystAgent/main.jinja2", line 1, in top-level template code
    {% extends 'Actor/main.jinja2' %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/prompts/Actor/main.jinja2", line 4, in top-level template code
    {%- block context -%}

  File "/home/jovyan/repos/mt-ai-assistant/.venv/lib/python3.11/site-packages/lumen/ai/prompts/AnalystAgent/main.jinja2", line 13, in block 'context'
    {{ memory.sql }}

jinja2.exceptions.UndefinedError: 'lumen.ai.memory._Memory object' has no attribute 'sql'
@philippjfr
Copy link
Member

@ahuang11 could you look at this one?

@ahuang11
Copy link
Contributor

ahuang11 commented Feb 3, 2025

@MarcSkovMadsen can you share the CSV with me? I can't seem to reproduce

Data_Plotting_Plan.ipynb.txt

Image

@MarcSkovMadsen
Copy link
Author

MarcSkovMadsen commented Feb 4, 2025

I can no longer reproduce.

Even though I cannot reproduce is it not possible to look at the file ai/prompts/AnalystAgent/main.jinja2 and review whether the line {{ memory.sql }} makes sense?

@ahuang11
Copy link
Contributor

ahuang11 commented Feb 4, 2025

I added memory.sql to provide the AnalystAgent more context as to how the data was derived, and potentially point out what could've went wrong if the data returned is empty or looks wrong.

@philippjfr
Copy link
Member

I think there's a simple solution which is to guard all memory lookups in conditions:

{% if ''sql' in memory %}
Here is the current SQL query:
```sql
{{ memory.sql }}

{% endif %}


Note I haven't tested this.

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

No branches or pull requests

3 participants