langroid 0.33.8__tar.gz → 0.33.10__tar.gz
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-0.33.8 → langroid-0.33.10}/PKG-INFO +1 -1
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/chat_agent.py +46 -12
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/sql_chat_agent.py +38 -20
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tool_message.py +1 -1
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/orchestration.py +1 -1
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/qdrantdb.py +21 -0
- {langroid-0.33.8 → langroid-0.33.10}/pyproject.toml +1 -1
- {langroid-0.33.8 → langroid-0.33.10}/.gitignore +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/LICENSE +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/README.md +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/batch.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/callbacks/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/callbacks/chainlit.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/chat_document.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/arangodb/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/arangodb/system_messages.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/arangodb/tools.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/arangodb/utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/doc_chat_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_tools.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/neo4j/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/neo4j/system_messages.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/neo4j/tools.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/task.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/file_tools.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/metaphor_search_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/retrieval_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/rewind_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/agent/xml_tool_message.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/cachedb/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/models.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings.proto +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/remote_embeds.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/exceptions.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/config.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/mock_lm.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/mytypes.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/parse_json.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/parser.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/routing.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/search.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/spider.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/urls.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/parsing/web_search.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/prompts/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/prompts/dialog.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/prompts/templates.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/py.typed +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/pydantic_v1/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/pydantic_v1/main.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/configuration.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/constants.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/git_utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/globals.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/logging.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/object_registry.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/output/citations.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/output/printing.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/output/status.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/system.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/utils/types.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/base.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.33.8 → langroid-0.33.10}/langroid/vector_store/momento.py +0 -0
@@ -539,6 +539,20 @@ class ChatAgent(Agent):
|
|
539
539
|
self.message_history[i].content = message
|
540
540
|
break
|
541
541
|
|
542
|
+
def delete_last_message(self, role: str = Role.USER) -> None:
|
543
|
+
"""
|
544
|
+
Delete the last message that has role `role` from the message history.
|
545
|
+
Args:
|
546
|
+
role (str): role of message to delete
|
547
|
+
"""
|
548
|
+
if len(self.message_history) == 0:
|
549
|
+
return
|
550
|
+
# find last message in self.message_history with role `role`
|
551
|
+
for i in range(len(self.message_history) - 1, -1, -1):
|
552
|
+
if self.message_history[i].role == role:
|
553
|
+
self.message_history.pop(i)
|
554
|
+
break
|
555
|
+
|
542
556
|
def _create_system_and_tools_message(self) -> LLMMessage:
|
543
557
|
"""
|
544
558
|
(Re-)Create the system message for the LLM of the agent,
|
@@ -1219,15 +1233,25 @@ class ChatAgent(Agent):
|
|
1219
1233
|
instructions=True,
|
1220
1234
|
)
|
1221
1235
|
recovery_message = self._strict_recovery_instructions(AnyTool)
|
1236
|
+
augmented_message = message
|
1237
|
+
if augmented_message is None:
|
1238
|
+
augmented_message = recovery_message
|
1239
|
+
elif isinstance(augmented_message, str):
|
1240
|
+
augmented_message = augmented_message + recovery_message
|
1241
|
+
else:
|
1242
|
+
augmented_message.content = augmented_message.content + recovery_message
|
1222
1243
|
|
1244
|
+
# only use the augmented message for this one response...
|
1245
|
+
result = self.llm_response(augmented_message)
|
1246
|
+
# ... restore the original user message so that the AnyTool recover
|
1247
|
+
# instructions don't persist in the message history
|
1248
|
+
# (this can cause the LLM to use the AnyTool directly as a tool)
|
1223
1249
|
if message is None:
|
1224
|
-
|
1225
|
-
elif isinstance(message, str):
|
1226
|
-
message = message + recovery_message
|
1250
|
+
self.delete_last_message(role=Role.USER)
|
1227
1251
|
else:
|
1228
|
-
|
1229
|
-
|
1230
|
-
return
|
1252
|
+
msg = message if isinstance(message, str) else message.content
|
1253
|
+
self.update_last_message(msg, role=Role.USER)
|
1254
|
+
return result
|
1231
1255
|
|
1232
1256
|
hist, output_len = self._prep_llm_messages(message)
|
1233
1257
|
if len(hist) == 0:
|
@@ -1294,15 +1318,25 @@ class ChatAgent(Agent):
|
|
1294
1318
|
instructions=True,
|
1295
1319
|
)
|
1296
1320
|
recovery_message = self._strict_recovery_instructions(AnyTool)
|
1321
|
+
augmented_message = message
|
1322
|
+
if augmented_message is None:
|
1323
|
+
augmented_message = recovery_message
|
1324
|
+
elif isinstance(augmented_message, str):
|
1325
|
+
augmented_message = augmented_message + recovery_message
|
1326
|
+
else:
|
1327
|
+
augmented_message.content = augmented_message.content + recovery_message
|
1297
1328
|
|
1329
|
+
# only use the augmented message for this one response...
|
1330
|
+
result = self.llm_response(augmented_message)
|
1331
|
+
# ... restore the original user message so that the AnyTool recover
|
1332
|
+
# instructions don't persist in the message history
|
1333
|
+
# (this can cause the LLM to use the AnyTool directly as a tool)
|
1298
1334
|
if message is None:
|
1299
|
-
|
1300
|
-
elif isinstance(message, str):
|
1301
|
-
message = message + recovery_message
|
1335
|
+
self.delete_last_message(role=Role.USER)
|
1302
1336
|
else:
|
1303
|
-
|
1304
|
-
|
1305
|
-
return
|
1337
|
+
msg = message if isinstance(message, str) else message.content
|
1338
|
+
self.update_last_message(msg, role=Role.USER)
|
1339
|
+
return result
|
1306
1340
|
|
1307
1341
|
hist, output_len = self._prep_llm_messages(message)
|
1308
1342
|
if len(hist) == 0:
|
@@ -13,6 +13,7 @@ from typing import Any, Dict, List, Optional, Sequence, Union
|
|
13
13
|
from rich.console import Console
|
14
14
|
|
15
15
|
from langroid.exceptions import LangroidImportError
|
16
|
+
from langroid.mytypes import Entity
|
16
17
|
from langroid.utils.constants import SEND_TO
|
17
18
|
|
18
19
|
try:
|
@@ -43,10 +44,12 @@ from langroid.agent.special.sql.utils.tools import (
|
|
43
44
|
RunQueryTool,
|
44
45
|
)
|
45
46
|
from langroid.agent.tools.orchestration import (
|
47
|
+
DonePassTool,
|
46
48
|
DoneTool,
|
47
49
|
ForwardTool,
|
48
50
|
PassTool,
|
49
51
|
)
|
52
|
+
from langroid.language_models.base import Role
|
50
53
|
from langroid.vector_store.base import VectorStoreConfig
|
51
54
|
|
52
55
|
logger = logging.getLogger(__name__)
|
@@ -72,7 +75,8 @@ Start by asking what I would like to know about the data.
|
|
72
75
|
|
73
76
|
ADDRESSING_INSTRUCTION = """
|
74
77
|
IMPORTANT - Whenever you are NOT writing a SQL query, make sure you address the user
|
75
|
-
using {prefix}User
|
78
|
+
using {prefix}User (NO SPACE between {prefix} and User).
|
79
|
+
You MUST use the EXACT syntax {prefix}User !!!
|
76
80
|
|
77
81
|
In other words, you ALWAYS write EITHER:
|
78
82
|
- a SQL query using the `run_query` tool,
|
@@ -110,6 +114,8 @@ class SQLChatAgentConfig(ChatAgentConfig):
|
|
110
114
|
# as opposed to returning a result from the task.run()
|
111
115
|
chat_mode: bool = False
|
112
116
|
addressing_prefix: str = ""
|
117
|
+
max_result_rows: int | None = None # limit query results to this
|
118
|
+
max_retained_tokens: int | None = None # limit history of query results to this
|
113
119
|
|
114
120
|
"""
|
115
121
|
Optional, but strongly recommended, context descriptions for tables, columns,
|
@@ -181,6 +187,7 @@ class SQLChatAgent(ChatAgent):
|
|
181
187
|
self.helper_config = self.config.copy()
|
182
188
|
self.helper_config.is_helper = True
|
183
189
|
self.helper_config.use_helper = False
|
190
|
+
self.helper_config.chat_mode = False
|
184
191
|
self.helper_agent = SQLHelperAgent(self.helper_config)
|
185
192
|
|
186
193
|
def _validate_config(self, config: "SQLChatAgentConfig") -> None:
|
@@ -264,11 +271,13 @@ class SQLChatAgent(ChatAgent):
|
|
264
271
|
|
265
272
|
def _init_tools(self) -> None:
|
266
273
|
"""Initialize sys msg and tools."""
|
274
|
+
RunQueryTool._max_retained_tokens = self.config.max_retained_tokens
|
267
275
|
self.enable_message([RunQueryTool, ForwardTool])
|
268
276
|
if self.config.use_schema_tools:
|
269
277
|
self._enable_schema_tools()
|
270
278
|
if not self.config.chat_mode:
|
271
279
|
self.enable_message(DoneTool)
|
280
|
+
self.enable_message(DonePassTool)
|
272
281
|
|
273
282
|
def _format_message(self) -> str:
|
274
283
|
if self.engine is None:
|
@@ -311,14 +320,11 @@ class SQLChatAgent(ChatAgent):
|
|
311
320
|
"""
|
312
321
|
if self.config.chat_mode:
|
313
322
|
return f"""
|
314
|
-
you must use the `{ForwardTool.name()}` with the `agent`
|
323
|
+
you must use the TOOL `{ForwardTool.name()}` with the `agent`
|
315
324
|
parameter set to "User"
|
316
325
|
"""
|
317
326
|
else:
|
318
|
-
return f""
|
319
|
-
you must use the `{DoneTool.name()}` with the `content`
|
320
|
-
set to the answer or result
|
321
|
-
"""
|
327
|
+
return f"you must use the TOOL `{DonePassTool.name()}`"
|
322
328
|
|
323
329
|
def _clarifying_message(self) -> str:
|
324
330
|
tools_instruction = f"""
|
@@ -343,23 +349,24 @@ class SQLChatAgent(ChatAgent):
|
|
343
349
|
self, message: str | ChatDocument
|
344
350
|
) -> str | ForwardTool | ChatDocument | None:
|
345
351
|
"""
|
346
|
-
|
347
|
-
|
348
|
-
|
352
|
+
We'd end up here if the current msg has no tool.
|
353
|
+
If this is from LLM, we may need to handle the scenario where
|
354
|
+
it may have "forgotten" to generate a tool.
|
349
355
|
"""
|
350
|
-
if
|
356
|
+
if (
|
357
|
+
not isinstance(message, ChatDocument)
|
358
|
+
or message.metadata.sender != Entity.LLM
|
359
|
+
):
|
351
360
|
return None
|
352
|
-
if self.
|
353
|
-
#
|
354
|
-
# when chat_mode=True, so in this case
|
355
|
-
# we send any Non-tool msg to the user
|
361
|
+
if self.config.chat_mode:
|
362
|
+
# send any Non-tool msg to the user
|
356
363
|
return ForwardTool(agent="User")
|
357
364
|
# Agent intent not clear => use the helper agent to
|
358
365
|
# do what this agent should have done, e.g. generate tool, etc.
|
359
366
|
# This is likelier to succeed since this agent has no "baggage" of
|
360
367
|
# prior conversation, other than the system msg, and special
|
361
368
|
# "Intent-interpretation" instructions.
|
362
|
-
if self._json_schema_available():
|
369
|
+
if self._json_schema_available() and self.config.strict_recovery:
|
363
370
|
AnyTool = self._get_any_tool_message(optional=False)
|
364
371
|
self.set_output_format(
|
365
372
|
AnyTool,
|
@@ -371,15 +378,18 @@ class SQLChatAgent(ChatAgent):
|
|
371
378
|
recovery_message = self._strict_recovery_instructions(
|
372
379
|
AnyTool, optional=False
|
373
380
|
)
|
374
|
-
|
375
|
-
|
381
|
+
result = self.llm_response(recovery_message)
|
382
|
+
# remove the recovery_message (it has User role) from the chat history,
|
383
|
+
# else it may cause the LLM to directly use the AnyTool.
|
384
|
+
self.delete_last_message(role=Role.USER) # delete last User-role msg
|
385
|
+
return result
|
386
|
+
elif self.config.use_helper:
|
376
387
|
response = self.helper_agent.llm_response(message)
|
377
388
|
tools = self.try_get_tool_messages(response)
|
378
389
|
if tools:
|
379
390
|
return response
|
380
|
-
|
381
|
-
|
382
|
-
return self._clarifying_message()
|
391
|
+
# fall back on the clarification message
|
392
|
+
return self._clarifying_message()
|
383
393
|
|
384
394
|
def retry_query(self, e: Exception, query: str) -> str:
|
385
395
|
"""
|
@@ -466,6 +476,14 @@ class SQLChatAgent(ChatAgent):
|
|
466
476
|
try:
|
467
477
|
# attempt to fetch results: should work for normal SELECT queries
|
468
478
|
rows = query_result.fetchall()
|
479
|
+
n_rows = len(rows)
|
480
|
+
if self.config.max_result_rows and n_rows > self.config.max_result_rows:
|
481
|
+
rows = rows[: self.config.max_result_rows]
|
482
|
+
logger.warning(
|
483
|
+
f"SQL query produced {n_rows} rows, "
|
484
|
+
f"limiting to {self.config.max_result_rows}"
|
485
|
+
)
|
486
|
+
|
469
487
|
response_message = self._format_rows(rows)
|
470
488
|
except ResourceClosedError:
|
471
489
|
# If we get here, it's a non-SELECT query (UPDATE, INSERT, DELETE)
|
@@ -101,7 +101,7 @@ class ToolMessage(ABC, BaseModel):
|
|
101
101
|
# Some tools can have large results that we may not want to fully retain,
|
102
102
|
# e.g. result of a db query, which the LLM later reduces to a summary, so
|
103
103
|
# in subsequent dialog we may only want to retain the summary,
|
104
|
-
# and replace this raw result truncated to
|
104
|
+
# and replace this raw result truncated to _max_retained_tokens.
|
105
105
|
# Important to note: unlike _max_result_tokens, this param is used
|
106
106
|
# NOT used to immediately truncate the result;
|
107
107
|
# it is only used to truncate what is retained in msg history AFTER the
|
@@ -156,7 +156,7 @@ class PassTool(ToolMessage):
|
|
156
156
|
def response(self, agent: ChatAgent, chat_doc: ChatDocument) -> ChatDocument:
|
157
157
|
"""When this tool is enabled for an Agent, this will result in a method
|
158
158
|
added to the Agent with signature:
|
159
|
-
`
|
159
|
+
`pass_tool(self, tool: PassTool, chat_doc: ChatDocument) -> ChatDocument:`
|
160
160
|
"""
|
161
161
|
# if PassTool is in chat_doc, pass its parent, else pass chat_doc itself
|
162
162
|
doc = chat_doc
|
@@ -2,6 +2,7 @@ import hashlib
|
|
2
2
|
import json
|
3
3
|
import logging
|
4
4
|
import os
|
5
|
+
import time
|
5
6
|
import uuid
|
6
7
|
from typing import Dict, List, Optional, Sequence, Tuple, TypeVar
|
7
8
|
|
@@ -323,6 +324,26 @@ class QdrantDB(VectorStore):
|
|
323
324
|
}
|
324
325
|
if self.config.use_sparse_embeddings:
|
325
326
|
vectors["text-sparse"] = sparse_embedding_vecs[i : i + b]
|
327
|
+
coll_found: bool = False
|
328
|
+
for _ in range(3):
|
329
|
+
# poll until collection is ready
|
330
|
+
if (
|
331
|
+
self.client.collection_exists(self.config.collection_name)
|
332
|
+
and self.client.get_collection(self.config.collection_name).status
|
333
|
+
== CollectionStatus.GREEN
|
334
|
+
):
|
335
|
+
coll_found = True
|
336
|
+
break
|
337
|
+
time.sleep(1)
|
338
|
+
|
339
|
+
if not coll_found:
|
340
|
+
raise ValueError(
|
341
|
+
f"""
|
342
|
+
QdrantDB Collection {self.config.collection_name}
|
343
|
+
not found or not ready
|
344
|
+
"""
|
345
|
+
)
|
346
|
+
|
326
347
|
self.client.upsert(
|
327
348
|
collection_name=self.config.collection_name,
|
328
349
|
points=Batch(
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/lance_rag/query_planner_agent.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.33.8 → langroid-0.33.10}/langroid/agent/special/sql/utils/description_extractors.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.33.8 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/hf_formatter.py
RENAMED
File without changes
|
{langroid-0.33.8 → langroid-0.33.10}/langroid/language_models/prompt_formatter/llama2_formatter.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|