langroid 0.52.5__py3-none-any.whl → 0.52.7__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.
@@ -735,7 +735,11 @@ class ChatAgent(Agent):
735
735
  self.llm_tools_usable.discard(t)
736
736
  self.llm_functions_usable.discard(t)
737
737
 
738
- # Set tool instructions and JSON format instructions
738
+ self._update_tool_instructions()
739
+
740
+ def _update_tool_instructions(self) -> None:
741
+ # Set tool instructions and JSON format instructions,
742
+ # in case Tools have been enabled/disabled.
739
743
  if self.config.use_tools:
740
744
  self.system_tool_format_instructions = self.tool_format_rules()
741
745
  self.system_tool_instructions = self.tool_instructions()
@@ -977,6 +981,8 @@ class ChatAgent(Agent):
977
981
  self.llm_tools_usable.discard(t)
978
982
  self.llm_functions_usable.discard(t)
979
983
 
984
+ self._update_tool_instructions()
985
+
980
986
  def disable_message_use_except(self, message_class: Type[ToolMessage]) -> None:
981
987
  """
982
988
  Disable this agent from USING ALL messages EXCEPT a message class (Tool)
@@ -988,6 +994,7 @@ class ChatAgent(Agent):
988
994
  for r in to_remove:
989
995
  self.llm_tools_usable.discard(r)
990
996
  self.llm_functions_usable.discard(r)
997
+ self._update_tool_instructions()
991
998
 
992
999
  def _load_output_format(self, message: ChatDocument) -> None:
993
1000
  """
@@ -123,6 +123,9 @@ class DocChatAgentConfig(ChatAgentConfig):
123
123
  None # filter condition for various lexical/semantic search fns
124
124
  )
125
125
  conversation_mode: bool = True # accumulate message history?
126
+ # retain retrieved context? Setting to True increases token consumption, but
127
+ # helps LLM fix citation errors and improve accuracy of follow-up questions.
128
+ retain_context: bool = False
126
129
  # In assistant mode, DocChatAgent receives questions from another Agent,
127
130
  # and those will already be in stand-alone form, so in this mode
128
131
  # there is no need to convert them to stand-alone form.
@@ -861,11 +864,15 @@ class DocChatAgent(ChatAgent):
861
864
  # one for `final_prompt`, and one for the LLM response
862
865
 
863
866
  if self.config.conversation_mode:
864
- # respond with temporary context
865
- answer_doc = super()._llm_response_temp_context(question, final_prompt)
867
+ if self.config.retain_context:
868
+ answer_doc = super().llm_response(final_prompt)
869
+ else:
870
+ # respond with temporary context
871
+ answer_doc = super()._llm_response_temp_context(question, final_prompt)
866
872
  else:
867
873
  answer_doc = super().llm_response_forget(final_prompt)
868
874
 
875
+ assert answer_doc is not None, "LLM response should not be None here"
869
876
  final_answer = answer_doc.content.strip()
870
877
  show_if_debug(final_answer, "SUMMARIZE_RESPONSE= ")
871
878
 
@@ -1893,7 +1893,8 @@ class OpenAIGPT(LanguageModel):
1893
1893
  max_completion_tokens=max_tokens,
1894
1894
  stream=self.get_stream(),
1895
1895
  )
1896
- if self.get_stream():
1896
+ if self.get_stream() and "groq" not in self.chat_model_orig:
1897
+ # groq fails when we include stream_options in the request
1897
1898
  args.update(
1898
1899
  dict(
1899
1900
  # get token-usage numbers in stream mode from OpenAI API,
@@ -67,6 +67,7 @@ def retry_with_exponential_backoff(
67
67
  for err in [
68
68
  "BadRequestError",
69
69
  "ConnectionError",
70
+ "NotFoundError",
70
71
  ]
71
72
  ):
72
73
  logger.error(f"OpenAI API request failed with error: {e}.")
@@ -137,6 +138,19 @@ def async_retry_with_exponential_backoff(
137
138
  raise e
138
139
  # Retry on specified errors
139
140
  except errors as e:
141
+ # For certain types of errors that slip through here
142
+ # (e.g. when using proxies like LiteLLM, do not retry)
143
+ if any(
144
+ err in str(e)
145
+ for err in [
146
+ "BadRequestError",
147
+ "ConnectionError",
148
+ "NotFoundError",
149
+ ]
150
+ ):
151
+ logger.error(f"OpenAI API request failed with error: {e}.")
152
+ raise e
153
+
140
154
  # Increment retries
141
155
  num_retries += 1
142
156
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langroid
3
- Version: 0.52.5
3
+ Version: 0.52.7
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  Author-email: Prasad Chalasani <pchalasani@gmail.com>
6
6
  License: MIT
@@ -5,7 +5,7 @@ langroid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,786
6
6
  langroid/agent/base.py,sha256=lWR4ivX_elTFejpknLhkO-DlAGT3aG6ojQAVkzDOqMc,80090
7
7
  langroid/agent/batch.py,sha256=vi1r5i1-vN80WfqHDSwjEym_KfGsqPGUtwktmiK1nuk,20635
8
- langroid/agent/chat_agent.py,sha256=mIkf3kq5m1RPXeBb6U52pXB9itum0ChcpXABC_g-Xfs,85082
8
+ langroid/agent/chat_agent.py,sha256=nsFSARSANCVByL4fAl_DhyWm9gM7s_6waqNsmePXJMA,85309
9
9
  langroid/agent/chat_document.py,sha256=6O20Fp4QrquykaF2jFtwNHkvcoDte1LLwVZNk9mVH9c,18057
10
10
  langroid/agent/openai_assistant.py,sha256=JkAcs02bIrgPNVvUWVR06VCthc5-ulla2QMBzux_q6o,34340
11
11
  langroid/agent/task.py,sha256=HB6N-Jn80HFqCf0ZYOC1v3Bn3oO7NLjShHQJJFwW0q4,90557
@@ -14,7 +14,7 @@ langroid/agent/xml_tool_message.py,sha256=6SshYZJKIfi4mkE-gIoSwjkEYekQ8GwcSiCv7a
14
14
  langroid/agent/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  langroid/agent/callbacks/chainlit.py,sha256=UHB6P_J40vsVnssosqkpkOVWRf9NK4TOY0_G2g_Arsg,20900
16
16
  langroid/agent/special/__init__.py,sha256=gik_Xtm_zV7U9s30Mn8UX3Gyuy4jTjQe9zjiE3HWmEo,1273
17
- langroid/agent/special/doc_chat_agent.py,sha256=ALp2rv12J-ChRCxVtflDwz6n0qIbUAymldIy8qpsvrg,65236
17
+ langroid/agent/special/doc_chat_agent.py,sha256=7PvVKHrXHw2LoSgU2-3hE7mz46r5oKB3o_bFhWmfT_I,65642
18
18
  langroid/agent/special/doc_chat_task.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  langroid/agent/special/lance_doc_chat_agent.py,sha256=s8xoRs0gGaFtDYFUSIRchsgDVbS5Q3C2b2mr3V1Fd-Q,10419
20
20
  langroid/agent/special/lance_tools.py,sha256=qS8x4wi8mrqfbYV2ztFzrcxyhHQ0ZWOc-zkYiH7awj0,2105
@@ -72,8 +72,8 @@ langroid/language_models/base.py,sha256=pfN3t-BktKmN_4K8pwmpjC9OdcHxsytM5s5TmsJ-
72
72
  langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
73
73
  langroid/language_models/mock_lm.py,sha256=5BgHKDVRWFbUwDT_PFgTZXz9-k8wJSA2e3PZmyDgQ1k,4022
74
74
  langroid/language_models/model_info.py,sha256=vOaTi-XFKnz-BvHUvgjnt0XfOtl21Apev3Zy7Rhckbw,14458
75
- langroid/language_models/openai_gpt.py,sha256=Hw4llY9Dbox7L0sVP06q10ayoem8FOfXSfbLm3u55v4,85317
76
- langroid/language_models/utils.py,sha256=hC5p61P_Qlrowkm5wMap1A1b5ZUCwK_XhPIzAQk1T1s,5483
75
+ langroid/language_models/openai_gpt.py,sha256=p9Bi2tIn84U1aqIbgeDmq0A02VxFODfyhiXqeinKR0g,85427
76
+ langroid/language_models/utils.py,sha256=n55Oe2_V_4VNGhytvPWLYC-0tFS07RTjN83KWl-p_MI,6032
77
77
  langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
78
78
  langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
79
79
  langroid/language_models/prompt_formatter/hf_formatter.py,sha256=PVJppmjRvD-2DF-XNC6mE05vTZ9wbu37SmXwZBQhad0,5055
@@ -129,7 +129,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
129
129
  langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
130
130
  langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
131
131
  langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
132
- langroid-0.52.5.dist-info/METADATA,sha256=zlyRvxolWKDmmw88ARFvXeIT9dkfROqJBAVV4v2saBY,63519
133
- langroid-0.52.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
- langroid-0.52.5.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
- langroid-0.52.5.dist-info/RECORD,,
132
+ langroid-0.52.7.dist-info/METADATA,sha256=-yVeanvHmLWshy3ZjElHv884I8_i5WRLZb8-TMcSRcs,63519
133
+ langroid-0.52.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ langroid-0.52.7.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
+ langroid-0.52.7.dist-info/RECORD,,