langroid 0.22.2__tar.gz → 0.22.4__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.
Files changed (148) hide show
  1. {langroid-0.22.2 → langroid-0.22.4}/PKG-INFO +1 -1
  2. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/chat_agent.py +21 -9
  3. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/sql_chat_agent.py +62 -68
  4. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/retrieval_tool.py +4 -1
  5. {langroid-0.22.2 → langroid-0.22.4}/pyproject.toml +1 -1
  6. {langroid-0.22.2 → langroid-0.22.4}/LICENSE +0 -0
  7. {langroid-0.22.2 → langroid-0.22.4}/README.md +0 -0
  8. {langroid-0.22.2 → langroid-0.22.4}/langroid/__init__.py +0 -0
  9. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/__init__.py +0 -0
  10. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/base.py +0 -0
  11. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/batch.py +0 -0
  12. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/callbacks/__init__.py +0 -0
  13. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/callbacks/chainlit.py +0 -0
  14. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/chat_document.py +0 -0
  15. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/helpers.py +0 -0
  16. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/junk +0 -0
  17. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/openai_assistant.py +0 -0
  18. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/__init__.py +0 -0
  19. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/arangodb/__init__.py +0 -0
  20. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
  21. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/arangodb/system_messages.py +0 -0
  22. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/arangodb/tools.py +0 -0
  23. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/arangodb/utils.py +0 -0
  24. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/doc_chat_agent.py +0 -0
  25. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
  26. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_rag/__init__.py +0 -0
  27. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
  28. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
  29. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
  30. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/lance_tools.py +0 -0
  31. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/neo4j/__init__.py +0 -0
  32. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
  33. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
  34. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/neo4j/system_messages.py +0 -0
  35. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/neo4j/tools.py +0 -0
  36. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/relevance_extractor_agent.py +0 -0
  37. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/retriever_agent.py +0 -0
  38. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/__init__.py +0 -0
  39. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/utils/__init__.py +0 -0
  40. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
  41. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
  42. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/utils/system_message.py +0 -0
  43. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/sql/utils/tools.py +0 -0
  44. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/special/table_chat_agent.py +0 -0
  45. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/structured_message.py +0 -0
  46. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/task.py +0 -0
  47. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tool_message.py +0 -0
  48. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/__init__.py +0 -0
  49. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
  50. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/file_tools.py +0 -0
  51. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/google_search_tool.py +0 -0
  52. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/metaphor_search_tool.py +0 -0
  53. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/orchestration.py +0 -0
  54. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/recipient_tool.py +0 -0
  55. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/rewind_tool.py +0 -0
  56. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/tools/segment_extract_tool.py +0 -0
  57. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/typed_task.py +0 -0
  58. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent/xml_tool_message.py +0 -0
  59. {langroid-0.22.2 → langroid-0.22.4}/langroid/agent_config.py +0 -0
  60. {langroid-0.22.2 → langroid-0.22.4}/langroid/cachedb/__init__.py +0 -0
  61. {langroid-0.22.2 → langroid-0.22.4}/langroid/cachedb/base.py +0 -0
  62. {langroid-0.22.2 → langroid-0.22.4}/langroid/cachedb/momento_cachedb.py +0 -0
  63. {langroid-0.22.2 → langroid-0.22.4}/langroid/cachedb/redis_cachedb.py +0 -0
  64. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/__init__.py +0 -0
  65. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/base.py +0 -0
  66. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/clustering.py +0 -0
  67. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/models.py +0 -0
  68. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/protoc/__init__.py +0 -0
  69. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/protoc/embeddings.proto +0 -0
  70. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
  71. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
  72. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
  73. {langroid-0.22.2 → langroid-0.22.4}/langroid/embedding_models/remote_embeds.py +0 -0
  74. {langroid-0.22.2 → langroid-0.22.4}/langroid/exceptions.py +0 -0
  75. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/.chainlit/config.toml +0 -0
  76. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/.chainlit/translations/en-US.json +0 -0
  77. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/__init__.py +0 -0
  78. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/azure_openai.py +0 -0
  79. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/base.py +0 -0
  80. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/config.py +0 -0
  81. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/mock_lm.py +0 -0
  82. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/openai_gpt.py +0 -0
  83. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/prompt_formatter/__init__.py +0 -0
  84. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/prompt_formatter/base.py +0 -0
  85. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
  86. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
  87. {langroid-0.22.2 → langroid-0.22.4}/langroid/language_models/utils.py +0 -0
  88. {langroid-0.22.2 → langroid-0.22.4}/langroid/mytypes.py +0 -0
  89. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/__init__.py +0 -0
  90. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/agent_chats.py +0 -0
  91. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/code-parsing.md +0 -0
  92. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/code_parser.py +0 -0
  93. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/config.py +0 -0
  94. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/document_parser.py +0 -0
  95. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/image_text.py +0 -0
  96. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/para_sentence_split.py +0 -0
  97. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/parse_json.py +0 -0
  98. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/parser.py +0 -0
  99. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/repo_loader.py +0 -0
  100. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/routing.py +0 -0
  101. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/search.py +0 -0
  102. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/spider.py +0 -0
  103. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/table_loader.py +0 -0
  104. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/url_loader.py +0 -0
  105. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/url_loader_cookies.py +0 -0
  106. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/urls.py +0 -0
  107. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/utils.py +0 -0
  108. {langroid-0.22.2 → langroid-0.22.4}/langroid/parsing/web_search.py +0 -0
  109. {langroid-0.22.2 → langroid-0.22.4}/langroid/prompts/__init__.py +0 -0
  110. {langroid-0.22.2 → langroid-0.22.4}/langroid/prompts/chat-gpt4-system-prompt.md +0 -0
  111. {langroid-0.22.2 → langroid-0.22.4}/langroid/prompts/dialog.py +0 -0
  112. {langroid-0.22.2 → langroid-0.22.4}/langroid/prompts/prompts_config.py +0 -0
  113. {langroid-0.22.2 → langroid-0.22.4}/langroid/prompts/templates.py +0 -0
  114. {langroid-0.22.2 → langroid-0.22.4}/langroid/py.typed +0 -0
  115. {langroid-0.22.2 → langroid-0.22.4}/langroid/pydantic_v1/__init__.py +0 -0
  116. {langroid-0.22.2 → langroid-0.22.4}/langroid/pydantic_v1/main.py +0 -0
  117. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/.chainlit/config.toml +0 -0
  118. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/.chainlit/translations/en-US.json +0 -0
  119. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/__init__.py +0 -0
  120. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/algorithms/__init__.py +0 -0
  121. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/algorithms/graph.py +0 -0
  122. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/configuration.py +0 -0
  123. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/constants.py +0 -0
  124. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/docker.py +0 -0
  125. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/git_utils.py +0 -0
  126. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/globals.py +0 -0
  127. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/llms/__init__.py +0 -0
  128. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/llms/strings.py +0 -0
  129. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/logging.py +0 -0
  130. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/object_registry.py +0 -0
  131. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/output/__init__.py +0 -0
  132. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/output/citations.py +0 -0
  133. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/output/printing.py +0 -0
  134. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/output/status.py +0 -0
  135. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/pandas_utils.py +0 -0
  136. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/pydantic_utils.py +0 -0
  137. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/system.py +0 -0
  138. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/types.py +0 -0
  139. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/web/__init__.py +0 -0
  140. {langroid-0.22.2 → langroid-0.22.4}/langroid/utils/web/login.py +0 -0
  141. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/__init__.py +0 -0
  142. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/base.py +0 -0
  143. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/chromadb.py +0 -0
  144. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/lancedb.py +0 -0
  145. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/meilisearch.py +0 -0
  146. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/momento.py +0 -0
  147. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/qdrant_cloud.py +0 -0
  148. {langroid-0.22.2 → langroid-0.22.4}/langroid/vector_store/qdrantdb.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.22.2
3
+ Version: 0.22.4
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -623,10 +623,27 @@ class ChatAgent(Agent):
623
623
  self.llm_tools_usable.discard(r)
624
624
  self.llm_functions_usable.discard(r)
625
625
 
626
+ def truncate_message(
627
+ self,
628
+ idx: int,
629
+ tokens: int = 5,
630
+ warning: str = "...[Contents truncated!]",
631
+ ) -> LLMMessage:
632
+ """Truncate message at idx in msg history to `tokens` tokens"""
633
+ llm_msg = self.message_history[idx]
634
+ orig_content = llm_msg.content
635
+ new_content = (
636
+ self.parser.truncate_tokens(orig_content, tokens)
637
+ if self.parser is not None
638
+ else orig_content[: tokens * 4] # approx truncation
639
+ )
640
+ llm_msg.content = new_content + "\n" + warning
641
+ return llm_msg
642
+
626
643
  def _reduce_raw_tool_results(self, message: ChatDocument) -> None:
627
644
  """
628
- If message is the result of a ToolMessage that had the
629
- flag `_retain_raw_results = False`, then we replace contents
645
+ If message is the result of a ToolMessage that had
646
+ a `_max_retained_tokens` set to a non-None value, then we replace contents
630
647
  with a placeholder message.
631
648
  """
632
649
  parent_message: ChatDocument | None = message.parent
@@ -641,14 +658,9 @@ class ChatAgent(Agent):
641
658
  and has been truncated to {max_tokens} tokens.
642
659
  To obtain the full result, the tool needs to be re-used.
643
660
  """
644
- llm_msg = self.message_history[message.metadata.msg_idx]
645
- orig_content = llm_msg.content
646
- new_content = (
647
- self.parser.truncate_tokens(orig_content, max_tokens)
648
- if self.parser is not None
649
- else orig_content[: max_tokens * 4] # approx truncation
661
+ self.truncate_message(
662
+ message.metadata.msg_idx, max_tokens, truncation_warning
650
663
  )
651
- llm_msg.content = new_content + "\n\n" + truncation_warning
652
664
 
653
665
  def llm_response(
654
666
  self, message: Optional[str | ChatDocument] = None
@@ -10,11 +10,10 @@ Functionality includes:
10
10
  import logging
11
11
  from typing import Any, Dict, List, Optional, Sequence, Union
12
12
 
13
- from rich import print
14
13
  from rich.console import Console
15
14
 
16
15
  from langroid.exceptions import LangroidImportError
17
- from langroid.utils.constants import DONE, SEND_TO
16
+ from langroid.utils.constants import SEND_TO
18
17
 
19
18
  try:
20
19
  from sqlalchemy import MetaData, Row, create_engine, inspect, text
@@ -25,7 +24,7 @@ except ImportError as e:
25
24
  raise LangroidImportError(extra="sql", error=str(e))
26
25
 
27
26
  from langroid.agent.chat_agent import ChatAgent, ChatAgentConfig
28
- from langroid.agent.chat_document import ChatDocMetaData, ChatDocument
27
+ from langroid.agent.chat_document import ChatDocument
29
28
  from langroid.agent.special.sql.utils.description_extractors import (
30
29
  extract_schema_descriptions,
31
30
  )
@@ -43,15 +42,15 @@ from langroid.agent.special.sql.utils.tools import (
43
42
  GetTableSchemaTool,
44
43
  RunQueryTool,
45
44
  )
46
- from langroid.mytypes import Entity
45
+ from langroid.agent.tools.orchestration import DoneTool, ForwardTool
47
46
  from langroid.vector_store.base import VectorStoreConfig
48
47
 
49
48
  logger = logging.getLogger(__name__)
50
49
 
51
50
  console = Console()
52
51
 
53
- DEFAULT_SQL_CHAT_SYSTEM_MESSAGE = f"""
54
- {{mode}}
52
+ DEFAULT_SQL_CHAT_SYSTEM_MESSAGE = """
53
+ {mode}
55
54
 
56
55
  You do not need to attempt answering a question with just one query.
57
56
  You could make a sequence of SQL queries to help you write the final query.
@@ -65,19 +64,24 @@ are "Male" and "Female".
65
64
 
66
65
  Start by asking what I would like to know about the data.
67
66
 
68
- When you have FINISHED the given query or database update task,
69
- say {DONE} and show your answer.
70
-
71
67
  """
72
68
 
73
- ADDRESSING_INSTRUCTION = f"""
69
+ ADDRESSING_INSTRUCTION = """
74
70
  IMPORTANT - Whenever you are NOT writing a SQL query, make sure you address the user
75
- using {{prefix}}User. You MUST use the EXACT syntax {{prefix}} !!!
71
+ using {prefix}User. You MUST use the EXACT syntax {prefix} !!!
76
72
 
77
73
  In other words, you ALWAYS write EITHER:
78
74
  - a SQL query using the `run_query` tool,
79
- - OR address the user using {{prefix}}User, and include {DONE} to indicate your
80
- task is FINISHED.
75
+ - OR address the user using {prefix}User
76
+ """
77
+
78
+ DONE_INSTRUCTION = f"""
79
+ When you are SURE you have the CORRECT answer to a user's query or request,
80
+ use the `{DoneTool.name()}` with `content` set to the answer or result.
81
+ If you DO NOT think you have the answer to the user's query or request,
82
+ you SHOULD NOT use the `{DoneTool.name()}` tool.
83
+ Instead, you must CONTINUE to improve your queries (tools) to get the correct answer,
84
+ and finally use the `{DoneTool.name()}` tool to send the correct answer to the user.
81
85
  """
82
86
 
83
87
 
@@ -96,7 +100,10 @@ class SQLChatAgentConfig(ChatAgentConfig):
96
100
  context_descriptions: Dict[str, Dict[str, Union[str, Dict[str, str]]]] = {}
97
101
  use_schema_tools: bool = False
98
102
  multi_schema: bool = False
99
- addressing_prefix: str = SEND_TO
103
+ # whether the agent is used in a continuous chat with user,
104
+ # as opposed to returning a result from the task.run()
105
+ chat_mode: bool = False
106
+ addressing_prefix: str = ""
100
107
 
101
108
  """
102
109
  Optional, but strongly recommended, context descriptions for tables, columns,
@@ -225,14 +232,21 @@ class SQLChatAgent(ChatAgent):
225
232
  """Initialize message tools used for chatting."""
226
233
  message = self._format_message()
227
234
  self.config.system_message = self.config.system_message.format(mode=message)
228
- if self.config.addressing_prefix != "":
235
+
236
+ if self.config.chat_mode:
237
+ self.config.addressing_prefix = self.config.addressing_prefix or SEND_TO
229
238
  self.config.system_message += ADDRESSING_INSTRUCTION.format(
230
239
  prefix=self.config.addressing_prefix
231
240
  )
241
+ else:
242
+ self.config.system_message += DONE_INSTRUCTION
243
+
232
244
  super().__init__(self.config)
233
- self.enable_message(RunQueryTool)
245
+ self.enable_message([RunQueryTool, ForwardTool])
234
246
  if self.config.use_schema_tools:
235
247
  self._enable_schema_tools()
248
+ if not self.config.chat_mode:
249
+ self.enable_message(DoneTool)
236
250
 
237
251
  def _format_message(self) -> str:
238
252
  if self.engine is None:
@@ -270,7 +284,7 @@ class SQLChatAgent(ChatAgent):
270
284
 
271
285
  def handle_message_fallback(
272
286
  self, msg: str | ChatDocument
273
- ) -> str | ChatDocument | None:
287
+ ) -> str | ForwardTool | None:
274
288
  """
275
289
  Handle the scenario where current msg is not a tool.
276
290
  Special handling is only needed if the message was from the LLM
@@ -278,60 +292,40 @@ class SQLChatAgent(ChatAgent):
278
292
  """
279
293
  if not self.llm_responded:
280
294
  return None
281
- if self.used_run_query:
282
- prefix = (
283
- self.config.addressing_prefix + "User"
284
- if self.config.addressing_prefix
285
- else ""
286
- )
287
- return (
288
- DONE + prefix + (msg.content if isinstance(msg, ChatDocument) else msg)
289
- )
295
+ if self.interactive:
296
+ return ForwardTool(agent="User")
290
297
 
291
- else:
292
- reminder = """
293
- You may have forgotten to use the `run_query` tool to execute an SQL query
294
- for the user's question/request
298
+ tools_instruction = f"""
299
+ For example you may want to use the TOOL
300
+ `{RunQueryTool.name()}` to further explore the database contents
301
+ """
302
+ if self.config.use_schema_tools:
303
+ tools_instruction += """
304
+ OR you may want to use one of the schema tools to
305
+ explore the database schema
306
+ """
307
+ if self.config.chat_mode:
308
+ return f"""
309
+ Since you did not explicitly address the User, it is not clear
310
+ whether:
311
+ - you intend this to be the final response to the
312
+ user's query/request, in which case you must use the
313
+ `{ForwardTool.name()}` to indicate this.
314
+ - OR, you FORGOT to use an Appropriate TOOL,
315
+ in which case you should use the available tools to
316
+ make progress on the user's query/request.
317
+ {tools_instruction}
295
318
  """
296
- if self.config.addressing_prefix != "":
297
- reminder += f"""
298
- OR you may have forgotten to address the user using the prefix
299
- {self.config.addressing_prefix}
300
- """
301
- return reminder
302
-
303
- def _agent_response(
304
- self,
305
- msg: Optional[str | ChatDocument] = None,
306
- ) -> Optional[ChatDocument]:
307
- # Your override code here
308
- if msg is None:
309
- return None
310
-
311
- results = self.handle_message(msg)
312
- if results is None:
313
- return None
314
319
 
315
- output = results
316
- if SQL_ERROR_MSG in output:
317
- output = "There was an error in the SQL Query. Press enter to retry."
318
-
319
- console.print(f"[red]{self.indent}", end="")
320
- print(f"[red]Agent: {output}")
321
- sender_name = self.config.name
322
- if isinstance(msg, ChatDocument) and msg.function_call is not None:
323
- sender_name = msg.function_call.name
324
-
325
- content = results.content if isinstance(results, ChatDocument) else results
326
-
327
- return ChatDocument(
328
- content=content,
329
- metadata=ChatDocMetaData(
330
- source=Entity.AGENT,
331
- sender=Entity.AGENT,
332
- sender_name=sender_name,
333
- ),
334
- )
320
+ return f"""
321
+ The intent of your response is not clear:
322
+ - if you intended this to be the FINAL answer to the user's query,
323
+ then use the `{DoneTool.name()}` to indicate so,
324
+ with the `content` set to the answer or result.
325
+ - otherwise, use one of the available tools to make progress
326
+ to arrive at the final answer.
327
+ {tools_instruction}
328
+ """
335
329
 
336
330
  def retry_query(self, e: Exception, query: str) -> str:
337
331
  """
@@ -4,7 +4,10 @@ from langroid.agent.tool_message import ToolMessage
4
4
 
5
5
 
6
6
  class RetrievalTool(ToolMessage):
7
- """Retrieval tool, only to be used by a DocChatAgent."""
7
+ """
8
+ Retrieval tool, only to be used by a DocChatAgent.
9
+ The handler method is defined in DocChatAgent.retrieval_tool
10
+ """
8
11
 
9
12
  request: str = "retrieval_tool"
10
13
  purpose: str = """
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.22.2"
3
+ version = "0.22.4"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes