quantalogic 0.61.3__py3-none-any.whl → 0.92__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.
- quantalogic/agent.py +0 -1
- quantalogic/flow/__init__.py +16 -34
- quantalogic/main.py +11 -6
- quantalogic/tools/action_gen.py +1 -1
- quantalogic/tools/tool.py +8 -500
- quantalogic-0.92.dist-info/METADATA +448 -0
- {quantalogic-0.61.3.dist-info → quantalogic-0.92.dist-info}/RECORD +10 -33
- {quantalogic-0.61.3.dist-info → quantalogic-0.92.dist-info}/WHEEL +1 -1
- quantalogic-0.92.dist-info/entry_points.txt +3 -0
- quantalogic/codeact/__init__.py +0 -0
- quantalogic/codeact/agent.py +0 -499
- quantalogic/codeact/cli.py +0 -232
- quantalogic/codeact/constants.py +0 -9
- quantalogic/codeact/events.py +0 -78
- quantalogic/codeact/llm_util.py +0 -76
- quantalogic/codeact/prompts/error_format.j2 +0 -11
- quantalogic/codeact/prompts/generate_action.j2 +0 -26
- quantalogic/codeact/prompts/generate_program.j2 +0 -39
- quantalogic/codeact/prompts/response_format.j2 +0 -11
- quantalogic/codeact/tools_manager.py +0 -135
- quantalogic/codeact/utils.py +0 -135
- quantalogic/flow/flow.py +0 -960
- quantalogic/flow/flow_extractor.py +0 -723
- quantalogic/flow/flow_generator.py +0 -294
- quantalogic/flow/flow_manager.py +0 -637
- quantalogic/flow/flow_manager_schema.py +0 -255
- quantalogic/flow/flow_mermaid.py +0 -365
- quantalogic/flow/flow_validator.py +0 -479
- quantalogic/flow/flow_yaml.linkedin.md +0 -31
- quantalogic/flow/flow_yaml.md +0 -767
- quantalogic/flow/templates/prompt_check_inventory.j2 +0 -1
- quantalogic/flow/templates/system_check_inventory.j2 +0 -1
- quantalogic-0.61.3.dist-info/METADATA +0 -900
- quantalogic-0.61.3.dist-info/entry_points.txt +0 -6
- {quantalogic-0.61.3.dist-info → quantalogic-0.92.dist-info}/LICENSE +0 -0
quantalogic/codeact/utils.py
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
import ast
|
2
|
-
import inspect
|
3
|
-
from functools import wraps
|
4
|
-
from typing import Any, Callable, Tuple
|
5
|
-
|
6
|
-
from loguru import logger
|
7
|
-
from lxml import etree
|
8
|
-
|
9
|
-
|
10
|
-
def log_async_tool(verb: str):
|
11
|
-
"""Decorator factory for consistent async tool logging."""
|
12
|
-
def decorator(func: Callable) -> Callable:
|
13
|
-
@wraps(func)
|
14
|
-
async def wrapper(*args, **kwargs):
|
15
|
-
logger.info(f"Starting tool: {func.__name__}")
|
16
|
-
sig = inspect.signature(func)
|
17
|
-
bound_args = sig.bind(*args, **kwargs)
|
18
|
-
bound_args.apply_defaults()
|
19
|
-
logger.info(f"{verb} {', '.join(f'{k}={v}' for k, v in bound_args.arguments.items())}")
|
20
|
-
result = await func(*args, **kwargs)
|
21
|
-
logger.info(f"Finished tool: {func.__name__}")
|
22
|
-
return result
|
23
|
-
return wrapper
|
24
|
-
return decorator
|
25
|
-
|
26
|
-
|
27
|
-
def log_tool_method(func: Callable) -> Callable:
|
28
|
-
"""Decorator for logging Tool class methods."""
|
29
|
-
@wraps(func)
|
30
|
-
async def wrapper(self, **kwargs):
|
31
|
-
logger.info(f"Starting tool: {self.name}")
|
32
|
-
try:
|
33
|
-
result = await func(self, **kwargs)
|
34
|
-
logger.info(f"Finished tool: {self.name}")
|
35
|
-
return result
|
36
|
-
except Exception as e:
|
37
|
-
logger.error(f"Tool {self.name} failed: {e}")
|
38
|
-
raise
|
39
|
-
return wrapper
|
40
|
-
|
41
|
-
|
42
|
-
def validate_xml(xml_string: str) -> bool:
|
43
|
-
"""Validate XML string."""
|
44
|
-
try:
|
45
|
-
etree.fromstring(xml_string)
|
46
|
-
return True
|
47
|
-
except etree.XMLSyntaxError as e:
|
48
|
-
logger.error(f"XML validation failed: {e}")
|
49
|
-
return False
|
50
|
-
|
51
|
-
|
52
|
-
def validate_code(code: str) -> bool:
|
53
|
-
"""Check if code has an async main() function."""
|
54
|
-
try:
|
55
|
-
tree = ast.parse(code)
|
56
|
-
return any(isinstance(node, ast.AsyncFunctionDef) and node.name == "main"
|
57
|
-
for node in ast.walk(tree))
|
58
|
-
except SyntaxError:
|
59
|
-
return False
|
60
|
-
|
61
|
-
|
62
|
-
def format_xml_element(tag: str, value: Any, **attribs) -> etree.Element:
|
63
|
-
"""Create an XML element with optional CDATA and attributes."""
|
64
|
-
elem = etree.Element(tag, **attribs)
|
65
|
-
elem.text = etree.CDATA(str(value)) if value is not None else None
|
66
|
-
return elem
|
67
|
-
|
68
|
-
|
69
|
-
class XMLResultHandler:
|
70
|
-
"""Utility class for handling XML formatting and parsing."""
|
71
|
-
@staticmethod
|
72
|
-
def format_execution_result(result) -> str:
|
73
|
-
"""Format execution result as XML."""
|
74
|
-
root = etree.Element("ExecutionResult")
|
75
|
-
root.append(format_xml_element("Status", "Success" if not result.error else "Error"))
|
76
|
-
root.append(format_xml_element("Value", result.result or result.error))
|
77
|
-
root.append(format_xml_element("ExecutionTime", f"{result.execution_time:.2f} seconds"))
|
78
|
-
|
79
|
-
completed = result.result and result.result.startswith("Task completed:")
|
80
|
-
root.append(format_xml_element("Completed", str(completed).lower()))
|
81
|
-
|
82
|
-
if completed:
|
83
|
-
final_answer = result.result[len("Task completed:"):].strip()
|
84
|
-
root.append(format_xml_element("FinalAnswer", final_answer))
|
85
|
-
|
86
|
-
if result.local_variables:
|
87
|
-
vars_elem = etree.SubElement(root, "Variables")
|
88
|
-
for k, v in result.local_variables.items():
|
89
|
-
if not callable(v) and not k.startswith("__"):
|
90
|
-
vars_elem.append(format_xml_element("Variable", str(v)[:5000] +
|
91
|
-
("... (truncated)" if len(str(v)) > 5000 else ""),
|
92
|
-
name=k))
|
93
|
-
return etree.tostring(root, pretty_print=True, encoding="unicode")
|
94
|
-
|
95
|
-
@staticmethod
|
96
|
-
def format_result_summary(result_xml: str) -> str:
|
97
|
-
"""Format XML result into a readable summary."""
|
98
|
-
try:
|
99
|
-
root = etree.fromstring(result_xml)
|
100
|
-
lines = [
|
101
|
-
f"- Status: {root.findtext('Status', 'N/A')}",
|
102
|
-
f"- Value: {root.findtext('Value', 'N/A')}",
|
103
|
-
f"- Execution Time: {root.findtext('ExecutionTime', 'N/A')}",
|
104
|
-
f"- Completed: {root.findtext('Completed', 'N/A').capitalize()}"
|
105
|
-
]
|
106
|
-
if final_answer := root.findtext("FinalAnswer"):
|
107
|
-
lines.append(f"- Final Answer: {final_answer}")
|
108
|
-
|
109
|
-
if (vars_elem := root.find("Variables")) is not None:
|
110
|
-
lines.append("- Variables:")
|
111
|
-
lines.extend(f" - {var.get('name', 'unknown')}: {var.text.strip() or 'N/A'}"
|
112
|
-
for var in vars_elem.findall("Variable"))
|
113
|
-
return "\n".join(lines)
|
114
|
-
except etree.XMLSyntaxError:
|
115
|
-
logger.error(f"Failed to parse XML: {result_xml}")
|
116
|
-
return result_xml
|
117
|
-
|
118
|
-
@staticmethod
|
119
|
-
def parse_response(response: str) -> Tuple[str, str]:
|
120
|
-
"""Parse XML response to extract thought and code."""
|
121
|
-
try:
|
122
|
-
root = etree.fromstring(response)
|
123
|
-
thought = root.findtext("Thought") or ""
|
124
|
-
code = root.findtext("Code") or ""
|
125
|
-
return thought, code
|
126
|
-
except etree.XMLSyntaxError as e:
|
127
|
-
raise ValueError(f"Failed to parse XML: {e}")
|
128
|
-
|
129
|
-
@staticmethod
|
130
|
-
def extract_result_value(result: str) -> str:
|
131
|
-
"""Extract the value from the result XML."""
|
132
|
-
try:
|
133
|
-
return etree.fromstring(result).findtext("Value") or ""
|
134
|
-
except etree.XMLSyntaxError:
|
135
|
-
return ""
|