langroid 0.16.7__py3-none-any.whl → 0.17.0__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 +45 -21
- langroid/agent/chat_agent.py +22 -14
- langroid/agent/chat_document.py +22 -13
- langroid/agent/tool_message.py +11 -11
- langroid/agent/tools/file_tools.py +234 -0
- langroid/agent/xml_tool_message.py +178 -45
- langroid/utils/constants.py +2 -0
- langroid/utils/git_utils.py +251 -0
- langroid/utils/system.py +78 -0
- {langroid-0.16.7.dist-info → langroid-0.17.0.dist-info}/METADATA +6 -3
- {langroid-0.16.7.dist-info → langroid-0.17.0.dist-info}/RECORD +14 -89
- pyproject.toml +3 -2
- langroid/agent/md_tool_message_grammar.py +0 -455
- langroid/agent/tools/code_file_tool_parse.py +0 -150
- langroid/agent/tools/code_file_tool_pyparsing.py +0 -194
- langroid/agent/tools/code_file_tool_pyparsing2.py +0 -199
- langroid/agent/tools/extract_tool.py +0 -96
- langroid/agent/tools/formatted_model_custom.py +0 -150
- langroid/agent/tools/formatted_model_custom2.py +0 -168
- langroid/agent/tools/formatted_model_custom3.py +0 -279
- langroid/agent/tools/formatted_model_custom4.py +0 -395
- langroid/agent/tools/formatted_model_jinja.py +0 -133
- langroid/agent/tools/formatted_model_jinja.py-e +0 -122
- langroid/agent/tools/formatted_model_jinja2.py +0 -145
- langroid/agent/tools/formatted_model_jinja2.py-e +0 -135
- langroid/agent/tools/formatted_model_lark.py +0 -0
- langroid/agent/tools/formatted_model_lark2.py +0 -168
- langroid/agent/tools/formatted_model_parse.py +0 -105
- langroid/agent/tools/formatted_model_parse.py-e +0 -98
- langroid/agent/tools/formatted_model_parse2.py +0 -113
- langroid/agent/tools/formatted_model_parse2.py-e +0 -109
- langroid/agent/tools/formatted_model_parse3.py +0 -114
- langroid/agent/tools/formatted_model_parse3.py-e +0 -110
- langroid/agent/tools/formatted_model_parsimon.py +0 -194
- langroid/agent/tools/formatted_model_parsimon.py-e +0 -186
- langroid/agent/tools/formatted_model_pyparsing.py +0 -169
- langroid/agent/tools/formatted_model_pyparsing.py-e +0 -149
- langroid/agent/tools/formatted_model_pyparsing2.py +0 -159
- langroid/agent/tools/formatted_model_pyparsing2.py-e +0 -143
- langroid/agent/tools/formatted_model_pyparsing3.py +0 -133
- langroid/agent/tools/formatted_model_pyparsing3.py-e +0 -121
- langroid/agent/tools/formatted_model_pyparsing4.py +0 -213
- langroid/agent/tools/formatted_model_pyparsing4.py-e +0 -176
- langroid/agent/tools/formatted_model_pyparsing5.py +0 -173
- langroid/agent/tools/formatted_model_pyparsing5.py-e +0 -142
- langroid/agent/tools/formatted_model_regex.py +0 -246
- langroid/agent/tools/formatted_model_regex.py-e +0 -248
- langroid/agent/tools/formatted_model_regex2.py +0 -250
- langroid/agent/tools/formatted_model_regex2.py-e +0 -253
- langroid/agent/tools/formatted_model_tatsu.py +0 -172
- langroid/agent/tools/formatted_model_tatsu.py-e +0 -160
- langroid/agent/tools/formatted_model_template.py +0 -217
- langroid/agent/tools/formatted_model_template.py-e +0 -200
- langroid/agent/tools/formatted_model_xml.py +0 -178
- langroid/agent/tools/formatted_model_xml2.py +0 -178
- langroid/agent/tools/formatted_model_xml3.py +0 -132
- langroid/agent/tools/formatted_model_xml4.py +0 -130
- langroid/agent/tools/formatted_model_xml5.py +0 -130
- langroid/agent/tools/formatted_model_xml6.py +0 -113
- langroid/agent/tools/formatted_model_xml7.py +0 -117
- langroid/agent/tools/formatted_model_xml8.py +0 -164
- langroid/agent/tools/generator_tool.py +0 -20
- langroid/agent/tools/generic_tool.py +0 -165
- langroid/agent/tools/generic_tool_tatsu.py +0 -275
- langroid/agent/tools/grammar_based_model.py +0 -132
- langroid/agent/tools/grammar_based_model.py-e +0 -128
- langroid/agent/tools/grammar_based_model_lark.py +0 -156
- langroid/agent/tools/grammar_based_model_lark.py-e +0 -153
- langroid/agent/tools/grammar_based_model_parse.py +0 -86
- langroid/agent/tools/grammar_based_model_parse.py-e +0 -80
- langroid/agent/tools/grammar_based_model_parsimonious.py +0 -129
- langroid/agent/tools/grammar_based_model_parsimonious.py-e +0 -120
- langroid/agent/tools/grammar_based_model_pyparsing.py +0 -105
- langroid/agent/tools/grammar_based_model_pyparsing.py-e +0 -103
- langroid/agent/tools/grammar_based_model_regex.py +0 -139
- langroid/agent/tools/grammar_based_model_regex.py-e +0 -130
- langroid/agent/tools/grammar_based_model_regex2.py +0 -124
- langroid/agent/tools/grammar_based_model_regex2.py-e +0 -116
- langroid/agent/tools/grammar_based_model_tatsu.py +0 -80
- langroid/agent/tools/grammar_based_model_tatsu.py-e +0 -77
- langroid/agent/tools/lark_earley_example.py +0 -135
- langroid/agent/tools/lark_earley_example.py-e +0 -117
- langroid/agent/tools/lark_example.py +0 -72
- langroid/agent/tools/note_tool.py +0 -0
- langroid/agent/tools/parse_example.py +0 -76
- langroid/agent/tools/parse_example2.py +0 -87
- langroid/agent/tools/parse_example3.py +0 -42
- langroid/agent/tools/parse_test.py +0 -791
- langroid/agent/tools/run_python_code.py +0 -60
- {langroid-0.16.7.dist-info → langroid-0.17.0.dist-info}/LICENSE +0 -0
- {langroid-0.16.7.dist-info → langroid-0.17.0.dist-info}/WHEEL +0 -0
@@ -1,60 +0,0 @@
|
|
1
|
-
import io
|
2
|
-
import sys
|
3
|
-
from typing import List, Tuple
|
4
|
-
|
5
|
-
from langroid.agent.tool_message import ToolMessage
|
6
|
-
|
7
|
-
|
8
|
-
class RunPythonCodeTool(ToolMessage):
|
9
|
-
"""
|
10
|
-
Tool/function to run code generated by the LLM.
|
11
|
-
The code is assumed to be self-contained, i.e. it contains all necessary imports
|
12
|
-
and does not depend on any external variables.
|
13
|
-
"""
|
14
|
-
|
15
|
-
request: str = "run_python_code"
|
16
|
-
purpose: str = """
|
17
|
-
To run python <code> and return the results to answer a question.
|
18
|
-
"""
|
19
|
-
code: str
|
20
|
-
|
21
|
-
@classmethod
|
22
|
-
def examples(cls) -> List["ToolMessage" | Tuple[str, "ToolMessage"]]:
|
23
|
-
return [
|
24
|
-
cls(code="import numpy as np\nnp.square(9)"),
|
25
|
-
]
|
26
|
-
|
27
|
-
def handle(self) -> str:
|
28
|
-
"""
|
29
|
-
Handle a RunPythonCodeTool message by running the code and returning the result.
|
30
|
-
Returns:
|
31
|
-
str: The result of running the code along with any print output.
|
32
|
-
"""
|
33
|
-
code = self.code
|
34
|
-
|
35
|
-
# Create a string-based I/O stream
|
36
|
-
code_out = io.StringIO()
|
37
|
-
|
38
|
-
# Temporarily redirect standard output to our string-based I/O stream
|
39
|
-
sys.stdout = code_out
|
40
|
-
|
41
|
-
try:
|
42
|
-
eval_result = eval(code, {})
|
43
|
-
except Exception as e:
|
44
|
-
eval_result = f"ERROR: {type(e)}: {e}"
|
45
|
-
|
46
|
-
if eval_result is None:
|
47
|
-
eval_result = ""
|
48
|
-
|
49
|
-
# Always restore the original standard output
|
50
|
-
sys.stdout = sys.__stdout__
|
51
|
-
|
52
|
-
# Get the resulting string from the I/O stream
|
53
|
-
print_result = code_out.getvalue() or ""
|
54
|
-
sep = "\n" if print_result else ""
|
55
|
-
# Combine the print and eval results
|
56
|
-
result = f"{print_result}{sep}{eval_result}"
|
57
|
-
if result == "":
|
58
|
-
result = "No result"
|
59
|
-
# Return the result
|
60
|
-
return result
|
File without changes
|
File without changes
|