langroid 0.2.5__py3-none-any.whl → 0.2.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/task.py CHANGED
@@ -41,7 +41,6 @@ from langroid.parsing.routing import parse_addressed_message
41
41
  from langroid.pydantic_v1 import BaseModel
42
42
  from langroid.utils.configuration import settings
43
43
  from langroid.utils.constants import (
44
- AT, # regex for start of an addressed recipient e.g. "@"
45
44
  DONE,
46
45
  NO_ANSWER,
47
46
  PASS,
@@ -74,6 +73,18 @@ class TaskConfig(BaseModel):
74
73
  inf_loop_wait_factor (int): wait this * cycle_len msgs before loop-check
75
74
  restart_subtask_run (bool): whether to restart *every* run of this task
76
75
  when run as a subtask.
76
+ addressing_prefix (str): prefix an agent can use to address other
77
+ agents, or entities of the agent. E.g., if this is "@", the addressing
78
+ string would be "@Alice", or "@user", "@llm", "@agent", etc.
79
+ If this is an empty string, then addressing is disabled.
80
+ Default is empty string "".
81
+ CAUTION: this is a deprecated practice, since normal prompts
82
+ can accidentally contain such addressing prefixes, and will break
83
+ your runs. This could happen especially when your prompt/context
84
+ contains code, but of course could occur in normal text as well.
85
+ Instead, use the `RecipientTool` to have agents address other agents or
86
+ entities. If you do choose to use `addressing_prefix`, the recommended
87
+ setting is to use `langroid.utils.constants.AT`, which currently is "|@|".
77
88
  """
78
89
 
79
90
  inf_loop_cycle_len: int = 10
@@ -81,6 +92,7 @@ class TaskConfig(BaseModel):
81
92
  inf_loop_wait_factor: int = 5
82
93
  restart_as_subtask: bool = False
83
94
  logs_dir: str = "logs"
95
+ addressing_prefix: str = ""
84
96
 
85
97
 
86
98
  class Task:
@@ -1190,7 +1202,10 @@ class Task:
1190
1202
  if result is None:
1191
1203
  return None
1192
1204
  # if result content starts with @name, set recipient to name
1193
- is_pass, recipient, content = parse_routing(result)
1205
+ is_pass, recipient, content = parse_routing(
1206
+ result,
1207
+ addressing_prefix=self.config.addressing_prefix,
1208
+ )
1194
1209
  if is_pass is None: # no routing, i.e. neither PASS nor SEND
1195
1210
  return result
1196
1211
  if is_pass:
@@ -1648,6 +1663,7 @@ class Task:
1648
1663
 
1649
1664
  def parse_routing(
1650
1665
  msg: ChatDocument | str,
1666
+ addressing_prefix: str = "",
1651
1667
  ) -> Tuple[bool | None, str | None, str | None]:
1652
1668
  """
1653
1669
  Parse routing instruction if any, of the form:
@@ -1656,6 +1672,8 @@ def parse_routing(
1656
1672
  @<recipient> <content> (send content to recipient)
1657
1673
  Args:
1658
1674
  msg (ChatDocument|str|None): message to parse
1675
+ addressing_prefix (str): prefix to address other agents or entities,
1676
+ (e.g. "@". See documentation of `TaskConfig` for details).
1659
1677
  Returns:
1660
1678
  Tuple[bool|None, str|None, str|None]:
1661
1679
  bool: true=PASS, false=SEND, or None if neither
@@ -1682,8 +1700,12 @@ def parse_routing(
1682
1700
  else:
1683
1701
  return False, addressee, content_to_send
1684
1702
  if (
1685
- AT in content
1686
- and (addressee_content := parse_addressed_message(content, AT))[0] is not None
1703
+ addressing_prefix != ""
1704
+ and addressing_prefix in content
1705
+ and (addressee_content := parse_addressed_message(content, addressing_prefix))[
1706
+ 0
1707
+ ]
1708
+ is not None
1687
1709
  ):
1688
1710
  (addressee, content_to_send) = addressee_content
1689
1711
  # if no content then treat same as PASS_TO
File without changes
langroid/mytypes.py CHANGED
@@ -22,11 +22,17 @@ class Entity(str, Enum):
22
22
  SYSTEM = "System"
23
23
 
24
24
  def __eq__(self, other: object) -> bool:
25
- """Allow case-insensitive comparison with strings."""
25
+ """Allow case-insensitive equality (==) comparison with strings."""
26
+ if other is None:
27
+ return False
26
28
  if isinstance(other, str):
27
29
  return self.value.lower() == other.lower()
28
30
  return super().__eq__(other)
29
31
 
32
+ def __ne__(self, other: object) -> bool:
33
+ """Allow case-insensitive non-equality (!=) comparison with strings."""
34
+ return not self.__eq__(other)
35
+
30
36
  def __hash__(self) -> int:
31
37
  """Override this to ensure hashability of the enum,
32
38
  so it can be used sets and dictionary keys.
@@ -18,6 +18,11 @@ DONE = "DONE"
18
18
  USER_QUIT_STRINGS = ["q", "x", "quit", "exit", "bye", DONE]
19
19
  PASS = "__PASS__"
20
20
  PASS_TO = PASS + ":"
21
- SEND_TO = "SEND:"
21
+ SEND_TO = "__SEND__:"
22
22
  TOOL = "TOOL"
23
- AT = "@"
23
+ # This is a recommended setting for TaskConfig.addressing_prefix if using it at all;
24
+ # prefer to use `RecipientTool` to allow agents addressing others.
25
+ # Caution the AT string should NOT contain any 'word' characters, i.e.
26
+ # it no letters, digits or underscores.
27
+ # See tests/main/test_msg_routing for example usage
28
+ AT = "|@|"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -150,7 +150,7 @@ This Multi-Agent paradigm is inspired by the
150
150
  `Langroid` is a fresh take on LLM app-development, where considerable thought has gone
151
151
  into simplifying the developer experience; it does not use `Langchain`.
152
152
 
153
- Companies are using/adapting Langroid in production. Here is a quote from one of them:
153
+ 📢 Companies are using/adapting Langroid in **production**. Here is a quote:
154
154
 
155
155
  >[Nullify](https://www.nullify.ai) uses AI Agents for secure software development.
156
156
  > It finds, prioritizes and fixes vulnerabilities. We have internally adapted Langroid's multi-agent orchestration framework in production, after evaluating CrewAI, Autogen, LangChain, Langflow, etc. We found Langroid to be far superior to those frameworks in terms of ease of setup and flexibility. Langroid's Agent and Task abstractions are intuitive, well thought out, and provide a great developer experience. We wanted the quickest way to get something in production. With other frameworks it would have taken us weeks, but with Langroid we got to good results in minutes. Highly recommended! <br> -- Jacky Wong, Head of AI at Nullify.
@@ -461,17 +461,17 @@ such as [ollama](https://github.com/ollama), [oobabooga](https://github.com/ooba
461
461
  - **Observability, Logging, Lineage:** Langroid generates detailed logs of multi-agent interactions and
462
462
  maintains provenance/lineage of messages, so that you can trace back
463
463
  the origin of a message.
464
- - **[Tools/Plugins/Function-calling](https://langroid.github.io/langroid/quick-start/chat-agent-tool/)**: Langroid supports OpenAI's recently
465
- released [function calling](https://platform.openai.com/docs/guides/gpt/function-calling)
466
- feature. In addition, Langroid has its own native equivalent, which we
467
- call **tools** (also known as "plugins" in other contexts). Function
468
- calling and tools have the same developer-facing interface, implemented
464
+ - **[Tools/Plugins/Function-calling](https://langroid.github.io/langroid/quick-start/chat-agent-tool/)**:
465
+ Langroid supports OpenAI's [function calling](https://platform.openai.com/docs/guides/gpt/function-calling), as
466
+ well as an equivalent `ToolMessage` mechanism which works with
467
+ any LLM, not just OpenAI's.
468
+ Function calling and tools have the same developer-facing interface, implemented
469
469
  using [Pydantic](https://docs.pydantic.dev/latest/),
470
470
  which makes it very easy to define tools/functions and enable agents
471
471
  to use them. Benefits of using Pydantic are that you never have to write
472
472
  complex JSON specs for function calling, and when the LLM
473
473
  hallucinates malformed JSON, the Pydantic error message is sent back to
474
- the LLM so it can fix it!
474
+ the LLM so it can fix it.
475
475
 
476
476
  ---
477
477
 
@@ -32,7 +32,7 @@ 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=vFYysk6Vi7HJjII8B4RitA3pt_z3gkSglDNdhNVMiFc,1332
34
34
  langroid/agent/special/table_chat_agent.py,sha256=d9v2wsblaRx7oMnKhLV7uO_ujvk9gh59pSGvBXyeyNc,9659
35
- langroid/agent/task.py,sha256=SDDIGE4heOq5v-FeFXnRwQZg2kmayz1xxkSVHbVYWXE,72421
35
+ langroid/agent/task.py,sha256=1ujx4-SN3_-3xE0Z3r0lC-6LYYa4G-0lblg5cZWchBQ,73651
36
36
  langroid/agent/tool_message.py,sha256=wIyZnUcZpxkiRPvM9O3MO3b5BBAdLEEan9kqPbvtApc,9743
37
37
  langroid/agent/tools/__init__.py,sha256=e-63cfwQNk_ftRKQwgDAJQK16QLbRVWDBILeXIc7wLk,402
38
38
  langroid/agent/tools/duckduckgo_search_tool.py,sha256=NhsCaGZkdv28nja7yveAhSK_w6l_Ftym8agbrdzqgfo,1935
@@ -40,6 +40,7 @@ langroid/agent/tools/extract_tool.py,sha256=u5lL9rKBzaLBOrRyLnTAZ97pQ1uxyLP39XsW
40
40
  langroid/agent/tools/generator_tool.py,sha256=y0fB0ZObjA0b3L0uSTtrqRCKHDUR95arBftqiUeKD2o,663
41
41
  langroid/agent/tools/google_search_tool.py,sha256=y7b-3FtgXf0lfF4AYxrZ3K5pH2dhidvibUOAGBE--WI,1456
42
42
  langroid/agent/tools/metaphor_search_tool.py,sha256=qj4gt453cLEX3EGW7nVzVu6X7LCdrwjSlcNY0qJW104,2489
43
+ langroid/agent/tools/note_tool.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
44
  langroid/agent/tools/recipient_tool.py,sha256=NrLxIeQT-kbMv7AeYX0uqvGeMK4Q3fIDvG15OVzlgk8,9624
44
45
  langroid/agent/tools/retrieval_tool.py,sha256=2q2pfoYbZNfbWQ0McxrtmfF0ekGglIgRl-6uF26pa-E,871
45
46
  langroid/agent/tools/rewind_tool.py,sha256=G4DiXuOt2nQ2fU7qvtJMdLyyf-rK7RZwLsFxsAUfk-Y,5606
@@ -72,7 +73,7 @@ langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6c
72
73
  langroid/language_models/prompt_formatter/hf_formatter.py,sha256=TFL6ppmeQWnzr6CKQzRZFYY810zE1mr8DZnhw6i85ok,5217
73
74
  langroid/language_models/prompt_formatter/llama2_formatter.py,sha256=YdcO88qyBeuMENVIVvVqSYuEpvYSTndUe_jd6hVTko4,2899
74
75
  langroid/language_models/utils.py,sha256=o6Zo2cnnvKrfSgF26knVQ1xkSxEoE7yN85296gNdVOw,4858
75
- langroid/mytypes.py,sha256=YjlunP4n_-J3wDNQM4MBtLyOuaa1qJJpwzVfvn0Ca1A,2206
76
+ langroid/mytypes.py,sha256=KRN_dBamplSl3SYekosT_Maj6ZA749LONypaqPVnmbI,2435
76
77
  langroid/parsing/__init__.py,sha256=ZgSAfgTC6VsTLFlRSWT-TwYco7SQeRMeZG-49MnKYGY,936
77
78
  langroid/parsing/agent_chats.py,sha256=sbZRV9ujdM5QXvvuHVjIi2ysYSYlap-uqfMMUKulrW0,1068
78
79
  langroid/parsing/code-parsing.md,sha256=--cyyNiSZSDlIwcjAV4-shKrSiRe2ytF3AdSoS_hD2g,3294
@@ -104,7 +105,7 @@ langroid/utils/__init__.py,sha256=Sruos2tB4G7Tn0vlblvYlX9PEGR0plI2uE0PJ4d_EC4,35
104
105
  langroid/utils/algorithms/__init__.py,sha256=WylYoZymA0fnzpB4vrsH_0n7WsoLhmuZq8qxsOCjUpM,41
105
106
  langroid/utils/algorithms/graph.py,sha256=JbdpPnUOhw4-D6O7ou101JLA3xPCD0Lr3qaPoFCaRfo,2866
106
107
  langroid/utils/configuration.py,sha256=A70LdvdMuunlLSGI1gBmBL5j6Jhz-1syNP8R4AdjqDc,3295
107
- langroid/utils/constants.py,sha256=5WgyXjhRegNWB_BSYZsEZW-7mm-F_5bJPM4nuZ9qvNo,590
108
+ langroid/utils/constants.py,sha256=w3eBQ5Q2HjxMBN_y1UarK0keREqCwXSxQXizMafsG-M,911
108
109
  langroid/utils/docker.py,sha256=kJQOLTgM0x9j9pgIIqp0dZNZCTvoUDhp6i8tYBq1Jr0,1105
109
110
  langroid/utils/globals.py,sha256=Az9dOFqR6n9CoTYSqa2kLikQWS0oCQ9DFQIQAnG-2q8,1355
110
111
  langroid/utils/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -128,8 +129,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
128
129
  langroid/vector_store/momento.py,sha256=QaPzUnTwlswoawGB-paLtUPyLRvckFXLfLDfvbTzjNQ,10505
129
130
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
130
131
  langroid/vector_store/qdrantdb.py,sha256=wYOuu5c2vIKn9ZgvTXcAiZXMpV8AOXEWFAzI8S8UP-0,16828
131
- pyproject.toml,sha256=Z8rxMBrFYpYvURHB8jbQ7EgUfYjULvNK9EN2jR_oZL0,6957
132
- langroid-0.2.5.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
133
- langroid-0.2.5.dist-info/METADATA,sha256=jCXWx9FIzzo3Ev3Y2TiCtkvocMH1lwXjnR4lxgkqBW4,54012
134
- langroid-0.2.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
135
- langroid-0.2.5.dist-info/RECORD,,
132
+ pyproject.toml,sha256=QRWcQbtqFx0WvwrEVlpHvz0sqaXYaWplEfARV_RiN-0,6957
133
+ langroid-0.2.6.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
134
+ langroid-0.2.6.dist-info/METADATA,sha256=zKW_qJFbNttbgLTicYyef_8RONS-C38OSJYGISr38Xw,53950
135
+ langroid-0.2.6.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
136
+ langroid-0.2.6.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.2.5"
3
+ version = "0.2.6"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"