goose-py 0.3.8__tar.gz → 0.3.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.
- {goose_py-0.3.8 → goose_py-0.3.9}/PKG-INFO +1 -1
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/flow.py +20 -10
- {goose_py-0.3.8 → goose_py-0.3.9}/pyproject.toml +1 -1
- {goose_py-0.3.8 → goose_py-0.3.9}/README.md +0 -0
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/__init__.py +0 -0
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/agent.py +0 -0
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/errors.py +0 -0
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/py.typed +0 -0
- {goose_py-0.3.8 → goose_py-0.3.9}/goose/store.py +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
from contextlib import asynccontextmanager
|
3
3
|
from contextvars import ContextVar
|
4
|
+
from types import CodeType
|
4
5
|
from typing import (
|
5
6
|
Any,
|
6
7
|
AsyncIterator,
|
@@ -65,6 +66,8 @@ class Conversation[R: Result](BaseModel):
|
|
65
66
|
|
66
67
|
|
67
68
|
class IAdapter[ResultT: Result](Protocol):
|
69
|
+
__code__: CodeType
|
70
|
+
|
68
71
|
async def __call__(self, *, conversation: Conversation[ResultT]) -> ResultT: ...
|
69
72
|
|
70
73
|
|
@@ -72,7 +75,7 @@ class NodeState[ResultT: Result](BaseModel):
|
|
72
75
|
task_name: str
|
73
76
|
index: int
|
74
77
|
conversation: Conversation[ResultT]
|
75
|
-
|
78
|
+
last_hash: int
|
76
79
|
|
77
80
|
@property
|
78
81
|
def result(self) -> ResultT:
|
@@ -89,15 +92,15 @@ class NodeState[ResultT: Result](BaseModel):
|
|
89
92
|
self,
|
90
93
|
*,
|
91
94
|
result: ResultT,
|
92
|
-
|
95
|
+
new_hash: int | None = None,
|
93
96
|
overwrite: bool = False,
|
94
97
|
) -> Self:
|
95
98
|
if overwrite and len(self.conversation.result_messages) > 0:
|
96
99
|
self.conversation.result_messages[-1] = result
|
97
100
|
else:
|
98
101
|
self.conversation.result_messages.append(result)
|
99
|
-
if
|
100
|
-
self.
|
102
|
+
if new_hash is not None:
|
103
|
+
self.last_hash = new_hash
|
101
104
|
return self
|
102
105
|
|
103
106
|
def add_user_message(self, *, message: UserMessage) -> Self:
|
@@ -160,7 +163,7 @@ class FlowRun:
|
|
160
163
|
conversation=Conversation[task.result_type](
|
161
164
|
user_messages=[], result_messages=[]
|
162
165
|
),
|
163
|
-
|
166
|
+
last_hash=0,
|
164
167
|
)
|
165
168
|
|
166
169
|
def start(
|
@@ -289,10 +292,10 @@ class Task[**P, R: Result]:
|
|
289
292
|
async def generate(
|
290
293
|
self, state: NodeState[R], *args: P.args, **kwargs: P.kwargs
|
291
294
|
) -> R:
|
292
|
-
|
293
|
-
if
|
295
|
+
state_hash = self.__hash_task_call(*args, **kwargs)
|
296
|
+
if state_hash != state.last_hash:
|
294
297
|
result = await self._generator(*args, **kwargs)
|
295
|
-
state.add_result(result=result,
|
298
|
+
state.add_result(result=result, new_hash=state_hash, overwrite=True)
|
296
299
|
return result
|
297
300
|
else:
|
298
301
|
return state.result
|
@@ -326,9 +329,16 @@ class Task[**P, R: Result]:
|
|
326
329
|
flow_run.add(node_state)
|
327
330
|
return result
|
328
331
|
|
329
|
-
def
|
332
|
+
def __hash_task_call(self, *args: P.args, **kwargs: P.kwargs) -> int:
|
330
333
|
try:
|
331
|
-
to_hash = str(
|
334
|
+
to_hash = str(
|
335
|
+
tuple(args)
|
336
|
+
+ tuple(kwargs.values())
|
337
|
+
+ (
|
338
|
+
self._generator.__code__,
|
339
|
+
self._adapter.__code__ if self._adapter is not None else None,
|
340
|
+
)
|
341
|
+
)
|
332
342
|
return hash(to_hash)
|
333
343
|
except TypeError:
|
334
344
|
raise Honk(f"Unhashable argument to task {self.name}: {args} {kwargs}")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|