goose-py 0.3.12__tar.gz → 0.4.0__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.
- {goose_py-0.3.12 → goose_py-0.4.0}/PKG-INFO +1 -1
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/flow.py +54 -18
- {goose_py-0.3.12 → goose_py-0.4.0}/pyproject.toml +1 -1
- {goose_py-0.3.12 → goose_py-0.4.0}/README.md +0 -0
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/__init__.py +0 -0
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/agent.py +0 -0
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/errors.py +0 -0
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/py.typed +0 -0
- {goose_py-0.3.12 → goose_py-0.4.0}/goose/store.py +0 -0
@@ -115,6 +115,8 @@ class FlowRun:
|
|
115
115
|
self._flow_name = ""
|
116
116
|
self._id = ""
|
117
117
|
self._agent: Agent | None = None
|
118
|
+
self._flow_args: tuple[Any, ...] | None = None
|
119
|
+
self._flow_kwargs: dict[str, Any] | None = None
|
118
120
|
|
119
121
|
@property
|
120
122
|
def flow_name(self) -> str:
|
@@ -130,17 +132,12 @@ class FlowRun:
|
|
130
132
|
raise Honk("Agent is only accessible once a run is started")
|
131
133
|
return self._agent
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
self.
|
136
|
-
|
137
|
-
def get_next[R: Result](self, *, task: "Task[Any, R]") -> NodeState[R]:
|
138
|
-
if task.name not in self._last_requested_indices:
|
139
|
-
self._last_requested_indices[task.name] = 0
|
140
|
-
else:
|
141
|
-
self._last_requested_indices[task.name] += 1
|
135
|
+
@property
|
136
|
+
def flow_inputs(self) -> tuple[tuple[Any, ...], dict[str, Any]]:
|
137
|
+
if self._flow_args is None or self._flow_kwargs is None:
|
138
|
+
raise Honk("This Flow run has not been executed before")
|
142
139
|
|
143
|
-
return self.
|
140
|
+
return self._flow_args, self._flow_kwargs
|
144
141
|
|
145
142
|
def get_all[R: Result](self, *, task: "Task[Any, R]") -> list[NodeState[R]]:
|
146
143
|
matching_nodes: list[NodeState[R]] = []
|
@@ -166,6 +163,22 @@ class FlowRun:
|
|
166
163
|
last_hash=0,
|
167
164
|
)
|
168
165
|
|
166
|
+
def set_flow_inputs(self, *args: Any, **kwargs: Any) -> None:
|
167
|
+
self._flow_args = args
|
168
|
+
self._flow_kwargs = kwargs
|
169
|
+
|
170
|
+
def add_node_state(self, node_state: NodeState[Any], /) -> None:
|
171
|
+
key = (node_state.task_name, node_state.index)
|
172
|
+
self._node_states[key] = node_state.model_dump_json()
|
173
|
+
|
174
|
+
def get_next[R: Result](self, *, task: "Task[Any, R]") -> NodeState[R]:
|
175
|
+
if task.name not in self._last_requested_indices:
|
176
|
+
self._last_requested_indices[task.name] = 0
|
177
|
+
else:
|
178
|
+
self._last_requested_indices[task.name] += 1
|
179
|
+
|
180
|
+
return self.get(task=task, index=self._last_requested_indices[task.name])
|
181
|
+
|
169
182
|
def start(
|
170
183
|
self,
|
171
184
|
*,
|
@@ -192,25 +205,35 @@ class FlowRun:
|
|
192
205
|
del self._node_states[key]
|
193
206
|
|
194
207
|
def dump(self) -> SerializedFlowRun:
|
208
|
+
flow_args, flow_kwargs = self.flow_inputs
|
209
|
+
|
195
210
|
return SerializedFlowRun(
|
196
211
|
json.dumps(
|
197
212
|
{
|
198
|
-
"
|
199
|
-
|
213
|
+
"node_states": {
|
214
|
+
":".join([task_name, str(index)]): value
|
215
|
+
for (task_name, index), value in self._node_states.items()
|
216
|
+
},
|
217
|
+
"flow_args": list(flow_args),
|
218
|
+
"flow_kwargs": flow_kwargs,
|
200
219
|
}
|
201
220
|
)
|
202
221
|
)
|
203
222
|
|
204
223
|
@classmethod
|
205
|
-
def load(cls,
|
224
|
+
def load(cls, serialized_flow_run: SerializedFlowRun, /) -> Self:
|
206
225
|
flow_run = cls()
|
207
|
-
|
226
|
+
run = json.loads(serialized_flow_run)
|
227
|
+
|
208
228
|
new_node_states: dict[tuple[str, int], str] = {}
|
209
|
-
for key, node_state in
|
229
|
+
for key, node_state in run["node_states"].items():
|
210
230
|
task_name, index = tuple(key.split(":"))
|
211
231
|
new_node_states[(task_name, int(index))] = node_state
|
212
|
-
|
213
232
|
flow_run._node_states = new_node_states
|
233
|
+
|
234
|
+
flow_run._flow_args = tuple(run["flow_args"])
|
235
|
+
flow_run._flow_kwargs = run["flow_kwargs"]
|
236
|
+
|
214
237
|
return flow_run
|
215
238
|
|
216
239
|
|
@@ -264,8 +287,21 @@ class Flow[**P]:
|
|
264
287
|
_current_flow_run.set(old_run)
|
265
288
|
|
266
289
|
async def generate(self, *args: P.args, **kwargs: P.kwargs) -> None:
|
290
|
+
flow_run = _current_flow_run.get()
|
291
|
+
if flow_run is None:
|
292
|
+
raise Honk("No current flow run")
|
293
|
+
|
294
|
+
flow_run.set_flow_inputs(*args, **kwargs)
|
267
295
|
await self._fn(*args, **kwargs)
|
268
296
|
|
297
|
+
async def regenerate(self) -> None:
|
298
|
+
flow_run = _current_flow_run.get()
|
299
|
+
if flow_run is None:
|
300
|
+
raise Honk("No current flow run")
|
301
|
+
|
302
|
+
flow_args, flow_kwargs = flow_run.flow_inputs
|
303
|
+
await self._fn(*flow_args, **flow_kwargs)
|
304
|
+
|
269
305
|
|
270
306
|
class Task[**P, R: Result]:
|
271
307
|
def __init__(
|
@@ -323,7 +359,7 @@ class Task[**P, R: Result]:
|
|
323
359
|
|
324
360
|
result = await self._adapter(conversation=node_state.conversation)
|
325
361
|
node_state.add_result(result=result)
|
326
|
-
flow_run.
|
362
|
+
flow_run.add_node_state(node_state)
|
327
363
|
|
328
364
|
return result
|
329
365
|
|
@@ -331,7 +367,7 @@ class Task[**P, R: Result]:
|
|
331
367
|
flow_run = self.__get_current_flow_run()
|
332
368
|
node_state = flow_run.get_next(task=self)
|
333
369
|
result = await self.generate(node_state, *args, **kwargs)
|
334
|
-
flow_run.
|
370
|
+
flow_run.add_node_state(node_state)
|
335
371
|
return result
|
336
372
|
|
337
373
|
def __hash_task_call(self, *args: P.args, **kwargs: P.kwargs) -> int:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|