langroid 0.6.0__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langroid/agent/special/neo4j/neo4j_chat_agent.py +17 -39
- langroid/agent/special/neo4j/utils/system_message.py +10 -0
- {langroid-0.6.0.dist-info → langroid-0.6.1.dist-info}/METADATA +1 -1
- {langroid-0.6.0.dist-info → langroid-0.6.1.dist-info}/RECORD +7 -7
- pyproject.toml +1 -1
- {langroid-0.6.0.dist-info → langroid-0.6.1.dist-info}/LICENSE +0 -0
- {langroid-0.6.0.dist-info → langroid-0.6.1.dist-info}/WHEEL +0 -0
@@ -11,10 +11,10 @@ from langroid.pydantic_v1 import BaseModel, BaseSettings
|
|
11
11
|
if TYPE_CHECKING:
|
12
12
|
import neo4j
|
13
13
|
|
14
|
-
|
15
14
|
from langroid.agent.chat_agent import ChatAgent, ChatAgentConfig
|
16
|
-
from langroid.agent.chat_document import
|
15
|
+
from langroid.agent.chat_document import ChatDocument
|
17
16
|
from langroid.agent.special.neo4j.utils.system_message import (
|
17
|
+
ADDRESSING_INSTRUCTION,
|
18
18
|
DEFAULT_NEO4J_CHAT_SYSTEM_MESSAGE,
|
19
19
|
DEFAULT_SYS_MSG,
|
20
20
|
SCHEMA_TOOLS_SYS_MSG,
|
@@ -76,6 +76,7 @@ class Neo4jChatAgentConfig(ChatAgentConfig):
|
|
76
76
|
use_schema_tools: bool = True
|
77
77
|
use_functions_api: bool = True
|
78
78
|
use_tools: bool = False
|
79
|
+
addressing_prefix: str = ""
|
79
80
|
|
80
81
|
|
81
82
|
class Neo4jChatAgent(ChatAgent):
|
@@ -85,12 +86,21 @@ class Neo4jChatAgent(ChatAgent):
|
|
85
86
|
Raises:
|
86
87
|
ValueError: If database information is not provided in the config.
|
87
88
|
"""
|
88
|
-
self.config = config
|
89
|
+
self.config: Neo4jChatAgentConfig = config
|
89
90
|
self._validate_config()
|
90
91
|
self._import_neo4j()
|
91
92
|
self._initialize_connection()
|
92
93
|
self._init_tool_messages()
|
93
94
|
|
95
|
+
def handle_message_fallback(
|
96
|
+
self, msg: str | ChatDocument
|
97
|
+
) -> str | ChatDocument | None:
|
98
|
+
"""When LLM sends a no-tool msg, assume user is the intended recipient."""
|
99
|
+
if isinstance(msg, ChatDocument) and msg.metadata.sender == Entity.LLM:
|
100
|
+
msg.metadata.recipient = Entity.USER
|
101
|
+
return msg
|
102
|
+
return None
|
103
|
+
|
94
104
|
def _validate_config(self) -> None:
|
95
105
|
"""Validate the configuration to ensure all necessary fields are present."""
|
96
106
|
assert isinstance(self.config, Neo4jChatAgentConfig)
|
@@ -318,6 +328,10 @@ class Neo4jChatAgent(ChatAgent):
|
|
318
328
|
"""Initialize message tools used for chatting."""
|
319
329
|
message = self._format_message()
|
320
330
|
self.config.system_message = self.config.system_message.format(mode=message)
|
331
|
+
if self.config.addressing_prefix != "":
|
332
|
+
self.config.system_message += ADDRESSING_INSTRUCTION.format(
|
333
|
+
prefix=self.config.addressing_prefix
|
334
|
+
)
|
321
335
|
super().__init__(self.config)
|
322
336
|
self.enable_message(CypherRetrievalTool)
|
323
337
|
self.enable_message(CypherCreationTool)
|
@@ -332,39 +346,3 @@ class Neo4jChatAgent(ChatAgent):
|
|
332
346
|
if self.config.use_schema_tools
|
333
347
|
else DEFAULT_SYS_MSG.format(schema=self.get_schema(None))
|
334
348
|
)
|
335
|
-
|
336
|
-
def agent_response(
|
337
|
-
self,
|
338
|
-
msg: Optional[str | ChatDocument] = None,
|
339
|
-
) -> Optional[ChatDocument]:
|
340
|
-
if msg is None:
|
341
|
-
return None
|
342
|
-
|
343
|
-
results = self.handle_message(msg)
|
344
|
-
if results is None:
|
345
|
-
return None
|
346
|
-
|
347
|
-
output = results
|
348
|
-
if NEO4J_ERROR_MSG in output:
|
349
|
-
output = "There was an error in the Cypher Query. Press enter to retry."
|
350
|
-
|
351
|
-
console.print(f"[red]{self.indent}", end="")
|
352
|
-
print(f"[red]Agent: {output}")
|
353
|
-
sender_name = self.config.name
|
354
|
-
if isinstance(msg, ChatDocument) and msg.function_call is not None:
|
355
|
-
sender_name = msg.function_call.name
|
356
|
-
|
357
|
-
content = results.content if isinstance(results, ChatDocument) else results
|
358
|
-
recipient = (
|
359
|
-
results.metadata.recipient if isinstance(results, ChatDocument) else ""
|
360
|
-
)
|
361
|
-
|
362
|
-
return ChatDocument(
|
363
|
-
content=content,
|
364
|
-
metadata=ChatDocMetaData(
|
365
|
-
# source=Entity.AGENT,
|
366
|
-
sender=Entity.AGENT,
|
367
|
-
sender_name=sender_name,
|
368
|
-
recipient=recipient,
|
369
|
-
),
|
370
|
-
)
|
@@ -44,3 +44,13 @@ Also if you receive a null or other unexpected result,
|
|
44
44
|
Start by asking what I would like to know about the data.
|
45
45
|
|
46
46
|
"""
|
47
|
+
|
48
|
+
ADDRESSING_INSTRUCTION = """
|
49
|
+
IMPORTANT - Whenever you are NOT writing a CYPHER query, make sure you address the
|
50
|
+
user using {prefix}User. You MUST use the EXACT syntax {prefix} !!!
|
51
|
+
|
52
|
+
In other words, you ALWAYS write EITHER:
|
53
|
+
- a CYPHER query using one of the tools,
|
54
|
+
- OR address the user using {prefix}User.
|
55
|
+
|
56
|
+
"""
|
@@ -23,9 +23,9 @@ langroid/agent/special/lance_rag_new/query_planner_agent.py,sha256=JqO_5fKW8HPn-
|
|
23
23
|
langroid/agent/special/lance_tools.py,sha256=BznV_r3LAFyybvBRa9KQ0oU7mPM3uQVfri7PFp7M_qc,1894
|
24
24
|
langroid/agent/special/neo4j/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
25
|
langroid/agent/special/neo4j/csv_kg_chat.py,sha256=dRsAgMBa1H_EMI2YYgJR2Xyv1D7e4o3G9M64mTewq_c,6409
|
26
|
-
langroid/agent/special/neo4j/neo4j_chat_agent.py,sha256=
|
26
|
+
langroid/agent/special/neo4j/neo4j_chat_agent.py,sha256=B5y4he__9QjNrjNyngv4rlfVx7QezQ4Turom-l_zjCg,12572
|
27
27
|
langroid/agent/special/neo4j/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
|
-
langroid/agent/special/neo4j/utils/system_message.py,sha256=
|
28
|
+
langroid/agent/special/neo4j/utils/system_message.py,sha256=OvYuBSlnLhav4HAiwcYiJJSrpbGxqOqs4RAvnlwAvRI,2557
|
29
29
|
langroid/agent/special/relevance_extractor_agent.py,sha256=zIx8GUdVo1aGW6ASla0NPQjYYIpmriK_TYMijqAx3F8,4796
|
30
30
|
langroid/agent/special/retriever_agent.py,sha256=lvMvf-u9rSosg4YASuFdUbGLgkzLPknXAbJZfZ1LZCc,1868
|
31
31
|
langroid/agent/special/sql/__init__.py,sha256=mWfmm1QpXCezpFOS2eI57M0L_Ok3q5_ukG8tXBnBrEA,319
|
@@ -134,8 +134,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
|
|
134
134
|
langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
|
135
135
|
langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
|
136
136
|
langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
|
137
|
-
pyproject.toml,sha256=
|
138
|
-
langroid-0.6.
|
139
|
-
langroid-0.6.
|
140
|
-
langroid-0.6.
|
141
|
-
langroid-0.6.
|
137
|
+
pyproject.toml,sha256=b3vqi_BvwKi-CRtturkQMIR9BjcuLOxbmAAFEMhz9DI,7063
|
138
|
+
langroid-0.6.1.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
139
|
+
langroid-0.6.1.dist-info/METADATA,sha256=o5zXQBol5AfCAVK6sd1vNMwG3Qhrsie8QDo7-1C4yXY,54402
|
140
|
+
langroid-0.6.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
141
|
+
langroid-0.6.1.dist-info/RECORD,,
|
pyproject.toml
CHANGED
File without changes
|
File without changes
|