agently 4.0.6.7__tar.gz → 4.0.6.9__tar.gz

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.
Files changed (76) hide show
  1. {agently-4.0.6.7 → agently-4.0.6.9}/PKG-INFO +1 -1
  2. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/ConfigurePromptExtension.py +2 -0
  3. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py +58 -1
  4. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/Agent.py +52 -23
  5. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/ModelRequest.py +169 -16
  6. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/Prompt.py +8 -0
  7. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/PromptGenerator.py +5 -1
  8. {agently-4.0.6.7 → agently-4.0.6.9}/pyproject.toml +1 -1
  9. {agently-4.0.6.7 → agently-4.0.6.9}/LICENSE +0 -0
  10. {agently-4.0.6.7 → agently-4.0.6.9}/README.md +0 -0
  11. {agently-4.0.6.7 → agently-4.0.6.9}/agently/__init__.py +0 -0
  12. {agently-4.0.6.7 → agently-4.0.6.9}/agently/_default_init.py +0 -0
  13. {agently-4.0.6.7 → agently-4.0.6.9}/agently/_default_settings.yaml +0 -0
  14. {agently-4.0.6.7 → agently-4.0.6.9}/agently/base.py +0 -0
  15. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/AutoFuncExtension.py +0 -0
  16. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/ChatSessionExtension.py +0 -0
  17. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/KeyWaiterExtension.py +0 -0
  18. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/ToolExtension.py +0 -0
  19. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/agent_extensions/__init__.py +0 -0
  20. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/hookers/ConsoleHooker.py +0 -0
  21. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/hookers/PureLoggerHooker.py +0 -0
  22. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/hookers/SystemMessageHooker.py +0 -0
  23. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/plugins/ModelRequester/OpenAICompatible.py +0 -0
  24. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/plugins/ResponseParser/AgentlyResponseParser.py +0 -0
  25. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/plugins/ToolManager/AgentlyToolManager.py +0 -0
  26. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/plugins/__init__.py +0 -0
  27. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/tools/Browse.py +0 -0
  28. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/tools/Search.py +0 -0
  29. {agently-4.0.6.7 → agently-4.0.6.9}/agently/builtins/tools/__init__.py +0 -0
  30. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/EventCenter.py +0 -0
  31. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/ExtensionHandlers.py +0 -0
  32. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/PluginManager.py +0 -0
  33. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/Tool.py +0 -0
  34. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/BluePrint.py +0 -0
  35. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/Chunk.py +0 -0
  36. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/Execution.py +0 -0
  37. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/Process.py +0 -0
  38. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/TriggerFlow.py +0 -0
  39. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/__init__.py +0 -0
  40. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/process/BaseProcess.py +0 -0
  41. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/process/ForEachProcess.py +0 -0
  42. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/process/MatchCaseProcess.py +0 -0
  43. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/TriggerFlow/process/__init__.py +0 -0
  44. {agently-4.0.6.7 → agently-4.0.6.9}/agently/core/__init__.py +0 -0
  45. {agently-4.0.6.7 → agently-4.0.6.9}/agently/integrations/chromadb.py +0 -0
  46. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/__init__.py +0 -0
  47. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/__init__.py +0 -0
  48. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/event.py +0 -0
  49. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/prompt.py +0 -0
  50. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/request.py +0 -0
  51. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/response.py +0 -0
  52. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/serializable.py +0 -0
  53. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/data/tool.py +0 -0
  54. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/EventHooker.py +0 -0
  55. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/ModelRequester.py +0 -0
  56. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/ResponseParser.py +0 -0
  57. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/ToolManager.py +0 -0
  58. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/__init__.py +0 -0
  59. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/plugins/base.py +0 -0
  60. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/trigger_flow/__init__.py +0 -0
  61. {agently-4.0.6.7 → agently-4.0.6.9}/agently/types/trigger_flow/trigger_flow.py +0 -0
  62. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/DataFormatter.py +0 -0
  63. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/DataLocator.py +0 -0
  64. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/DataPathBuilder.py +0 -0
  65. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/FunctionShifter.py +0 -0
  66. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/GeneratorConsumer.py +0 -0
  67. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/LazyImport.py +0 -0
  68. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/Logger.py +0 -0
  69. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/Messenger.py +0 -0
  70. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/RuntimeData.py +0 -0
  71. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/SerializableRuntimeData.py +0 -0
  72. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/Settings.py +0 -0
  73. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/Storage.py +0 -0
  74. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/StreamingJSONCompleter.py +0 -0
  75. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/StreamingJSONParser.py +0 -0
  76. {agently-4.0.6.7 → agently-4.0.6.9}/agently/utils/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agently
3
- Version: 4.0.6.7
3
+ Version: 4.0.6.9
4
4
  Summary:
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -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(name, **fields, **validators)
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
+ )
@@ -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.prompt.set(key, value, mappings)
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.prompt.set(key, None)
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.prompt:
116
- self.prompt.set("chat_history", [])
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.prompt.set("chat_history", chat_history)
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.prompt.set("chat_history", chat_history)
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.prompt:
134
- del self.prompt["action_results"]
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.prompt.set("action_results", action_results)
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.prompt.append("action_results", {action: result})
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.prompt.set("input", prompt, mappings)
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.prompt.set("instruct", ["{system.rule} ARE IMPORTANT RULES YOU SHALL FOLLOW!"])
168
- self.prompt.set("system.rule", prompt, mappings)
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.prompt.set("instruct", ["YOU MUST REACT AND RESPOND AS {system.role}!"])
183
- self.prompt.set("system.your_role", prompt, mappings)
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.prompt.set("instruct", ["{system.user_info} IS IMPORTANT INFORMATION ABOUT USER!"])
198
- self.prompt.set("system.user_info", prompt, mappings)
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.prompt.set("input", prompt, mappings)
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.prompt.set("info", prompt, mappings)
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.prompt.set("instruct", prompt, mappings)
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.prompt.set("examples", prompt, mappings)
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.prompt.set("output", prompt, mappings)
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.prompt.set("options", options)
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
+ )
@@ -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
- _response_parser = ResponseParser(agent_name, response_id, prompt, response_generator, self.settings)
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.get_generator = _response_parser.get_generator
65
- self.get_async_generator = _response_parser.get_async_generator
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
- return await self.get_response().async_get_data(type=type)
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(self):
425
- return await self.get_response().async_get_data_object()
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(
@@ -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: ...
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agently"
3
- version = "4.0.6.7"
3
+ version = "4.0.6.9"
4
4
  description = ""
5
5
  authors = [
6
6
  {name = "Agently Team",email = "developer@agently.tech"},
File without changes
File without changes
File without changes
File without changes