langroid 0.18.1__py3-none-any.whl → 0.18.2__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
@@ -91,6 +91,8 @@ class AgentConfig(BaseSettings):
91
91
  show_stats: bool = True # show token usage/cost stats?
92
92
  add_to_registry: bool = True # register agent in ObjectRegistry?
93
93
  respond_tools_only: bool = False # respond only to tool messages (not plain text)?
94
+ # allow multiple tool messages in a single response?
95
+ allow_multiple_tools: bool = True
94
96
 
95
97
  @validator("name")
96
98
  def check_name_alphanum(cls, v: str) -> str:
@@ -1120,6 +1122,8 @@ class Agent(ABC):
1120
1122
  # as a response to the tool message even though the tool was not intended
1121
1123
  # for this agent.
1122
1124
  return None
1125
+ if len(tools) > 1 and not self.config.allow_multiple_tools:
1126
+ return self.to_ChatDocument("ERROR: Use ONE tool at a time!")
1123
1127
  if len(tools) == 0:
1124
1128
  fallback_result = self.handle_message_fallback(msg)
1125
1129
  if fallback_result is None:
langroid/utils/system.py CHANGED
@@ -10,7 +10,7 @@ import socket
10
10
  import traceback
11
11
  import uuid
12
12
  from pathlib import Path
13
- from typing import Any
13
+ from typing import Any, Literal
14
14
 
15
15
  logger = logging.getLogger(__name__)
16
16
 
@@ -186,24 +186,48 @@ def generate_unique_id() -> str:
186
186
  return str(uuid.uuid4())
187
187
 
188
188
 
189
- def create_file(filepath: str | Path, content: str = "") -> None:
189
+ def create_file(
190
+ filepath: str | Path,
191
+ content: str = "",
192
+ if_exists: Literal["overwrite", "skip", "error", "append"] = "overwrite",
193
+ ) -> None:
190
194
  """
191
- Create a file with the given content in the specified directory.
195
+ Create, overwrite or append to a file, with the given content
196
+ at the specified filepath.
192
197
  If content is empty, it will simply touch to create an empty file.
193
198
 
194
199
  Args:
195
200
  filepath (str|Path): The relative path of the file to be created
196
201
  content (str): The content to be written to the file
202
+ if_exists (Literal["overwrite", "skip", "error", "append"]):
203
+ Action to take if file exists
197
204
  """
198
- Path(filepath).parent.mkdir(parents=True, exist_ok=True)
199
- if content == "":
200
- Path(filepath).touch()
205
+ filepath = Path(filepath)
206
+ filepath.parent.mkdir(parents=True, exist_ok=True)
207
+
208
+ if filepath.exists():
209
+ if if_exists == "skip":
210
+ logger.warning(f"File already exists, skipping: {filepath}")
211
+ return
212
+ elif if_exists == "error":
213
+ raise FileExistsError(f"File already exists: {filepath}")
214
+ elif if_exists == "append":
215
+ mode = "a"
216
+ else: # overwrite
217
+ mode = "w"
218
+ else:
219
+ mode = "w"
220
+
221
+ if content == "" and mode in ["a", "w"]:
222
+ filepath.touch()
223
+ logger.warning(f"Empty file created: {filepath}")
201
224
  else:
202
225
  # the newline = '\n` argument is used to ensure that
203
226
  # newlines in the content are written as actual line breaks
204
- with open(filepath, "w", newline="\n") as f:
227
+ with open(filepath, mode, newline="\n") as f:
205
228
  f.write(content)
206
- logger.warning(f"File created/updated: {filepath}")
229
+ action = "appended to" if mode == "a" else "created/updated in"
230
+ logger.warning(f"Content {action}: {filepath}")
207
231
 
208
232
 
209
233
  def read_file(path: str, line_numbers: bool = False) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.18.1
3
+ Version: 0.18.2
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -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=yFR9yrUWbuIOufgVDPOSjFDIP28JvGJWqvEu0HXEMX8,64045
3
+ langroid/agent/base.py,sha256=tJFil49Us2wRv2oKbikqrmcBv6KAeM-UdZ7Psrr-jjE,64282
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=oiZYfPyfkUfFqhVFBiobN3hAJEaYn0FBSglvNE7t17Q,22302
@@ -125,7 +125,7 @@ langroid/utils/output/printing.py,sha256=yzPJZN-8_jyOJmI9N_oLwEDfjMwVgk3IDiwnZ4e
125
125
  langroid/utils/output/status.py,sha256=rzbE7mDJcgNNvdtylCseQcPGCGghtJvVq3lB-OPJ49E,1049
126
126
  langroid/utils/pandas_utils.py,sha256=UctS986Jtl_MvU5rA7-GfrjEHXP7MNu8ePhepv0bTn0,755
127
127
  langroid/utils/pydantic_utils.py,sha256=iRy7uQhHhQmIDZTTPNX5jXb6fqefMe9N67p3fPfOmTI,20624
128
- langroid/utils/system.py,sha256=CZKEnERYMzFLdb2vBE5SfQRX5yeG-2AnezjmycsvQAU,7651
128
+ langroid/utils/system.py,sha256=AiEehQy0K9c9qHdKsZRCscRrazDzuh5Tv3GRQsA0Cxg,8455
129
129
  langroid/utils/types.py,sha256=4GrOnU3HLWh-UwaUPp7LlB3V413q3K5OSzc0ggDoQ6A,2510
130
130
  langroid/utils/web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
131
131
  langroid/utils/web/login.py,sha256=1iz9eUAHa87vpKIkzwkmFa00avwFWivDSAr7QUhK7U0,2528
@@ -137,8 +137,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
137
137
  langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
138
138
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
139
139
  langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
140
- pyproject.toml,sha256=4WsW43aYs4SPCgfi1cEPVqaOQIHDZRuyUz-S8Ka9oAY,7179
141
- langroid-0.18.1.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
142
- langroid-0.18.1.dist-info/METADATA,sha256=wamviAoQosjm8zl2aLANeU22nc0fsiosnPt8weJNsvs,56486
143
- langroid-0.18.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
144
- langroid-0.18.1.dist-info/RECORD,,
140
+ pyproject.toml,sha256=Vh1LYkE26eWAeHJABpWjRbXvTclFi7B6Lrh8LfuhJjU,7179
141
+ langroid-0.18.2.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
142
+ langroid-0.18.2.dist-info/METADATA,sha256=NFKC5gncBypWwo7Y0ErHW93oGtrNvaa41VNj_bZW2Cs,56486
143
+ langroid-0.18.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
144
+ langroid-0.18.2.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.18.1"
3
+ version = "0.18.2"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"