Skip to content

Conversation

@iamrajiv
Copy link

@iamrajiv iamrajiv commented Dec 4, 2025

Fixes: #58

How It Works

                        BEFORE (No History)
+-------------------------------------------------------------------------+
|  User: "What did Adrian say about spiders?"                             |
|  Answer: "Adrian mentioned spiders have eight legs..."                  |
|                                                                         |
|  User: "What else did he say about it?"                                 |
|         |                                                               |
|         v                                                               |
|  LLM: "he"=? "it"=? ---> [X] Cannot resolve references                  |
+-------------------------------------------------------------------------+

                        AFTER (With History)
+-------------------------------------------------------------------------+
|                                                                         |
|  +---------------+    +------------------+    +-----------------------+ |
|  | User Query    |--->| History Context  |--->| LLM Query Translation | |
|  |               |    | (last 3-5 Q&A)   |    |                       | |
|  | "What else    |    |                  |    | Prompt includes:      | |
|  |  did he say   |    | Q1: What did     |    | - User query          | |
|  |  about it?"   |    |     Adrian say   |    | - Recent Q&A pairs    | |
|  |               |    |     about        |    |                       | |
|  +---------------+    |     spiders?     |    | LLM resolves:         | |
|                       | A1: Adrian       |    | "he" -> Adrian        | |
|                       |     mentioned    |    | "it" -> spiders       | |
|                       |     spiders...   |    |                       | |
|                       +------------------+    +-----------+-----------+ |
|                                                           |             |
|                                                           v             |
|                                               +-----------------------+ |
|                                               | Structured Search     | |
|                                               | Query (JSON)          | |
|                                               |                       | |
|                                               | entities: ["Adrian"]  | |
|                                               | topics: ["spiders"]   | |
|                                               +-----------------------+ |
|                                                           |             |
|                                                           v             |
|                                                    Correct Answer       |
+-------------------------------------------------------------------------+

Data Flow

+-------------+     +--------------------+     +---------------------+
|             |     |                    |     |                     |
| User Query  |---->| process_query()    |---->| search_conversation |
|             |     |                    |     | _with_language()    |
+-------------+     | 1. Get history     |     |                     |
                    |    prompt section  |     | model_instructions  |
                    | 2. Inject into     |     | contains history    |
                    |    lang_options    |     | context             |
                    +--------------------+     +----------+----------+
                                                          |
                    +--------------------+                v
                    |                    |     +---------------------+
                    | ConversationHistory|<----| search_query_from   |
                    |                    |     | _language()         |
                    | Stores Q&A after   |     |                     |
                    | answer generated   |     | LLM sees history    |
                    +--------------------+     | in prompt_preamble  |
                                               +---------------------+

@iamrajiv
Copy link
Author

iamrajiv commented Dec 4, 2025

hi @gvanrossum this is my pr related to #58 i have tested this locally and below are the results for make format check test could you please review the pr once?

➜  typeagent-py git:(history) ✗ make format check test
.venv/bin/black -tpy312 -tpy313 -tpy314 typeagent test tools gmail demo
All done! ✨ 🍰 ✨
112 files left unchanged.
.venv/bin/pyright --pythonpath .venv/bin/python typeagent test tools gmail
WARNING: there is a new pyright version available (v1.1.406 -> v1.1.407).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

0 errors, 0 warnings, 0 informations
.venv/bin/pytest
============================= test session starts ==============================
platform darwin -- Python 3.13.9, pytest-8.4.2, pluggy-1.6.0
rootdir: /Users/rajiv.singh/Desktop/projects/tt/typeagent-py
configfile: pyproject.toml
testpaths: test
plugins: mock-3.15.1, asyncio-1.2.0, anyio-4.11.0, logfire-4.14.2
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 358 items

test/test_add_messages_with_indexing.py ...                              [  0%]
test/test_auth.py .......                                                [  2%]
test/test_collections.py ...........................                     [ 10%]
test/test_conversation_metadata.py ....................                  [ 15%]
test/test_demo.py s                                                      [ 16%]
test/test_embedding_consistency.py ...                                   [ 17%]
test/test_embeddings.py ...........                                      [ 20%]
test/test_factory.py ..s                                                 [ 20%]
test/test_incremental_index.py ..                                        [ 21%]
test/test_interfaces.py ......................                           [ 27%]
test/test_knowledge.py s...                                              [ 28%]
test/test_kplib.py ......                                                [ 30%]
test/test_mcp_server.py s.                                               [ 31%]
test/test_message_text_index_population.py .                             [ 31%]
test/test_message_text_index_serialization.py ..                         [ 31%]
test/test_messageindex.py ....s...                                       [ 34%]
test/test_online.py s                                                    [ 34%]
test/test_podcast_incremental.py ..                                      [ 34%]
test/test_podcasts.py s                                                  [ 35%]
test/test_property_index_population.py s                                 [ 35%]
test/test_propindex.py ............                                      [ 38%]
test/test_query.py ..................................                    [ 48%]
test/test_query_method.py ss                                             [ 48%]
test/test_related_terms_fast.py .                                        [ 49%]
test/test_related_terms_index_population.py s                            [ 49%]
test/test_reltermsindex.py ........s....                                 [ 53%]
test/test_searchlib.py ................................................. [ 66%]
......                                                                   [ 68%]
test/test_secindex.py ...                                                [ 69%]
test/test_secindex_storage_integration.py .                              [ 69%]
test/test_semrefindex.py ......................                          [ 75%]
test/test_serialization.py ........                                      [ 77%]
test/test_sqlite_indexes.py .....................                        [ 83%]
test/test_sqlitestore.py .....                                           [ 85%]
test/test_storage_providers_unified.py ..............................    [ 93%]
test/test_timestampindex.py .                                            [ 93%]
test/test_transcripts.py ......s                                         [ 95%]
test/test_utils.py ..s.                                                  [ 96%]
test/test_vectorbase.py ...........                                      [100%]

======================= 344 passed, 14 skipped in 3.06s ========================

@gvanrossum
Copy link
Collaborator

Thank you @iamrajiv. I have restarted the tests -- they only run when started by someone with repo write access.

I'm traveling all of December, and I'm not sure when I can review this thoroughly.

@iamrajiv
Copy link
Author

iamrajiv commented Dec 6, 2025

no worries @gvanrossum thanks alot

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.

Add intelligent persistent history to tools/query.py

2 participants