Skip to content

Conversation

@lemorage
Copy link
Contributor

Please describe the purpose of this pull request.
The agent's conversation_search tool, can search relevant content in the past conversations, by the given query_text. However, this can only work in PostgreSQL, since the ILIKE and json_array_elements are PostgreSQL-specific syntaxes.

if query_text:
content_element = func.json_array_elements(MessageModel.content).alias("content_element")
query = query.filter(
exists(
select(1)
.select_from(content_element)
.where(text("content_element->>'type' = 'text' AND content_element->>'text' ILIKE :query_text"))
.params(query_text=f"%{query_text}%")
)
)

This PR adds the SQLite3-compatible syntax, to fix #2553.

NOTE: This PR uses dialect branching to resolve the problem; there might be a more elegant and unified way to handle this, but I did not think of any. Welcome to suggestions!

How to test
poetry run pytest -s tests/test_managers.py -k test_list_messages_with_query_text

Have you tested this PR?
I added a unit test to reproduce this error. If you ran letta server locally, the test would fail without this fix. Also, the reproduction steps mentioned in #2553 can be used for testing.

@lemorage lemorage force-pushed the fix-conversation-search branch from 812e7ec to 569baed Compare April 13, 2025 03:33
Copy link
Contributor

@mattzh72 mattzh72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@mattzh72 mattzh72 merged commit 79f4a7e into letta-ai:main Apr 21, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from To triage to Done in 🐛 Letta issue tracker Apr 21, 2025
sarahwooders pushed a commit that referenced this pull request Jun 3, 2025
carenthomas pushed a commit that referenced this pull request Sep 15, 2025
carenthomas pushed a commit that referenced this pull request Oct 7, 2025
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

Successfully merging this pull request may close these issues.

Letta ADE crashed when agent usedconversation_search

2 participants