langroid 0.58.2__py3-none-any.whl → 0.59.0b1__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 +39 -17
- langroid/agent/base.py-e +2216 -0
- langroid/agent/callbacks/chainlit.py +2 -1
- langroid/agent/chat_agent.py +73 -55
- langroid/agent/chat_agent.py-e +2086 -0
- langroid/agent/chat_document.py +7 -7
- langroid/agent/chat_document.py-e +513 -0
- langroid/agent/openai_assistant.py +9 -9
- langroid/agent/openai_assistant.py-e +882 -0
- langroid/agent/special/arangodb/arangodb_agent.py +10 -18
- langroid/agent/special/arangodb/arangodb_agent.py-e +648 -0
- langroid/agent/special/arangodb/tools.py +3 -3
- langroid/agent/special/doc_chat_agent.py +16 -14
- langroid/agent/special/lance_rag/critic_agent.py +2 -2
- langroid/agent/special/lance_rag/query_planner_agent.py +4 -4
- langroid/agent/special/lance_tools.py +6 -5
- langroid/agent/special/lance_tools.py-e +61 -0
- langroid/agent/special/neo4j/neo4j_chat_agent.py +3 -7
- langroid/agent/special/neo4j/neo4j_chat_agent.py-e +430 -0
- langroid/agent/special/relevance_extractor_agent.py +1 -1
- langroid/agent/special/sql/sql_chat_agent.py +11 -3
- langroid/agent/task.py +9 -87
- langroid/agent/task.py-e +2418 -0
- langroid/agent/tool_message.py +33 -17
- langroid/agent/tool_message.py-e +400 -0
- langroid/agent/tools/file_tools.py +4 -2
- langroid/agent/tools/file_tools.py-e +234 -0
- langroid/agent/tools/mcp/fastmcp_client.py +19 -6
- langroid/agent/tools/mcp/fastmcp_client.py-e +584 -0
- langroid/agent/tools/orchestration.py +22 -17
- langroid/agent/tools/orchestration.py-e +301 -0
- langroid/agent/tools/recipient_tool.py +3 -3
- langroid/agent/tools/task_tool.py +22 -16
- langroid/agent/tools/task_tool.py-e +249 -0
- langroid/agent/xml_tool_message.py +90 -35
- langroid/agent/xml_tool_message.py-e +392 -0
- langroid/cachedb/base.py +1 -1
- langroid/embedding_models/base.py +2 -2
- langroid/embedding_models/models.py +3 -7
- langroid/embedding_models/models.py-e +563 -0
- langroid/exceptions.py +4 -1
- langroid/language_models/azure_openai.py +2 -2
- langroid/language_models/azure_openai.py-e +134 -0
- langroid/language_models/base.py +6 -4
- langroid/language_models/base.py-e +812 -0
- langroid/language_models/client_cache.py +64 -0
- langroid/language_models/config.py +2 -4
- langroid/language_models/config.py-e +18 -0
- langroid/language_models/model_info.py +9 -1
- langroid/language_models/model_info.py-e +483 -0
- langroid/language_models/openai_gpt.py +119 -20
- langroid/language_models/openai_gpt.py-e +2280 -0
- langroid/language_models/provider_params.py +3 -22
- langroid/language_models/provider_params.py-e +153 -0
- langroid/mytypes.py +11 -4
- langroid/mytypes.py-e +132 -0
- langroid/parsing/code_parser.py +1 -1
- langroid/parsing/file_attachment.py +1 -1
- langroid/parsing/file_attachment.py-e +246 -0
- langroid/parsing/md_parser.py +14 -4
- langroid/parsing/md_parser.py-e +574 -0
- langroid/parsing/parser.py +22 -7
- langroid/parsing/parser.py-e +410 -0
- langroid/parsing/repo_loader.py +3 -1
- langroid/parsing/repo_loader.py-e +812 -0
- langroid/parsing/search.py +1 -1
- langroid/parsing/url_loader.py +17 -51
- langroid/parsing/url_loader.py-e +683 -0
- langroid/parsing/urls.py +5 -4
- langroid/parsing/urls.py-e +279 -0
- langroid/prompts/prompts_config.py +1 -1
- langroid/pydantic_v1/__init__.py +45 -6
- langroid/pydantic_v1/__init__.py-e +36 -0
- langroid/pydantic_v1/main.py +11 -4
- langroid/pydantic_v1/main.py-e +11 -0
- langroid/utils/configuration.py +13 -11
- langroid/utils/configuration.py-e +141 -0
- langroid/utils/constants.py +1 -1
- langroid/utils/constants.py-e +32 -0
- langroid/utils/globals.py +21 -5
- langroid/utils/globals.py-e +49 -0
- langroid/utils/html_logger.py +2 -1
- langroid/utils/html_logger.py-e +825 -0
- langroid/utils/object_registry.py +1 -1
- langroid/utils/object_registry.py-e +66 -0
- langroid/utils/pydantic_utils.py +55 -28
- langroid/utils/pydantic_utils.py-e +602 -0
- langroid/utils/types.py +2 -2
- langroid/utils/types.py-e +113 -0
- langroid/vector_store/base.py +3 -3
- langroid/vector_store/lancedb.py +5 -5
- langroid/vector_store/lancedb.py-e +404 -0
- langroid/vector_store/meilisearch.py +2 -2
- langroid/vector_store/pineconedb.py +4 -4
- langroid/vector_store/pineconedb.py-e +427 -0
- langroid/vector_store/postgres.py +1 -1
- langroid/vector_store/qdrantdb.py +3 -3
- langroid/vector_store/weaviatedb.py +1 -1
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/METADATA +3 -2
- langroid-0.59.0b1.dist-info/RECORD +181 -0
- langroid/agent/special/doc_chat_task.py +0 -0
- langroid/mcp/__init__.py +0 -1
- langroid/mcp/server/__init__.py +0 -1
- langroid-0.58.2.dist-info/RECORD +0 -145
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/WHEEL +0 -0
- {langroid-0.58.2.dist-info → langroid-0.59.0b1.dist-info}/licenses/LICENSE +0 -0
langroid/agent/base.py
CHANGED
@@ -25,6 +25,8 @@ from typing import (
|
|
25
25
|
no_type_check,
|
26
26
|
)
|
27
27
|
|
28
|
+
from pydantic import Field, ValidationError, field_validator
|
29
|
+
from pydantic_settings import BaseSettings
|
28
30
|
from rich import print
|
29
31
|
from rich.console import Console
|
30
32
|
from rich.markup import escape
|
@@ -51,12 +53,6 @@ from langroid.parsing.file_attachment import FileAttachment
|
|
51
53
|
from langroid.parsing.parse_json import extract_top_level_json
|
52
54
|
from langroid.parsing.parser import Parser, ParsingConfig
|
53
55
|
from langroid.prompts.prompts_config import PromptsConfig
|
54
|
-
from langroid.pydantic_v1 import (
|
55
|
-
BaseSettings,
|
56
|
-
Field,
|
57
|
-
ValidationError,
|
58
|
-
validator,
|
59
|
-
)
|
60
56
|
from langroid.utils.configuration import settings
|
61
57
|
from langroid.utils.constants import (
|
62
58
|
DONE,
|
@@ -100,7 +96,8 @@ class AgentConfig(BaseSettings):
|
|
100
96
|
"Human (respond or q, x to exit current level, " "or hit enter to continue)"
|
101
97
|
)
|
102
98
|
|
103
|
-
@
|
99
|
+
@field_validator("name")
|
100
|
+
@classmethod
|
104
101
|
def check_name_alphanum(cls, v: str) -> str:
|
105
102
|
if not re.match(r"^[a-zA-Z0-9_-]+$", v):
|
106
103
|
raise ValueError(
|
@@ -1450,7 +1447,12 @@ class Agent(ABC):
|
|
1450
1447
|
return None
|
1451
1448
|
tool_class = self.llm_tools_map[tool_name]
|
1452
1449
|
tool_msg.update(dict(request=tool_name))
|
1453
|
-
|
1450
|
+
try:
|
1451
|
+
tool = tool_class.model_validate(tool_msg)
|
1452
|
+
except ValidationError as ve:
|
1453
|
+
# Store tool class as an attribute on the exception
|
1454
|
+
ve.tool_class = tool_class # type: ignore
|
1455
|
+
raise ve
|
1454
1456
|
return tool
|
1455
1457
|
|
1456
1458
|
def get_oai_tool_calls_classes(self, msg: ChatDocument) -> List[ToolMessage]:
|
@@ -1483,7 +1485,12 @@ class Agent(ABC):
|
|
1483
1485
|
all_errors = False
|
1484
1486
|
tool_class = self.llm_tools_map[tool_name]
|
1485
1487
|
tool_msg.update(dict(request=tool_name))
|
1486
|
-
|
1488
|
+
try:
|
1489
|
+
tool = tool_class.model_validate(tool_msg)
|
1490
|
+
except ValidationError as ve:
|
1491
|
+
# Store tool class as an attribute on the exception
|
1492
|
+
ve.tool_class = tool_class # type: ignore
|
1493
|
+
raise ve
|
1487
1494
|
tool.id = tc.id or ""
|
1488
1495
|
tools.append(tool)
|
1489
1496
|
# When no tool is valid and the message was produced
|
@@ -1491,18 +1498,28 @@ class Agent(ABC):
|
|
1491
1498
|
self.tool_error = all_errors and msg.metadata.sender == Entity.LLM
|
1492
1499
|
return tools
|
1493
1500
|
|
1494
|
-
def tool_validation_error(
|
1501
|
+
def tool_validation_error(
|
1502
|
+
self, ve: ValidationError, tool_class: Optional[Type[ToolMessage]] = None
|
1503
|
+
) -> str:
|
1495
1504
|
"""
|
1496
1505
|
Handle a validation error raised when parsing a tool message,
|
1497
1506
|
when there is a legit tool name used, but it has missing/bad fields.
|
1498
1507
|
Args:
|
1499
|
-
tool (ToolMessage): The tool message that failed validation
|
1500
1508
|
ve (ValidationError): The exception raised
|
1509
|
+
tool_class (Optional[Type[ToolMessage]]): The tool class that
|
1510
|
+
failed validation
|
1501
1511
|
|
1502
1512
|
Returns:
|
1503
1513
|
str: The error message to send back to the LLM
|
1504
1514
|
"""
|
1505
|
-
|
1515
|
+
# First try to get tool class from the exception itself
|
1516
|
+
if hasattr(ve, "tool_class") and ve.tool_class:
|
1517
|
+
tool_name = ve.tool_class.default_value("request") # type: ignore
|
1518
|
+
elif tool_class is not None:
|
1519
|
+
tool_name = tool_class.default_value("request")
|
1520
|
+
else:
|
1521
|
+
# Fallback: try to extract from error context if available
|
1522
|
+
tool_name = "Unknown Tool"
|
1506
1523
|
bad_field_errors = "\n".join(
|
1507
1524
|
[f"{e['loc']}: {e['msg']}" for e in ve.errors() if "loc" in e]
|
1508
1525
|
)
|
@@ -1778,11 +1795,11 @@ class Agent(ABC):
|
|
1778
1795
|
)
|
1779
1796
|
possible = [self.llm_tools_map[r] for r in allowable]
|
1780
1797
|
|
1781
|
-
default_keys = set(ToolMessage.
|
1798
|
+
default_keys = set(ToolMessage.model_fields.keys())
|
1782
1799
|
request_keys = set(maybe_tool_dict.keys())
|
1783
1800
|
|
1784
1801
|
def maybe_parse(tool: type[ToolMessage]) -> Optional[ToolMessage]:
|
1785
|
-
all_keys = set(tool.
|
1802
|
+
all_keys = set(tool.model_fields.keys())
|
1786
1803
|
non_inherited_keys = all_keys.difference(default_keys)
|
1787
1804
|
# If the request has any keys not valid for the tool and
|
1788
1805
|
# does not specify some key specific to the type
|
@@ -1794,7 +1811,7 @@ class Agent(ABC):
|
|
1794
1811
|
return None
|
1795
1812
|
|
1796
1813
|
try:
|
1797
|
-
return tool.
|
1814
|
+
return tool.model_validate(maybe_tool_dict)
|
1798
1815
|
except ValidationError:
|
1799
1816
|
return None
|
1800
1817
|
|
@@ -1824,9 +1841,11 @@ class Agent(ABC):
|
|
1824
1841
|
return None
|
1825
1842
|
|
1826
1843
|
try:
|
1827
|
-
message = message_class.
|
1844
|
+
message = message_class.model_validate(maybe_tool_dict)
|
1828
1845
|
except ValidationError as ve:
|
1829
1846
|
self.tool_error = from_llm
|
1847
|
+
# Store tool class as an attribute on the exception
|
1848
|
+
ve.tool_class = message_class # type: ignore
|
1830
1849
|
raise ve
|
1831
1850
|
return message
|
1832
1851
|
|
@@ -1940,11 +1959,14 @@ class Agent(ABC):
|
|
1940
1959
|
return None
|
1941
1960
|
|
1942
1961
|
def _maybe_truncate_result(
|
1943
|
-
self,
|
1962
|
+
self,
|
1963
|
+
result: str | ChatDocument | None,
|
1964
|
+
max_tokens: int | None,
|
1944
1965
|
) -> str | ChatDocument | None:
|
1945
1966
|
"""
|
1946
1967
|
Truncate the result string to `max_tokens` tokens.
|
1947
1968
|
"""
|
1969
|
+
|
1948
1970
|
if result is None or max_tokens is None:
|
1949
1971
|
return result
|
1950
1972
|
result_str = result.content if isinstance(result, ChatDocument) else result
|