langroid 0.22.4__py3-none-any.whl → 0.22.6__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/base.py CHANGED
@@ -142,7 +142,7 @@ class Agent(ABC):
142
142
  self.llm_tools_handled: Set[str] = set()
143
143
  self.llm_tools_usable: Set[str] = set()
144
144
  self.llm_tools_known: Set[str] = set() # all known tools, handled/used or not
145
- self.interactive: bool | None = None
145
+ self.interactive: bool = True # may be modified by Task wrapper
146
146
  self.token_stats_str = ""
147
147
  self.default_human_response: Optional[str] = None
148
148
  self._indent = ""
@@ -645,10 +645,11 @@ class Agent(ABC):
645
645
  need_human_response = (
646
646
  isinstance(msg, ChatDocument) and msg.metadata.recipient == Entity.USER
647
647
  )
648
+ default_user_msg = (
649
+ (self.default_human_response or "null") if need_human_response else ""
650
+ )
648
651
 
649
- interactive = self.interactive or settings.interactive
650
-
651
- if not interactive and not need_human_response:
652
+ if not self.interactive and not need_human_response:
652
653
  return None
653
654
  elif self.default_human_response is not None:
654
655
  user_msg = self.default_human_response
@@ -669,6 +670,8 @@ class Agent(ABC):
669
670
  tool_ids = []
670
671
  if msg is not None and isinstance(msg, ChatDocument):
671
672
  tool_ids = msg.metadata.tool_ids
673
+
674
+ user_msg = user_msg.strip() or default_user_msg.strip()
672
675
  # only return non-None result if user_msg not empty
673
676
  if not user_msg:
674
677
  return None
@@ -362,6 +362,17 @@ class SQLChatAgent(ChatAgent):
362
362
 
363
363
  return error_message_template
364
364
 
365
+ def _available_tool_names(self) -> str:
366
+ return ",".join(
367
+ tool.name() # type: ignore
368
+ for tool in [
369
+ RunQueryTool,
370
+ GetTableNamesTool,
371
+ GetTableSchemaTool,
372
+ GetColumnDescriptionsTool,
373
+ ]
374
+ )
375
+
365
376
  def run_query(self, msg: RunQueryTool) -> str:
366
377
  """
367
378
  Handle a RunQueryTool message by executing a SQL query and returning the result.
@@ -399,7 +410,20 @@ class SQLChatAgent(ChatAgent):
399
410
  finally:
400
411
  session.close()
401
412
 
402
- return response_message
413
+ final_message = f"""
414
+ Below is the result from your use of the TOOL `{RunQueryTool.name()}`:
415
+ ==== result ====
416
+ {response_message}
417
+ ================
418
+
419
+ If you are READY to ANSWER the ORIGINAL QUERY:
420
+ use the `{DoneTool.name()}` tool to send the result to the user,
421
+ with the `content` set to the answer or result
422
+ OTHERWISE:
423
+ continue using one of your available TOOLs:
424
+ {self._available_tool_names()}
425
+ """
426
+ return final_message
403
427
 
404
428
  def _format_rows(self, rows: Sequence[Row[Any]]) -> str:
405
429
  """
@@ -1,4 +1,4 @@
1
- from typing import List
1
+ from typing import List, Tuple
2
2
 
3
3
  from langroid.agent.tool_message import ToolMessage
4
4
 
@@ -11,6 +11,20 @@ class RunQueryTool(ToolMessage):
11
11
  """
12
12
  query: str
13
13
 
14
+ @classmethod
15
+ def examples(cls) -> List["ToolMessage" | Tuple[str, "ToolMessage"]]:
16
+ return [
17
+ cls(
18
+ query="SELECT * FROM movies WHERE genre = 'comedy'",
19
+ ),
20
+ (
21
+ "Find all movies with a rating of 5",
22
+ cls(
23
+ query="SELECT * FROM movies WHERE rating = 5",
24
+ ),
25
+ ),
26
+ ]
27
+
14
28
 
15
29
  class GetTableNamesTool(ToolMessage):
16
30
  request: str = "get_table_names"
langroid/agent/task.py CHANGED
@@ -1023,9 +1023,11 @@ class Task:
1023
1023
  found_response = False
1024
1024
  # (responder, result) from a responder who explicitly said NO_ANSWER
1025
1025
  no_answer_response: None | Tuple[Responder, ChatDocument] = None
1026
+ n_non_responders = 0
1026
1027
  for r in responders:
1027
1028
  self.is_pass_thru = False
1028
1029
  if not self._can_respond(r):
1030
+ n_non_responders += 1
1029
1031
  # create dummy msg for logging
1030
1032
  log_doc = ChatDocument(
1031
1033
  content="[CANNOT RESPOND]",
@@ -1038,6 +1040,9 @@ class Task:
1038
1040
  # no need to register this dummy msg in ObjectRegistry
1039
1041
  ChatDocument.delete_id(log_doc.id())
1040
1042
  self.log_message(r, log_doc)
1043
+ if n_non_responders == len(responders):
1044
+ # don't stay in this "non-response" loop forever
1045
+ break
1041
1046
  continue
1042
1047
  self.human_tried = r == Entity.USER
1043
1048
  result = self.response(r, turns)
langroid/parsing/utils.py CHANGED
@@ -31,6 +31,10 @@ def download_nltk_resource(resource: str) -> None:
31
31
  nltk.download(resource, quiet=True)
32
32
 
33
33
 
34
+ # Download punkt_tab resource at module import
35
+ download_nltk_resource("punkt_tab")
36
+ download_nltk_resource("gutenberg")
37
+
34
38
  T = TypeVar("T")
35
39
 
36
40
 
@@ -46,7 +50,6 @@ def batched(iterable: Iterable[T], n: int) -> Iterable[Sequence[T]]:
46
50
 
47
51
  def generate_random_sentences(k: int) -> str:
48
52
  # Load the sample text
49
- download_nltk_resource("gutenberg")
50
53
 
51
54
  from nltk.corpus import gutenberg
52
55
 
@@ -17,8 +17,6 @@ class Settings(BaseSettings):
17
17
  stream: bool = True # stream output?
18
18
  cache: bool = True # use cache?
19
19
  cache_type: Literal["redis", "fakeredis", "momento", "none"] = "redis" # cache type
20
- interactive: bool = True # interactive mode?
21
- gpt3_5: bool = True # use GPT-3.5?
22
20
  chat_model: str = "" # language model name, e.g. litellm/ollama/llama2
23
21
  quiet: bool = False # quiet mode (i.e. suppress all output)?
24
22
  notebook: bool = False # running in a notebook?
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.22.4
3
+ Version: 0.22.6
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -68,7 +68,7 @@ Requires-Dist: metaphor-python (>=0.1.23,<0.2.0) ; extra == "all" or extra == "m
68
68
  Requires-Dist: momento (>=1.10.2,<1.21) ; extra == "momento"
69
69
  Requires-Dist: neo4j (>=5.14.1,<6.0.0) ; extra == "all" or extra == "neo4j"
70
70
  Requires-Dist: nest-asyncio (>=1.6.0,<2.0.0)
71
- Requires-Dist: nltk (>=3.8.1,<4.0.0)
71
+ Requires-Dist: nltk (>=3.8.2,<4.0.0)
72
72
  Requires-Dist: onnxruntime (>=1.16.1,<2.0.0)
73
73
  Requires-Dist: openai (>=1.45.0,<2.0.0)
74
74
  Requires-Dist: pandas (>=2.0.3,<3.0.0)
@@ -1,6 +1,6 @@
1
1
  langroid/__init__.py,sha256=z_fCOLQJPOw3LLRPBlFB5-2HyCjpPgQa4m4iY5Fvb8Y,1800
2
2
  langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,786
3
- langroid/agent/base.py,sha256=IatVtrdstxMcreeVSndNoChFKxrJIEkYRpNruBxRQ7M,67112
3
+ langroid/agent/base.py,sha256=-lMv0XHO7ya1P6IW_xb439Mx8WhFEPgt1AmcMe200ds,67268
4
4
  langroid/agent/batch.py,sha256=QZdlt1563hx4l3AXrCaGovE-PNG93M3DsvQAbDzdiS8,13705
5
5
  langroid/agent/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  langroid/agent/callbacks/chainlit.py,sha256=JJXI3UGTyTDg2FFath4rqY1GyUo_0pbVBt8CZpvdtn4,23289
@@ -30,15 +30,15 @@ langroid/agent/special/neo4j/tools.py,sha256=Vw3HvtDfG2c4_bUHgt4_ZbJq48lpIQstbjj
30
30
  langroid/agent/special/relevance_extractor_agent.py,sha256=zIx8GUdVo1aGW6ASla0NPQjYYIpmriK_TYMijqAx3F8,4796
31
31
  langroid/agent/special/retriever_agent.py,sha256=lvMvf-u9rSosg4YASuFdUbGLgkzLPknXAbJZfZ1LZCc,1868
32
32
  langroid/agent/special/sql/__init__.py,sha256=mWfmm1QpXCezpFOS2eI57M0L_Ok3q5_ukG8tXBnBrEA,319
33
- langroid/agent/special/sql/sql_chat_agent.py,sha256=j8m1Lm8j_w3m3gzPjuC2vea_t_bfhNewCfDnPDzrc38,17191
33
+ langroid/agent/special/sql/sql_chat_agent.py,sha256=bh7UCFltngrQxsjH5PKM7JECjA6tMnntKOlUcjEmnT8,18011
34
34
  langroid/agent/special/sql/utils/__init__.py,sha256=JFif6CRTrN-bc91uuAI4K9fe2ndIWSNMVxJ0WA68--M,446
35
35
  langroid/agent/special/sql/utils/description_extractors.py,sha256=cX8TIpmTPXZXQTMpIi3OUFwFsPywxFFdurpx717Kq0I,6529
36
36
  langroid/agent/special/sql/utils/populate_metadata.py,sha256=1J22UsyEPKzwK0XlJZtYn9r6kYc0FXIr8-lZrndYlhc,3131
37
37
  langroid/agent/special/sql/utils/system_message.py,sha256=qKLHkvQWRQodTtPLPxr1GSLUYUFASZU8x-ybV67cB68,1885
38
- langroid/agent/special/sql/utils/tools.py,sha256=vFYysk6Vi7HJjII8B4RitA3pt_z3gkSglDNdhNVMiFc,1332
38
+ langroid/agent/special/sql/utils/tools.py,sha256=ovCePzq5cmbqw0vsVPBzxdZpUcSUIfTiDSMGXustZW8,1749
39
39
  langroid/agent/special/table_chat_agent.py,sha256=d9v2wsblaRx7oMnKhLV7uO_ujvk9gh59pSGvBXyeyNc,9659
40
40
  langroid/agent/structured_message.py,sha256=y7pud1EgRNeTFZlJmBkLmwME3yQJ_IYik-Xds9kdZbY,282
41
- langroid/agent/task.py,sha256=0ewueaJBXvOvlSAHipL21xqgcpiGySDHr-A_Ov0WyQ8,86659
41
+ langroid/agent/task.py,sha256=BdLNWFQqA9X-9ZtUIC2NwmRrPAX7GB0mAC0aXDzK0Uk,86877
42
42
  langroid/agent/tool_message.py,sha256=bjBSk1N1IgqqYGmOy6O97zPFMSaUdEK7r8ZjOaJwoeE,11335
43
43
  langroid/agent/tools/__init__.py,sha256=IMgCte-_ZIvCkozGQmvMqxIw7_nKLKzD78ccJL1bnQU,804
44
44
  langroid/agent/tools/duckduckgo_search_tool.py,sha256=NhsCaGZkdv28nja7yveAhSK_w6l_Ftym8agbrdzqgfo,1935
@@ -100,7 +100,7 @@ langroid/parsing/table_loader.py,sha256=qNM4obT_0Y4tjrxNBCNUYjKQ9oETCZ7FbolKBTcz
100
100
  langroid/parsing/url_loader.py,sha256=Na2TBlKuQkloZzkE2d7xl6mh9olS3CbpgCsJbJ-xhIA,4472
101
101
  langroid/parsing/url_loader_cookies.py,sha256=Lg4sNpRz9MByWq2mde6T0hKv68VZSV3mtMjNEHuFeSU,2327
102
102
  langroid/parsing/urls.py,sha256=XjpaV5onG7gKQ5iQeFTzHSw5P08Aqw0g-rMUu61lR6s,7988
103
- langroid/parsing/utils.py,sha256=pbSAbfwA28EBNESpQRJee_Kp1b44qze-2_2b9qJOKfM,12646
103
+ langroid/parsing/utils.py,sha256=kb9DlHaG1iQB-6JagH1C26SdCNNf8U-2XaXia4_dWCw,12726
104
104
  langroid/parsing/web_search.py,sha256=wGycU86N3nsZ78E9iS-BIm5NWueDgoknojABE0_1LRA,4886
105
105
  langroid/prompts/__init__.py,sha256=RW11vK6jiLPuaUh4GpeFvstti73gkm8_rDMtrbo2YsU,142
106
106
  langroid/prompts/chat-gpt4-system-prompt.md,sha256=Q3uLCJTPQvmUkZN2XDnkBC7M2K3X0F3C3GIQBaFvYvw,5329
@@ -115,7 +115,7 @@ langroid/utils/.chainlit/translations/en-US.json,sha256=DAFz2HjOFFfboCStrUfKFg2B
115
115
  langroid/utils/__init__.py,sha256=Sruos2tB4G7Tn0vlblvYlX9PEGR0plI2uE0PJ4d_EC4,353
116
116
  langroid/utils/algorithms/__init__.py,sha256=WylYoZymA0fnzpB4vrsH_0n7WsoLhmuZq8qxsOCjUpM,41
117
117
  langroid/utils/algorithms/graph.py,sha256=JbdpPnUOhw4-D6O7ou101JLA3xPCD0Lr3qaPoFCaRfo,2866
118
- langroid/utils/configuration.py,sha256=LgjHGB0qgKKTwBaVt84APiqvJbz6pLwylUvHWYmzyP0,3303
118
+ langroid/utils/configuration.py,sha256=V3RS8OP7AC0_bDKczxfortD0F5H3cnsZL0ulKBxuoHU,3213
119
119
  langroid/utils/constants.py,sha256=vKIdkAJwyPT-bRA5MDPiOl7-EppBRmewRBIOcdXi4I4,959
120
120
  langroid/utils/docker.py,sha256=kJQOLTgM0x9j9pgIIqp0dZNZCTvoUDhp6i8tYBq1Jr0,1105
121
121
  langroid/utils/git_utils.py,sha256=WnflJ3R3owhlD0LNdSJakcKhExcEehE1UW5jYVQl8JY,7955
@@ -142,8 +142,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
142
142
  langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
143
143
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
144
144
  langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
145
- pyproject.toml,sha256=OKFg1VTiVXkPi5MgYHzp5RLR0wltiTHWJeb7xo7Kis4,7488
146
- langroid-0.22.4.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
147
- langroid-0.22.4.dist-info/METADATA,sha256=nE0exrJpSqQR5MCdjEvLDifMqoCTngZJOn4PvKfqlX8,57107
148
- langroid-0.22.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
149
- langroid-0.22.4.dist-info/RECORD,,
145
+ pyproject.toml,sha256=iOYeCZhSZb6evu9r2X8g7nY_Q0m9PqX1Q-upDqifwek,7488
146
+ langroid-0.22.6.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
147
+ langroid-0.22.6.dist-info/METADATA,sha256=k9lDoCXrj1a8oEaphDoEeVfqf-2b2MkgNaY71axEE4w,57107
148
+ langroid-0.22.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
149
+ langroid-0.22.6.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.22.4"
3
+ version = "0.22.6"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"
@@ -62,7 +62,7 @@ fakeredis = "^2.12.1"
62
62
  faker = "^18.9.0"
63
63
  requests = "^2.31.0"
64
64
  pyparsing = "^3.0.9"
65
- nltk = "^3.8.1"
65
+ nltk = "^3.8.2"
66
66
  qdrant-client = "^1.8.0"
67
67
  pydantic = ">=1,<3"
68
68
  pandas = "^2.0.3"