langroid 0.1.256__py3-none-any.whl → 0.1.257__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
@@ -284,7 +284,7 @@ class Agent(ABC):
284
284
  enabled_classes: List[Type[ToolMessage]] = list(self.llm_tools_map.values())
285
285
  # use at most 2 sample conversations, no need to be exhaustive;
286
286
  sample_convo = [
287
- msg_cls().usage_example() # type: ignore
287
+ msg_cls().usage_examples(random=True) # type: ignore
288
288
  for i, msg_cls in enumerate(enabled_classes)
289
289
  if i < 2
290
290
  ]
@@ -270,9 +270,9 @@ class ChatAgent(Agent):
270
270
  ):
271
271
  # example will be shown in json_format_rules() when using TOOLs,
272
272
  # so we don't need to show it here.
273
- example = "" if self.config.use_tools else (msg_cls.usage_example())
273
+ example = "" if self.config.use_tools else (msg_cls.usage_examples())
274
274
  if example != "":
275
- example = "EXAMPLE: " + example
275
+ example = "EXAMPLES:\n" + example
276
276
  class_instructions = msg_cls.instructions()
277
277
  guidance = (
278
278
  ""
langroid/agent/task.py CHANGED
@@ -525,9 +525,11 @@ class Task:
525
525
  ):
526
526
  raise InfiniteLoopException(
527
527
  """Possible infinite loop detected!
528
- You can adjust infinite loop detection by changing the params
529
- in the TaskConfig passed to the Task constructor:
530
- e.g. set inf_loop_cycle_len=0 to disable loop detection."""
528
+ You can adjust infinite loop detection (or turn it off)
529
+ by changing the params in the TaskConfig passed to the Task
530
+ constructor; see here:
531
+ https://langroid.github.io/langroid/reference/agent/task/#langroid.agent.task.TaskConfig
532
+ """
531
533
  )
532
534
 
533
535
  final_result = self.result()
@@ -620,9 +622,11 @@ class Task:
620
622
  ):
621
623
  raise InfiniteLoopException(
622
624
  """Possible infinite loop detected!
623
- You can adjust infinite loop detection by changing the params
624
- in the TaskConfig passed to the Task constructor:
625
- e.g. set inf_loop_cycle_len=0 to disable loop detection."""
625
+ You can adjust infinite loop detection (or turn it off)
626
+ by changing the params in the TaskConfig passed to the Task
627
+ constructor; see here:
628
+ https://langroid.github.io/langroid/reference/agent/task/#langroid.agent.task.TaskConfig
629
+ """
626
630
  )
627
631
 
628
632
  final_result = self.result()
@@ -80,21 +80,34 @@ class ToolMessage(ABC, BaseModel):
80
80
  return []
81
81
 
82
82
  @classmethod
83
- def usage_example(cls) -> str:
83
+ def usage_examples(cls, random: bool = False) -> str:
84
84
  """
85
- Instruction to the LLM showing an example of how to use the message.
85
+ Instruction to the LLM showing examples of how to use the tool-message.
86
+
87
+ Args:
88
+ random (bool): whether to pick a random example from the list of examples.
89
+ Set to `true` when using this to illustrate a dialog between LLM and
90
+ user.
91
+ (if false, use ALL examples)
86
92
  Returns:
87
- str: example of how to use the message
93
+ str: examples of how to use the tool/function-call
88
94
  """
89
95
  # pick a random example of the fields
90
96
  if len(cls.examples()) == 0:
91
97
  return ""
92
- ex = choice(cls.examples())
93
- if isinstance(ex, tuple):
94
- # (description, example_instance)
95
- return f"{ex[0]} => {ex[1].json_example()}"
98
+ if random:
99
+ examples = [choice(cls.examples())]
96
100
  else:
97
- return ex.json_example()
101
+ examples = cls.examples()
102
+ examples_jsons = [
103
+ (
104
+ f"EXAMPLE {i}: (THOUGHT: {ex[0]}) => \n{ex[1].json_example()}"
105
+ if isinstance(ex, tuple)
106
+ else f"EXAMPLE {i}:\n {ex.json_example()}"
107
+ )
108
+ for i, ex in enumerate(examples, 1)
109
+ ]
110
+ return "\n\n".join(examples_jsons)
98
111
 
99
112
  def to_json(self) -> str:
100
113
  return self.json(indent=4, exclude={"result", "purpose"})
@@ -139,6 +152,9 @@ class ToolMessage(ABC, BaseModel):
139
152
  # cls.simple_schema() if tool else
140
153
  cls.llm_function_schema(request=True).parameters
141
154
  )
155
+ examples_str = ""
156
+ if cls.examples():
157
+ examples_str = "EXAMPLES:\n" + cls.usage_examples()
142
158
  return textwrap.dedent(
143
159
  f"""
144
160
  TOOL: {cls.default_value("request")}
@@ -146,7 +162,7 @@ class ToolMessage(ABC, BaseModel):
146
162
  JSON FORMAT: {
147
163
  json.dumps(param_dict, indent=4)
148
164
  }
149
- {"EXAMPLE: " + cls.usage_example() if cls.examples() else ""}
165
+ {examples_str}
150
166
  """.lstrip()
151
167
  )
152
168
 
@@ -26,7 +26,12 @@ class SegmentExtractTool(ToolMessage):
26
26
 
27
27
  @classmethod
28
28
  def examples(cls) -> List["ToolMessage" | Tuple[str, "ToolMessage"]]:
29
- return [cls(segment_list="1,3,5-7")]
29
+ return [
30
+ (
31
+ "I want to extract segments 1, 3, and 5 thru 7",
32
+ cls(segment_list="1,3,5-7"),
33
+ )
34
+ ]
30
35
 
31
36
  @classmethod
32
37
  def instructions(cls) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.256
3
+ Version: 0.1.257
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -1,10 +1,10 @@
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=6EznAMa4zeRdouo3U3_UzOI_cblvdpNH4v5CAM-fgbA,37171
3
+ langroid/agent/base.py,sha256=aSwWmOBg0d3QQHUSauscMNfnl8Wkv6nrk2nngKa9DjM,37183
4
4
  langroid/agent/batch.py,sha256=feRA_yRG768ElOQjrKEefcRv6Aefd_yY7qktuYUQDwc,10040
5
5
  langroid/agent/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  langroid/agent/callbacks/chainlit.py,sha256=XWih3UkHsYgPIaBQ1cZ-8H2VU_URh-sSfw8fcq1hfMo,20841
7
- langroid/agent/chat_agent.py,sha256=_xsBfGBkwcHd8IRErsW7tKNz7qn0h2oKSg_BFleOPCs,39475
7
+ langroid/agent/chat_agent.py,sha256=hnmeOxdi4i5w8WaL2kPjQOEpenoRW_hG5EfeMWuuVsQ,39478
8
8
  langroid/agent/chat_document.py,sha256=uwCq53SHRyxQw6qyhjzPYuJG48VHBgOf2122Ew3fk6c,9316
9
9
  langroid/agent/helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
@@ -32,8 +32,8 @@ langroid/agent/special/sql/utils/populate_metadata.py,sha256=1J22UsyEPKzwK0XlJZt
32
32
  langroid/agent/special/sql/utils/system_message.py,sha256=qKLHkvQWRQodTtPLPxr1GSLUYUFASZU8x-ybV67cB68,1885
33
33
  langroid/agent/special/sql/utils/tools.py,sha256=6uB2424SLtmapui9ggcEr0ZTiB6_dL1-JRGgN8RK9Js,1332
34
34
  langroid/agent/special/table_chat_agent.py,sha256=d9v2wsblaRx7oMnKhLV7uO_ujvk9gh59pSGvBXyeyNc,9659
35
- langroid/agent/task.py,sha256=J4GIvbPMlL9uXKr7J-bSPHGvFK5tI2R0INgbnbFRmqk,59265
36
- langroid/agent/tool_message.py,sha256=okhIK0M2ZIGTlQF3h6UGkYk6ibH17mzm0ypDeczlWc0,9137
35
+ langroid/agent/task.py,sha256=8f65p79ID17mCT8l2F7VuldL7uEWOavLTOkX0B29sbo,59465
36
+ langroid/agent/tool_message.py,sha256=7t-UGEbykosKHAvaLI0Rm59sgxvN31IO3-P7bg7gLug,9730
37
37
  langroid/agent/tools/__init__.py,sha256=8Pc9BlGCB5FQ2IDGKS_WPpHCoWp5jblMU8EHJwwikAY,303
38
38
  langroid/agent/tools/duckduckgo_search_tool.py,sha256=NhsCaGZkdv28nja7yveAhSK_w6l_Ftym8agbrdzqgfo,1935
39
39
  langroid/agent/tools/extract_tool.py,sha256=u5lL9rKBzaLBOrRyLnTAZ97pQ1uxyLP39XsWMnpaZpw,3789
@@ -43,7 +43,7 @@ langroid/agent/tools/metaphor_search_tool.py,sha256=qj4gt453cLEX3EGW7nVzVu6X7LCd
43
43
  langroid/agent/tools/recipient_tool.py,sha256=NrLxIeQT-kbMv7AeYX0uqvGeMK4Q3fIDvG15OVzlgk8,9624
44
44
  langroid/agent/tools/retrieval_tool.py,sha256=2q2pfoYbZNfbWQ0McxrtmfF0ekGglIgRl-6uF26pa-E,871
45
45
  langroid/agent/tools/run_python_code.py,sha256=BvoxYzzHijU-p4703n2iVlt5BCieR1oMSy50w0tQZAg,1787
46
- langroid/agent/tools/segment_extract_tool.py,sha256=WOwZdTTOqKaJUDIqI0jWDV126VM1UjJzIUandHsnC-g,1320
46
+ langroid/agent/tools/segment_extract_tool.py,sha256=__srZ_VGYLVOdPrITUM8S0HpmX4q7r5FHWMDdHdEv8w,1440
47
47
  langroid/agent_config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  langroid/cachedb/__init__.py,sha256=icAT2s7Vhf-ZGUeqpDQGNU6ob6o0aFEyjwcxxUGRFjg,225
49
49
  langroid/cachedb/base.py,sha256=LKiJyOFQUN1NRzPIynfbYKGFfSanA6auDfBNEedBK7Y,1342
@@ -126,7 +126,7 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
126
126
  langroid/vector_store/momento.py,sha256=QaPzUnTwlswoawGB-paLtUPyLRvckFXLfLDfvbTzjNQ,10505
127
127
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
128
128
  langroid/vector_store/qdrantdb.py,sha256=sk5Qb2ZNbooi0rorsMuqIMokF7WADw6PJ0D6goM2XBw,16802
129
- langroid-0.1.256.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
130
- langroid-0.1.256.dist-info/METADATA,sha256=W7Daa9ruwJoQrUJqJc4g0Ios64ifd0w1LFYGHUOhuKo,51001
131
- langroid-0.1.256.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
132
- langroid-0.1.256.dist-info/RECORD,,
129
+ langroid-0.1.257.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
130
+ langroid-0.1.257.dist-info/METADATA,sha256=xLoU_XiewcfxXk98d6dG8S8dkniC4r5hVrEFgS9_h8s,51001
131
+ langroid-0.1.257.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
132
+ langroid-0.1.257.dist-info/RECORD,,