agently 4.0.6.7__py3-none-any.whl → 4.0.6.9__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.
- agently/builtins/agent_extensions/ConfigurePromptExtension.py +2 -0
- agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py +58 -1
- agently/core/Agent.py +52 -23
- agently/core/ModelRequest.py +169 -16
- agently/core/Prompt.py +8 -0
- agently/types/plugins/PromptGenerator.py +5 -1
- {agently-4.0.6.7.dist-info → agently-4.0.6.9.dist-info}/METADATA +1 -1
- {agently-4.0.6.7.dist-info → agently-4.0.6.9.dist-info}/RECORD +10 -10
- {agently-4.0.6.7.dist-info → agently-4.0.6.9.dist-info}/WHEEL +0 -0
- {agently-4.0.6.7.dist-info → agently-4.0.6.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -188,6 +188,7 @@ class ConfigurePromptExtension(BaseAgent):
|
|
|
188
188
|
"Cannot execute YAML prompt configures, expect prompt configures as a dictionary data but got:"
|
|
189
189
|
f"{ prompt }"
|
|
190
190
|
)
|
|
191
|
+
return self
|
|
191
192
|
|
|
192
193
|
def load_json_prompt(self, path_or_content: str, mappings: dict[str, Any] | None = None):
|
|
193
194
|
path = Path(path_or_content)
|
|
@@ -209,3 +210,4 @@ class ConfigurePromptExtension(BaseAgent):
|
|
|
209
210
|
"Cannot execute JSON prompt configures, expect prompt configures as a dictionary data but got:"
|
|
210
211
|
f"{ prompt }"
|
|
211
212
|
)
|
|
213
|
+
return self
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
import json
|
|
15
16
|
import yaml
|
|
16
17
|
|
|
17
18
|
from typing import (
|
|
@@ -38,6 +39,7 @@ from agently.utils import SettingsNamespace, DataFormatter
|
|
|
38
39
|
|
|
39
40
|
if TYPE_CHECKING:
|
|
40
41
|
from pydantic import BaseModel
|
|
42
|
+
from agently.types.data import SerializableData
|
|
41
43
|
from agently.core import Prompt
|
|
42
44
|
from agently.utils import Settings
|
|
43
45
|
|
|
@@ -649,7 +651,12 @@ class AgentlyPromptGenerator(PromptGenerator):
|
|
|
649
651
|
}
|
|
650
652
|
)
|
|
651
653
|
|
|
652
|
-
return create_model(
|
|
654
|
+
return create_model(
|
|
655
|
+
name,
|
|
656
|
+
__config__={'extra': 'allow'},
|
|
657
|
+
**fields,
|
|
658
|
+
**validators,
|
|
659
|
+
)
|
|
653
660
|
else:
|
|
654
661
|
item_type = Any
|
|
655
662
|
if len(schema) > 0:
|
|
@@ -698,3 +705,53 @@ class AgentlyPromptGenerator(PromptGenerator):
|
|
|
698
705
|
"AgentlyOutput",
|
|
699
706
|
{"list": DataFormatter.sanitize(output_prompt, remain_type=True)},
|
|
700
707
|
)
|
|
708
|
+
|
|
709
|
+
def _to_serializable_output_prompt(self, output_prompt_part: Any):
|
|
710
|
+
if not isinstance(output_prompt_part, (Mapping, Sequence)) or isinstance(output_prompt_part, str):
|
|
711
|
+
return output_prompt_part
|
|
712
|
+
|
|
713
|
+
if isinstance(output_prompt_part, Mapping):
|
|
714
|
+
result = {}
|
|
715
|
+
for key, value in output_prompt_part.items():
|
|
716
|
+
result[key] = self._to_serializable_output_prompt(value)
|
|
717
|
+
return result
|
|
718
|
+
else:
|
|
719
|
+
if isinstance(output_prompt_part, tuple):
|
|
720
|
+
match len(output_prompt_part):
|
|
721
|
+
case 0:
|
|
722
|
+
return []
|
|
723
|
+
case 1:
|
|
724
|
+
return {
|
|
725
|
+
"$type": output_prompt_part[0],
|
|
726
|
+
}
|
|
727
|
+
case _:
|
|
728
|
+
return {
|
|
729
|
+
"$type": output_prompt_part[0],
|
|
730
|
+
"$desc": ";".join(output_prompt_part[1:]),
|
|
731
|
+
}
|
|
732
|
+
else:
|
|
733
|
+
return list(output_prompt_part)
|
|
734
|
+
|
|
735
|
+
def to_serializable_prompt_data(self, inherit: bool = False) -> "SerializableData":
|
|
736
|
+
prompt_data = self.prompt.get(
|
|
737
|
+
default={},
|
|
738
|
+
inherit=inherit,
|
|
739
|
+
)
|
|
740
|
+
if "output" in prompt_data:
|
|
741
|
+
prompt_data["output"] = self._to_serializable_output_prompt(prompt_data["output"])
|
|
742
|
+
return DataFormatter.sanitize(prompt_data)
|
|
743
|
+
|
|
744
|
+
def to_json_prompt(self, inherit: bool = False):
|
|
745
|
+
return json.dumps(
|
|
746
|
+
self.to_serializable_prompt_data(inherit),
|
|
747
|
+
indent=2,
|
|
748
|
+
ensure_ascii=False,
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
def to_yaml_prompt(self, inherit: bool = False):
|
|
752
|
+
return yaml.safe_dump(
|
|
753
|
+
self.to_serializable_prompt_data(inherit),
|
|
754
|
+
indent=2,
|
|
755
|
+
allow_unicode=True,
|
|
756
|
+
sort_keys=False,
|
|
757
|
+
)
|
agently/core/Agent.py
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import uuid
|
|
16
|
+
import yaml
|
|
17
|
+
import json
|
|
16
18
|
|
|
17
19
|
from typing import Any, TYPE_CHECKING
|
|
18
20
|
|
|
@@ -91,7 +93,7 @@ class BaseAgent:
|
|
|
91
93
|
value: Any,
|
|
92
94
|
mappings: dict[str, Any] | None = None,
|
|
93
95
|
):
|
|
94
|
-
self.
|
|
96
|
+
self.agent_prompt.set(key, value, mappings)
|
|
95
97
|
return self
|
|
96
98
|
|
|
97
99
|
def set_request_prompt(
|
|
@@ -104,7 +106,7 @@ class BaseAgent:
|
|
|
104
106
|
return self
|
|
105
107
|
|
|
106
108
|
def remove_agent_prompt(self, key: "PromptStandardSlot | str"):
|
|
107
|
-
self.
|
|
109
|
+
self.agent_prompt.set(key, None)
|
|
108
110
|
return self
|
|
109
111
|
|
|
110
112
|
def remove_request_prompt(self, key: "PromptStandardSlot | str"):
|
|
@@ -112,34 +114,34 @@ class BaseAgent:
|
|
|
112
114
|
return self
|
|
113
115
|
|
|
114
116
|
def reset_chat_history(self):
|
|
115
|
-
if "chat_history" in self.
|
|
116
|
-
self.
|
|
117
|
+
if "chat_history" in self.agent_prompt:
|
|
118
|
+
self.agent_prompt.set("chat_history", [])
|
|
117
119
|
return self
|
|
118
120
|
|
|
119
121
|
def set_chat_history(self, chat_history: "list[dict[str, Any] | ChatMessage]"):
|
|
120
122
|
self.reset_chat_history()
|
|
121
123
|
if not isinstance(chat_history, list):
|
|
122
124
|
chat_history = [chat_history]
|
|
123
|
-
self.
|
|
125
|
+
self.agent_prompt.set("chat_history", chat_history)
|
|
124
126
|
return self
|
|
125
127
|
|
|
126
128
|
def add_chat_history(self, chat_history: "list[dict[str, Any] | ChatMessage] | dict[str, Any] | ChatMessage"):
|
|
127
129
|
if not isinstance(chat_history, list):
|
|
128
130
|
chat_history = [chat_history]
|
|
129
|
-
self.
|
|
131
|
+
self.agent_prompt.set("chat_history", chat_history)
|
|
130
132
|
return self
|
|
131
133
|
|
|
132
134
|
def reset_action_results(self):
|
|
133
|
-
if "action_results" in self.
|
|
134
|
-
del self.
|
|
135
|
+
if "action_results" in self.agent_prompt:
|
|
136
|
+
del self.agent_prompt["action_results"]
|
|
135
137
|
return self
|
|
136
138
|
|
|
137
139
|
def set_action_results(self, action_results: list[dict[str, Any]]):
|
|
138
|
-
self.
|
|
140
|
+
self.agent_prompt.set("action_results", action_results)
|
|
139
141
|
return self
|
|
140
142
|
|
|
141
143
|
def add_action_results(self, action: str, result: Any):
|
|
142
|
-
self.
|
|
144
|
+
self.agent_prompt.append("action_results", {action: result})
|
|
143
145
|
return self
|
|
144
146
|
|
|
145
147
|
# Quick Prompt
|
|
@@ -151,7 +153,7 @@ class BaseAgent:
|
|
|
151
153
|
always: bool = False,
|
|
152
154
|
):
|
|
153
155
|
if always:
|
|
154
|
-
self.
|
|
156
|
+
self.agent_prompt.set("input", prompt, mappings)
|
|
155
157
|
else:
|
|
156
158
|
self.request.prompt.set("input", prompt, mappings)
|
|
157
159
|
return self
|
|
@@ -164,8 +166,8 @@ class BaseAgent:
|
|
|
164
166
|
always: bool = False,
|
|
165
167
|
):
|
|
166
168
|
if always:
|
|
167
|
-
self.
|
|
168
|
-
self.
|
|
169
|
+
self.agent_prompt.set("instruct", ["{system.rule} ARE IMPORTANT RULES YOU SHALL FOLLOW!"])
|
|
170
|
+
self.agent_prompt.set("system.rule", prompt, mappings)
|
|
169
171
|
else:
|
|
170
172
|
self.request.prompt.set("instruct", ["{system.rule} ARE IMPORTANT RULES YOU SHALL FOLLOW!"])
|
|
171
173
|
self.request.prompt.set("system.rule", prompt, mappings)
|
|
@@ -179,8 +181,8 @@ class BaseAgent:
|
|
|
179
181
|
always: bool = False,
|
|
180
182
|
):
|
|
181
183
|
if always:
|
|
182
|
-
self.
|
|
183
|
-
self.
|
|
184
|
+
self.agent_prompt.set("instruct", ["YOU MUST REACT AND RESPOND AS {system.role}!"])
|
|
185
|
+
self.agent_prompt.set("system.your_role", prompt, mappings)
|
|
184
186
|
else:
|
|
185
187
|
self.request.prompt.set("instruct", ["YOU MUST REACT AND RESPOND AS {system.role}!"])
|
|
186
188
|
self.request.prompt.set("system.your_role", prompt, mappings)
|
|
@@ -194,8 +196,8 @@ class BaseAgent:
|
|
|
194
196
|
always: bool = False,
|
|
195
197
|
):
|
|
196
198
|
if always:
|
|
197
|
-
self.
|
|
198
|
-
self.
|
|
199
|
+
self.agent_prompt.set("instruct", ["{system.user_info} IS IMPORTANT INFORMATION ABOUT USER!"])
|
|
200
|
+
self.agent_prompt.set("system.user_info", prompt, mappings)
|
|
199
201
|
else:
|
|
200
202
|
self.request.prompt.set("instruct", ["{system.user_info} IS IMPORTANT INFORMATION ABOUT USER!"])
|
|
201
203
|
self.request.prompt.set("system.user_info", prompt, mappings)
|
|
@@ -209,7 +211,7 @@ class BaseAgent:
|
|
|
209
211
|
always: bool = False,
|
|
210
212
|
):
|
|
211
213
|
if always:
|
|
212
|
-
self.
|
|
214
|
+
self.agent_prompt.set("input", prompt, mappings)
|
|
213
215
|
else:
|
|
214
216
|
self.request.prompt.set("input", prompt, mappings)
|
|
215
217
|
return self
|
|
@@ -222,7 +224,7 @@ class BaseAgent:
|
|
|
222
224
|
always: bool = False,
|
|
223
225
|
):
|
|
224
226
|
if always:
|
|
225
|
-
self.
|
|
227
|
+
self.agent_prompt.set("info", prompt, mappings)
|
|
226
228
|
else:
|
|
227
229
|
self.request.prompt.set("info", prompt, mappings)
|
|
228
230
|
return self
|
|
@@ -235,7 +237,7 @@ class BaseAgent:
|
|
|
235
237
|
always: bool = False,
|
|
236
238
|
):
|
|
237
239
|
if always:
|
|
238
|
-
self.
|
|
240
|
+
self.agent_prompt.set("instruct", prompt, mappings)
|
|
239
241
|
else:
|
|
240
242
|
self.request.prompt.set("instruct", prompt, mappings)
|
|
241
243
|
return self
|
|
@@ -248,7 +250,7 @@ class BaseAgent:
|
|
|
248
250
|
always: bool = False,
|
|
249
251
|
):
|
|
250
252
|
if always:
|
|
251
|
-
self.
|
|
253
|
+
self.agent_prompt.set("examples", prompt, mappings)
|
|
252
254
|
else:
|
|
253
255
|
self.request.prompt.set("examples", prompt, mappings)
|
|
254
256
|
return self
|
|
@@ -266,7 +268,7 @@ class BaseAgent:
|
|
|
266
268
|
always: bool = False,
|
|
267
269
|
):
|
|
268
270
|
if always:
|
|
269
|
-
self.
|
|
271
|
+
self.agent_prompt.set("output", prompt, mappings)
|
|
270
272
|
else:
|
|
271
273
|
self.request.prompt.set("output", prompt, mappings)
|
|
272
274
|
return self
|
|
@@ -278,7 +280,34 @@ class BaseAgent:
|
|
|
278
280
|
always: bool = False,
|
|
279
281
|
):
|
|
280
282
|
if always:
|
|
281
|
-
self.
|
|
283
|
+
self.agent_prompt.set("options", options)
|
|
282
284
|
else:
|
|
283
285
|
self.request.prompt.set("options", options)
|
|
284
286
|
return self
|
|
287
|
+
|
|
288
|
+
# Prompt
|
|
289
|
+
def get_prompt_text(self):
|
|
290
|
+
return self.request_prompt.to_text()[6:][:-11]
|
|
291
|
+
|
|
292
|
+
def get_json_prompt(self):
|
|
293
|
+
prompt_data = {
|
|
294
|
+
".agent": self.agent_prompt.to_serializable_prompt_data(),
|
|
295
|
+
".request": self.request_prompt.to_serializable_prompt_data(),
|
|
296
|
+
}
|
|
297
|
+
return json.dumps(
|
|
298
|
+
prompt_data,
|
|
299
|
+
indent=2,
|
|
300
|
+
ensure_ascii=False,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
def get_yaml_prompt(self):
|
|
304
|
+
prompt_data = {
|
|
305
|
+
".agent": self.agent_prompt.to_serializable_prompt_data(),
|
|
306
|
+
".request": self.request_prompt.to_serializable_prompt_data(),
|
|
307
|
+
}
|
|
308
|
+
return yaml.safe_dump(
|
|
309
|
+
prompt_data,
|
|
310
|
+
indent=2,
|
|
311
|
+
allow_unicode=True,
|
|
312
|
+
sort_keys=False,
|
|
313
|
+
)
|
agently/core/ModelRequest.py
CHANGED
|
@@ -22,12 +22,13 @@ ContentKindTuple: TypeAlias = Literal["all", "delta", "original"]
|
|
|
22
22
|
ContentKindStreaming: TypeAlias = Literal["instant", "streaming_parse"]
|
|
23
23
|
|
|
24
24
|
from agently.core import Prompt, ExtensionHandlers
|
|
25
|
-
from agently.utils import Settings, FunctionShifter, DataFormatter
|
|
25
|
+
from agently.utils import Settings, FunctionShifter, DataFormatter, DataLocator
|
|
26
26
|
|
|
27
27
|
if TYPE_CHECKING:
|
|
28
28
|
from agently.core import PluginManager
|
|
29
29
|
from agently.types.data import AgentlyModelResponseMessage, PromptStandardSlot, StreamingData, SerializableValue
|
|
30
30
|
from agently.types.plugins import ModelRequester, ResponseParser
|
|
31
|
+
from pydantic import BaseModel
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
class ModelResponseResult:
|
|
@@ -39,6 +40,7 @@ class ModelResponseResult:
|
|
|
39
40
|
response_generator: AsyncGenerator["AgentlyModelResponseMessage", None],
|
|
40
41
|
plugin_manager: "PluginManager",
|
|
41
42
|
settings: Settings,
|
|
43
|
+
extension_handlers: ExtensionHandlers,
|
|
42
44
|
):
|
|
43
45
|
self.agent_name = agent_name
|
|
44
46
|
self.plugin_manager = plugin_manager
|
|
@@ -50,19 +52,145 @@ class ModelResponseResult:
|
|
|
50
52
|
str(self.settings["plugins.ResponseParser.activate"]),
|
|
51
53
|
),
|
|
52
54
|
)
|
|
53
|
-
|
|
55
|
+
self._response_id = response_id
|
|
56
|
+
self._extension_handlers = extension_handlers
|
|
57
|
+
self._response_parser = ResponseParser(agent_name, response_id, prompt, response_generator, self.settings)
|
|
54
58
|
self.prompt = prompt
|
|
55
|
-
self.full_result_data = _response_parser.full_result_data
|
|
56
|
-
self.get_meta = _response_parser.get_meta
|
|
57
|
-
self.async_get_meta = _response_parser.async_get_meta
|
|
58
|
-
self.get_text = _response_parser.get_text
|
|
59
|
-
self.async_get_text = _response_parser.async_get_text
|
|
60
|
-
self.get_data = _response_parser.get_data
|
|
61
|
-
self.async_get_data = _response_parser.async_get_data
|
|
62
|
-
self.get_data_object = _response_parser.get_data_object
|
|
63
|
-
self.async_get_data_object = _response_parser.async_get_data_object
|
|
64
|
-
self.
|
|
65
|
-
self.
|
|
59
|
+
self.full_result_data = self._response_parser.full_result_data
|
|
60
|
+
self.get_meta = self._response_parser.get_meta
|
|
61
|
+
self.async_get_meta = self._response_parser.async_get_meta
|
|
62
|
+
self.get_text = self._response_parser.get_text
|
|
63
|
+
self.async_get_text = self._response_parser.async_get_text
|
|
64
|
+
# self.get_data = self._response_parser.get_data
|
|
65
|
+
# self.async_get_data = self._response_parser.async_get_data
|
|
66
|
+
# self.get_data_object = self._response_parser.get_data_object
|
|
67
|
+
# self.async_get_data_object = self._response_parser.async_get_data_object
|
|
68
|
+
self.get_data = FunctionShifter.syncify(self.async_get_data)
|
|
69
|
+
self.get_data_object = FunctionShifter.syncify(self.async_get_data_object)
|
|
70
|
+
self.get_generator = self._response_parser.get_generator
|
|
71
|
+
self.get_async_generator = self._response_parser.get_async_generator
|
|
72
|
+
|
|
73
|
+
@overload
|
|
74
|
+
async def async_get_data(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
type: Literal['parsed'],
|
|
78
|
+
ensure_keys: list[str],
|
|
79
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
80
|
+
max_retries: int = 3,
|
|
81
|
+
raise_ensure_failure: bool = True,
|
|
82
|
+
_retry_count: int = 0,
|
|
83
|
+
) -> dict[str, Any]: ...
|
|
84
|
+
|
|
85
|
+
@overload
|
|
86
|
+
async def async_get_data(
|
|
87
|
+
self,
|
|
88
|
+
*,
|
|
89
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
90
|
+
ensure_keys: list[str] | None = None,
|
|
91
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
92
|
+
max_retries: int = 3,
|
|
93
|
+
raise_ensure_failure: bool = True,
|
|
94
|
+
_retry_count: int = 0,
|
|
95
|
+
) -> Any: ...
|
|
96
|
+
|
|
97
|
+
async def async_get_data(
|
|
98
|
+
self,
|
|
99
|
+
*,
|
|
100
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
101
|
+
ensure_keys: list[str] | None = None,
|
|
102
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
103
|
+
max_retries: int = 3,
|
|
104
|
+
raise_ensure_failure: bool = True,
|
|
105
|
+
_retry_count: int = 0,
|
|
106
|
+
) -> Any:
|
|
107
|
+
if type == "parsed" and ensure_keys:
|
|
108
|
+
try:
|
|
109
|
+
data = await self._response_parser.async_get_data(type=type)
|
|
110
|
+
for ensure_key in ensure_keys:
|
|
111
|
+
EMPTY = object()
|
|
112
|
+
if DataLocator.locate_path_in_dict(data, ensure_key, key_style, default=EMPTY) is EMPTY:
|
|
113
|
+
raise
|
|
114
|
+
return data
|
|
115
|
+
except:
|
|
116
|
+
from agently.base import async_system_message
|
|
117
|
+
|
|
118
|
+
await async_system_message(
|
|
119
|
+
"MODEL_REQUEST",
|
|
120
|
+
{
|
|
121
|
+
"agent_name": self.agent_name,
|
|
122
|
+
"response_id": self._response_id,
|
|
123
|
+
"content": {
|
|
124
|
+
"stage": "No Target Data in Response, Preparing Retry",
|
|
125
|
+
"detail": f"\n[Response]: { await self.async_get_text() }\n"
|
|
126
|
+
f"[Retried Times]: { _retry_count }",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
self.settings,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if _retry_count < max_retries:
|
|
133
|
+
return await ModelResponse(
|
|
134
|
+
self.agent_name,
|
|
135
|
+
self.plugin_manager,
|
|
136
|
+
self.settings,
|
|
137
|
+
self.prompt,
|
|
138
|
+
self._extension_handlers,
|
|
139
|
+
).result.async_get_data(
|
|
140
|
+
type=type,
|
|
141
|
+
ensure_keys=ensure_keys,
|
|
142
|
+
key_style=key_style,
|
|
143
|
+
max_retries=max_retries,
|
|
144
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
145
|
+
_retry_count=_retry_count + 1,
|
|
146
|
+
)
|
|
147
|
+
else:
|
|
148
|
+
if raise_ensure_failure:
|
|
149
|
+
raise ValueError(
|
|
150
|
+
f"Can not generate ensure keys { ensure_keys } within { max_retries } retires."
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
return await self._response_parser.async_get_data(type=type)
|
|
154
|
+
return await self._response_parser.async_get_data(type=type)
|
|
155
|
+
|
|
156
|
+
@overload
|
|
157
|
+
async def async_get_data_object(
|
|
158
|
+
self,
|
|
159
|
+
*,
|
|
160
|
+
ensure_keys: list[str],
|
|
161
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
162
|
+
max_retries: int = 3,
|
|
163
|
+
raise_ensure_failure: bool = True,
|
|
164
|
+
) -> "BaseModel": ...
|
|
165
|
+
|
|
166
|
+
@overload
|
|
167
|
+
async def async_get_data_object(
|
|
168
|
+
self,
|
|
169
|
+
*,
|
|
170
|
+
ensure_keys: None,
|
|
171
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
172
|
+
max_retries: int = 3,
|
|
173
|
+
raise_ensure_failure: bool = True,
|
|
174
|
+
) -> "BaseModel | None": ...
|
|
175
|
+
|
|
176
|
+
async def async_get_data_object(
|
|
177
|
+
self,
|
|
178
|
+
*,
|
|
179
|
+
ensure_keys: list[str] | None = None,
|
|
180
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
181
|
+
max_retries: int = 3,
|
|
182
|
+
raise_ensure_failure: bool = True,
|
|
183
|
+
):
|
|
184
|
+
if ensure_keys:
|
|
185
|
+
await self.async_get_data(
|
|
186
|
+
ensure_keys=ensure_keys,
|
|
187
|
+
key_style=key_style,
|
|
188
|
+
max_retries=max_retries,
|
|
189
|
+
_retry_count=0,
|
|
190
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
191
|
+
)
|
|
192
|
+
return await self._response_parser.async_get_data_object()
|
|
193
|
+
return await self._response_parser.async_get_data_object()
|
|
66
194
|
|
|
67
195
|
|
|
68
196
|
class ModelResponse:
|
|
@@ -98,6 +226,7 @@ class ModelResponse:
|
|
|
98
226
|
self._get_response_generator(),
|
|
99
227
|
self.plugin_manager,
|
|
100
228
|
self.settings,
|
|
229
|
+
self.extension_handlers,
|
|
101
230
|
)
|
|
102
231
|
self.get_meta = self.result.get_meta
|
|
103
232
|
self.async_get_meta = self.result.async_get_meta
|
|
@@ -418,11 +547,35 @@ class ModelRequest:
|
|
|
418
547
|
self,
|
|
419
548
|
*,
|
|
420
549
|
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
550
|
+
ensure_keys: list[str] | None = None,
|
|
551
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
552
|
+
max_retries: int = 3,
|
|
553
|
+
raise_ensure_failure: bool = True,
|
|
421
554
|
):
|
|
422
|
-
|
|
555
|
+
response = self.get_response()
|
|
556
|
+
return await response.async_get_data(
|
|
557
|
+
type=type,
|
|
558
|
+
ensure_keys=ensure_keys,
|
|
559
|
+
key_style=key_style,
|
|
560
|
+
max_retries=max_retries,
|
|
561
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
562
|
+
)
|
|
423
563
|
|
|
424
|
-
async def async_get_data_object(
|
|
425
|
-
|
|
564
|
+
async def async_get_data_object(
|
|
565
|
+
self,
|
|
566
|
+
*,
|
|
567
|
+
ensure_keys: list[str] | None = None,
|
|
568
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
569
|
+
max_retries: int = 3,
|
|
570
|
+
raise_ensure_failure: bool = True,
|
|
571
|
+
):
|
|
572
|
+
response = self.get_response()
|
|
573
|
+
return await response.async_get_data_object(
|
|
574
|
+
ensure_keys=ensure_keys,
|
|
575
|
+
key_style=key_style,
|
|
576
|
+
max_retries=max_retries,
|
|
577
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
578
|
+
)
|
|
426
579
|
|
|
427
580
|
@overload
|
|
428
581
|
def get_generator(
|
agently/core/Prompt.py
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import re
|
|
16
|
+
from textwrap import dedent
|
|
16
17
|
from typing import Any, Literal, Mapping, Sequence, TYPE_CHECKING, cast, overload, TypeVar
|
|
17
18
|
|
|
18
19
|
from agently.utils import RuntimeData, Settings
|
|
@@ -98,6 +99,9 @@ class Prompt(RuntimeData):
|
|
|
98
99
|
self.to_messages = self.prompt_generator.to_messages
|
|
99
100
|
self.to_prompt_object = self.prompt_generator.to_prompt_object
|
|
100
101
|
self.to_output_model = self.prompt_generator.to_output_model
|
|
102
|
+
self.to_serializable_prompt_data = self.prompt_generator.to_serializable_prompt_data
|
|
103
|
+
self.to_json_prompt = self.prompt_generator.to_json_prompt
|
|
104
|
+
self.to_yaml_prompt = self.prompt_generator.to_yaml_prompt
|
|
101
105
|
|
|
102
106
|
def _substitute_placeholder(self, obj: T, variable_mappings: dict[str, Any]) -> T | Any:
|
|
103
107
|
if not isinstance(variable_mappings, dict):
|
|
@@ -157,6 +161,8 @@ class Prompt(RuntimeData):
|
|
|
157
161
|
value: Any,
|
|
158
162
|
mappings: dict[str, Any] | None = None,
|
|
159
163
|
):
|
|
164
|
+
if isinstance(value, str):
|
|
165
|
+
value = dedent(value.strip())
|
|
160
166
|
if mappings is not None:
|
|
161
167
|
super().set(
|
|
162
168
|
self._substitute_placeholder(key, mappings),
|
|
@@ -183,6 +189,8 @@ class Prompt(RuntimeData):
|
|
|
183
189
|
value: Any,
|
|
184
190
|
mappings: dict[str, Any] | None = None,
|
|
185
191
|
):
|
|
192
|
+
if isinstance(value, str):
|
|
193
|
+
value = dedent(value.strip())
|
|
186
194
|
if mappings is not None:
|
|
187
195
|
super().append(
|
|
188
196
|
self._substitute_placeholder(key, mappings),
|
|
@@ -16,7 +16,7 @@ from typing import Any, Protocol, TYPE_CHECKING
|
|
|
16
16
|
from .base import AgentlyPlugin
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
|
-
from agently.types.data import PromptModel
|
|
19
|
+
from agently.types.data import PromptModel, SerializableData
|
|
20
20
|
from agently.core import Prompt
|
|
21
21
|
from agently.utils import Settings
|
|
22
22
|
from pydantic import BaseModel
|
|
@@ -130,3 +130,7 @@ class PromptGenerator(AgentlyPlugin, Protocol):
|
|
|
130
130
|
- For list outputs: use `BaseModel(list=output_result)` to validate.
|
|
131
131
|
"""
|
|
132
132
|
...
|
|
133
|
+
|
|
134
|
+
def to_serializable_prompt_data(self, *args, **kwargs) -> "SerializableData": ...
|
|
135
|
+
def to_json_prompt(self, *args, **kwargs) -> str: ...
|
|
136
|
+
def to_yaml_prompt(self, *args, **kwargs) -> str: ...
|
|
@@ -4,7 +4,7 @@ agently/_default_settings.yaml,sha256=6woqJ2tjg_jl6kwSOwmTMETfVraHidort2smf0Is_q
|
|
|
4
4
|
agently/base.py,sha256=PY-HgIQesv3_oBsU25Fwe96C35C4GgpaFdxLBUwh-AA,4692
|
|
5
5
|
agently/builtins/agent_extensions/AutoFuncExtension.py,sha256=TmwMazwPzb5WXfDqfedY5yZOOMTFIHqaB9Bte29adUc,2433
|
|
6
6
|
agently/builtins/agent_extensions/ChatSessionExtension.py,sha256=Y6mvnsfAY0rykKtfp-tApwJy5O4SS-YEt2-jaWr83uc,12034
|
|
7
|
-
agently/builtins/agent_extensions/ConfigurePromptExtension.py,sha256=
|
|
7
|
+
agently/builtins/agent_extensions/ConfigurePromptExtension.py,sha256=vURsWcy5UnKppBNOAy0ZnY03yMY3QqH7j3ZeixS8VOo,10230
|
|
8
8
|
agently/builtins/agent_extensions/KeyWaiterExtension.py,sha256=Rf8dB8Yt3_9IJifpiE-Rn6lLIXqZjaNp94lnX6Betgw,5555
|
|
9
9
|
agently/builtins/agent_extensions/ToolExtension.py,sha256=S3jjumHiauEQ-m46Zkh-1I9ih02kKoj8sBEU82woz1E,6886
|
|
10
10
|
agently/builtins/agent_extensions/__init__.py,sha256=IxWRQogF8PCVNXeY7D4qhGukEx3JFvfLlUW2x0FbyfA,852
|
|
@@ -12,19 +12,19 @@ agently/builtins/hookers/ConsoleHooker.py,sha256=aJdDj_nG8CiwyelA505zvtpzBSwD52n
|
|
|
12
12
|
agently/builtins/hookers/PureLoggerHooker.py,sha256=fzN0OfhQzgns4KeCNH-qcdm-BdQT0W2kqEmt3Zp2pYI,1906
|
|
13
13
|
agently/builtins/hookers/SystemMessageHooker.py,sha256=nU5rOzcuXKdaTXWix3jhZ-4QoD4cMQJZo02wNTpZpjI,5396
|
|
14
14
|
agently/builtins/plugins/ModelRequester/OpenAICompatible.py,sha256=xX-iy3qgToD8jIrPsL1NufMb6dlf0SVmX0rPjAkPSQ0,25261
|
|
15
|
-
agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py,sha256=
|
|
15
|
+
agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py,sha256=Ma9rTsLnDk8gNkjVR5r1fqnO7emajR5aNJbtzZDteNU,30553
|
|
16
16
|
agently/builtins/plugins/ResponseParser/AgentlyResponseParser.py,sha256=FEhfsiHB4Bx7HfghnObklLj08j8IVwGh0WEVD6U-G3U,17445
|
|
17
17
|
agently/builtins/plugins/ToolManager/AgentlyToolManager.py,sha256=oaqte5LAryZQMD6vuEbKhe6kOLUyZTRZswC1MDFiYxw,9138
|
|
18
18
|
agently/builtins/plugins/__init__.py,sha256=wj4_U9TTekc2CmjppbXKUREDFRXFX1y0ySOW-CxQuok,801
|
|
19
19
|
agently/builtins/tools/Browse.py,sha256=gIePs-gtsqOI_ZTReGqEcoKvhs4FkBzTxow--QS5_ek,3469
|
|
20
20
|
agently/builtins/tools/Search.py,sha256=tUynNiW_ZMAGaB2ua3HRcY_trIbLEoASFE-p2QMQ0Zg,7362
|
|
21
21
|
agently/builtins/tools/__init__.py,sha256=pFOWgH2C3xRvgQo3UVdkj4yHjF9nNtmoVHmOZfoGsyU,647
|
|
22
|
-
agently/core/Agent.py,sha256=
|
|
22
|
+
agently/core/Agent.py,sha256=EIhHCxu4ePZxH6kMQdseQsfricRO3nFSNkEVkKVqXrE,9973
|
|
23
23
|
agently/core/EventCenter.py,sha256=sknU5w9MpGDQgMOF9c5k4PfM4SNT5X_LrpYte2HaFNM,10861
|
|
24
24
|
agently/core/ExtensionHandlers.py,sha256=88iSAW50bgMshB56cTgKg30eOjZQyXiJY1en4w7afWY,2076
|
|
25
|
-
agently/core/ModelRequest.py,sha256=
|
|
25
|
+
agently/core/ModelRequest.py,sha256=OAsNRKFiSAR_dfAdWO6efgUSQat8rHGfZ-zkiSPVNDc,22943
|
|
26
26
|
agently/core/PluginManager.py,sha256=oUnXbe1ilQTOWwnENxtGtV6wG-yZriCxniqfuxuTFO0,4354
|
|
27
|
-
agently/core/Prompt.py,sha256=
|
|
27
|
+
agently/core/Prompt.py,sha256=oAxRZ7kG07mM6G7p6gP_zX41TgGb8vA-IilcnCb_Gc4,8432
|
|
28
28
|
agently/core/Tool.py,sha256=PNYf_BwVefr8IOqf5asLaVq2fU7hQaFJwJVj3S4fq84,1871
|
|
29
29
|
agently/core/TriggerFlow/BluePrint.py,sha256=Lz-wbA0f79t7VjvX0knH-9AC_Qz9wts0QFemL97R3jo,4810
|
|
30
30
|
agently/core/TriggerFlow/Chunk.py,sha256=i5oTT9-dI-mXI6vbWwnQZ5e1ryGgZDYsyE9ALqbS2tQ,1555
|
|
@@ -48,7 +48,7 @@ agently/types/data/serializable.py,sha256=v2KlyKNOKp4L6J_Ueupb-gCyrnngvBskFUwNPS
|
|
|
48
48
|
agently/types/data/tool.py,sha256=wE8Dda2JtY5cojpHUuQrw7PNeVZ6Zma968bn-pUmS7I,1529
|
|
49
49
|
agently/types/plugins/EventHooker.py,sha256=kb80-baVc3fVlrddW5syv9uSD8a2Mcw8Fd3I2HQhY_Y,1030
|
|
50
50
|
agently/types/plugins/ModelRequester.py,sha256=urG1zFX0b4U6ZKSO50IbW5IHK3ydmRgUom7O7Niqk8s,3875
|
|
51
|
-
agently/types/plugins/PromptGenerator.py,sha256=
|
|
51
|
+
agently/types/plugins/PromptGenerator.py,sha256=V8kqT0Eeq09AQqfGA-SZ5mNKeit1UrmqlDQCquSMzUU,4752
|
|
52
52
|
agently/types/plugins/ResponseParser.py,sha256=_IRbQhT-G1ZNg2zkJgCYNF5qRaIzrDfbxLC7kO-tdK4,3984
|
|
53
53
|
agently/types/plugins/ToolManager.py,sha256=q1Y3G_tzh1AU3s13H-zTDZIkR4W1mjh9E6AKudFOvyg,2421
|
|
54
54
|
agently/types/plugins/__init__.py,sha256=gz_EpgBQGndIQHY5vJB2YRzAN5yIb3FZZG7pC8lB1lM,848
|
|
@@ -70,7 +70,7 @@ agently/utils/Storage.py,sha256=E7QyNJ9T0yOUafPgdP90La698hgLMSGjhJ7qCEHzxxw,9438
|
|
|
70
70
|
agently/utils/StreamingJSONCompleter.py,sha256=aZ9zuGUTQlP-QKbXHUZCf6EtVuG49MKn8xdhw0VhDEA,4292
|
|
71
71
|
agently/utils/StreamingJSONParser.py,sha256=sPPJOtj5OYvsrukRErcoxRl4yuV1zDuf7pQ_pvw_Zow,21116
|
|
72
72
|
agently/utils/__init__.py,sha256=7MDln5OVkqFEdhhuG8VTdr2q02UWwCj-udndwzWV_iQ,1280
|
|
73
|
-
agently-4.0.6.
|
|
74
|
-
agently-4.0.6.
|
|
75
|
-
agently-4.0.6.
|
|
76
|
-
agently-4.0.6.
|
|
73
|
+
agently-4.0.6.9.dist-info/METADATA,sha256=HTZhMkH_W8nVgy1aZJZhZbpp3VG168z60y7eEUsUwnk,7112
|
|
74
|
+
agently-4.0.6.9.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
75
|
+
agently-4.0.6.9.dist-info/licenses/LICENSE,sha256=Y5ZgAdYgMFigPT8dhN18dTLRtBshOSfWhTDRO1t0Cq4,11360
|
|
76
|
+
agently-4.0.6.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|