langroid 0.33.9__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.9 → langroid-0.33.10}/PKG-INFO +1 -1
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/chat_agent.py +46 -12
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/sql_chat_agent.py +36 -19
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tool_message.py +1 -1
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/orchestration.py +1 -1
- {langroid-0.33.9 → langroid-0.33.10}/pyproject.toml +1 -1
- {langroid-0.33.9 → langroid-0.33.10}/.gitignore +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/LICENSE +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/README.md +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/batch.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/callbacks/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/callbacks/chainlit.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/chat_document.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/arangodb/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/arangodb/system_messages.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/arangodb/tools.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/arangodb/utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/doc_chat_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/lance_tools.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/neo4j/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/neo4j/system_messages.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/neo4j/tools.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/task.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/file_tools.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/metaphor_search_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/retrieval_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/rewind_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/agent/xml_tool_message.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/cachedb/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/models.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/protoc/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings.proto +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/embedding_models/remote_embeds.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/exceptions.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/config.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/mock_lm.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/language_models/utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/mytypes.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/parse_json.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/parser.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/routing.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/search.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/spider.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/urls.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/parsing/web_search.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/prompts/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/prompts/dialog.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/prompts/templates.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/py.typed +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/pydantic_v1/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/pydantic_v1/main.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/configuration.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/constants.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/git_utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/globals.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/logging.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/object_registry.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/output/citations.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/output/printing.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/output/status.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/system.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/utils/types.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/base.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/momento.py +0 -0
- {langroid-0.33.9 → langroid-0.33.10}/langroid/vector_store/qdrantdb.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__)
|
@@ -111,6 +114,8 @@ class SQLChatAgentConfig(ChatAgentConfig):
|
|
111
114
|
# as opposed to returning a result from the task.run()
|
112
115
|
chat_mode: bool = False
|
113
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
|
114
119
|
|
115
120
|
"""
|
116
121
|
Optional, but strongly recommended, context descriptions for tables, columns,
|
@@ -182,6 +187,7 @@ class SQLChatAgent(ChatAgent):
|
|
182
187
|
self.helper_config = self.config.copy()
|
183
188
|
self.helper_config.is_helper = True
|
184
189
|
self.helper_config.use_helper = False
|
190
|
+
self.helper_config.chat_mode = False
|
185
191
|
self.helper_agent = SQLHelperAgent(self.helper_config)
|
186
192
|
|
187
193
|
def _validate_config(self, config: "SQLChatAgentConfig") -> None:
|
@@ -265,11 +271,13 @@ class SQLChatAgent(ChatAgent):
|
|
265
271
|
|
266
272
|
def _init_tools(self) -> None:
|
267
273
|
"""Initialize sys msg and tools."""
|
274
|
+
RunQueryTool._max_retained_tokens = self.config.max_retained_tokens
|
268
275
|
self.enable_message([RunQueryTool, ForwardTool])
|
269
276
|
if self.config.use_schema_tools:
|
270
277
|
self._enable_schema_tools()
|
271
278
|
if not self.config.chat_mode:
|
272
279
|
self.enable_message(DoneTool)
|
280
|
+
self.enable_message(DonePassTool)
|
273
281
|
|
274
282
|
def _format_message(self) -> str:
|
275
283
|
if self.engine is None:
|
@@ -312,14 +320,11 @@ class SQLChatAgent(ChatAgent):
|
|
312
320
|
"""
|
313
321
|
if self.config.chat_mode:
|
314
322
|
return f"""
|
315
|
-
you must use the `{ForwardTool.name()}` with the `agent`
|
323
|
+
you must use the TOOL `{ForwardTool.name()}` with the `agent`
|
316
324
|
parameter set to "User"
|
317
325
|
"""
|
318
326
|
else:
|
319
|
-
return f""
|
320
|
-
you must use the `{DoneTool.name()}` with the `content`
|
321
|
-
set to the answer or result
|
322
|
-
"""
|
327
|
+
return f"you must use the TOOL `{DonePassTool.name()}`"
|
323
328
|
|
324
329
|
def _clarifying_message(self) -> str:
|
325
330
|
tools_instruction = f"""
|
@@ -344,23 +349,24 @@ class SQLChatAgent(ChatAgent):
|
|
344
349
|
self, message: str | ChatDocument
|
345
350
|
) -> str | ForwardTool | ChatDocument | None:
|
346
351
|
"""
|
347
|
-
|
348
|
-
|
349
|
-
|
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.
|
350
355
|
"""
|
351
|
-
if
|
356
|
+
if (
|
357
|
+
not isinstance(message, ChatDocument)
|
358
|
+
or message.metadata.sender != Entity.LLM
|
359
|
+
):
|
352
360
|
return None
|
353
|
-
if self.
|
354
|
-
#
|
355
|
-
# when chat_mode=True, so in this case
|
356
|
-
# we send any Non-tool msg to the user
|
361
|
+
if self.config.chat_mode:
|
362
|
+
# send any Non-tool msg to the user
|
357
363
|
return ForwardTool(agent="User")
|
358
364
|
# Agent intent not clear => use the helper agent to
|
359
365
|
# do what this agent should have done, e.g. generate tool, etc.
|
360
366
|
# This is likelier to succeed since this agent has no "baggage" of
|
361
367
|
# prior conversation, other than the system msg, and special
|
362
368
|
# "Intent-interpretation" instructions.
|
363
|
-
if self._json_schema_available():
|
369
|
+
if self._json_schema_available() and self.config.strict_recovery:
|
364
370
|
AnyTool = self._get_any_tool_message(optional=False)
|
365
371
|
self.set_output_format(
|
366
372
|
AnyTool,
|
@@ -372,15 +378,18 @@ class SQLChatAgent(ChatAgent):
|
|
372
378
|
recovery_message = self._strict_recovery_instructions(
|
373
379
|
AnyTool, optional=False
|
374
380
|
)
|
375
|
-
|
376
|
-
|
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:
|
377
387
|
response = self.helper_agent.llm_response(message)
|
378
388
|
tools = self.try_get_tool_messages(response)
|
379
389
|
if tools:
|
380
390
|
return response
|
381
|
-
|
382
|
-
|
383
|
-
return self._clarifying_message()
|
391
|
+
# fall back on the clarification message
|
392
|
+
return self._clarifying_message()
|
384
393
|
|
385
394
|
def retry_query(self, e: Exception, query: str) -> str:
|
386
395
|
"""
|
@@ -467,6 +476,14 @@ class SQLChatAgent(ChatAgent):
|
|
467
476
|
try:
|
468
477
|
# attempt to fetch results: should work for normal SELECT queries
|
469
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
|
+
|
470
487
|
response_message = self._format_rows(rows)
|
471
488
|
except ResourceClosedError:
|
472
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
|
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.9 → 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.9 → 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.9 → 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.9 → langroid-0.33.10}/langroid/language_models/prompt_formatter/hf_formatter.py
RENAMED
File without changes
|
{langroid-0.33.9 → 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
|
File without changes
|