langroid 0.22.2__py3-none-any.whl → 0.22.3__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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.22.2
3
+ Version: 0.22.3
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -4,7 +4,7 @@ langroid/agent/base.py,sha256=IatVtrdstxMcreeVSndNoChFKxrJIEkYRpNruBxRQ7M,67112
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
7
- langroid/agent/chat_agent.py,sha256=2aUDqM6jsdeU8xt-P86JU2TuZhTpPkUVx9mkXFMy8Rs,51646
7
+ langroid/agent/chat_agent.py,sha256=DU_wtNFAxSJJFRkxpWNNqvI1P5QHkdi529As-22-Aog,51955
8
8
  langroid/agent/chat_document.py,sha256=FZ_PkeKU5OVp1IUlMvspfqxIXzlyd7J_F32DSYrxQ7E,17651
9
9
  langroid/agent/helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
@@ -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=SqUjrPzZZgrSr-AojnyP3Du81tNyxCEsP_N1m-smqiA,7488
146
- langroid-0.22.2.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
147
- langroid-0.22.2.dist-info/METADATA,sha256=xoC9bs2-ntnP7OWrkvrGRmFWt2opCRmNCaeCy2hF7Tc,57107
148
- langroid-0.22.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
149
- langroid-0.22.2.dist-info/RECORD,,
145
+ pyproject.toml,sha256=blIMIWJ0_N8r8YBAJV1BoWriHqWE3erxmjQb-2npkbU,7488
146
+ langroid-0.22.3.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
147
+ langroid-0.22.3.dist-info/METADATA,sha256=_1rwLApadQ9D1HTsVSTq03sPgyiALup286Snmx2Ei7I,57107
148
+ langroid-0.22.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
149
+ langroid-0.22.3.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.22.2"
3
+ version = "0.22.3"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"