goose-py 0.9.3__py3-none-any.whl → 0.9.5__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.
- goose/_internal/flow.py +10 -8
- goose/_internal/state.py +4 -2
- goose/_internal/store.py +8 -14
- goose/_internal/task.py +28 -5
- {goose_py-0.9.3.dist-info → goose_py-0.9.5.dist-info}/METADATA +1 -1
- {goose_py-0.9.3.dist-info → goose_py-0.9.5.dist-info}/RECORD +7 -7
- {goose_py-0.9.3.dist-info → goose_py-0.9.5.dist-info}/WHEEL +0 -0
goose/_internal/flow.py
CHANGED
@@ -30,13 +30,13 @@ class Flow[FlowArgumentsT: FlowArguments]:
|
|
30
30
|
/,
|
31
31
|
*,
|
32
32
|
name: str | None = None,
|
33
|
-
store: IFlowRunStore
|
33
|
+
store: IFlowRunStore | None = None,
|
34
34
|
agent_logger: IAgentLogger | None = None,
|
35
35
|
) -> None:
|
36
36
|
self._fn = fn
|
37
37
|
self._name = name
|
38
38
|
self._agent_logger = agent_logger
|
39
|
-
self._store = store or InMemoryFlowRunStore(flow_name=self.name
|
39
|
+
self._store = store or InMemoryFlowRunStore(flow_name=self.name)
|
40
40
|
|
41
41
|
@property
|
42
42
|
def flow_arguments_model(self) -> type[FlowArgumentsT]:
|
@@ -59,11 +59,13 @@ class Flow[FlowArgumentsT: FlowArguments]:
|
|
59
59
|
|
60
60
|
@asynccontextmanager
|
61
61
|
async def start_run(self, *, run_id: str) -> AsyncIterator[FlowRun[FlowArgumentsT]]:
|
62
|
-
|
63
|
-
if
|
64
|
-
run = FlowRun(
|
62
|
+
existing_serialized_run = await self._store.get(run_id=run_id)
|
63
|
+
if existing_serialized_run is not None:
|
64
|
+
run = FlowRun.load(
|
65
|
+
serialized_flow_run=existing_serialized_run, flow_arguments_model=self.flow_arguments_model
|
66
|
+
)
|
65
67
|
else:
|
66
|
-
run =
|
68
|
+
run = FlowRun(flow_arguments_model=self.flow_arguments_model)
|
67
69
|
|
68
70
|
old_run = get_current_flow_run()
|
69
71
|
set_current_flow_run(run)
|
@@ -97,7 +99,7 @@ def flow[FlowArgumentsT: FlowArguments](fn: IGenerator[FlowArgumentsT], /) -> Fl
|
|
97
99
|
def flow[FlowArgumentsT: FlowArguments](
|
98
100
|
*,
|
99
101
|
name: str | None = None,
|
100
|
-
store: IFlowRunStore
|
102
|
+
store: IFlowRunStore | None = None,
|
101
103
|
agent_logger: IAgentLogger | None = None,
|
102
104
|
) -> Callable[[IGenerator[FlowArgumentsT]], Flow[FlowArgumentsT]]: ...
|
103
105
|
def flow[FlowArgumentsT: FlowArguments](
|
@@ -105,7 +107,7 @@ def flow[FlowArgumentsT: FlowArguments](
|
|
105
107
|
/,
|
106
108
|
*,
|
107
109
|
name: str | None = None,
|
108
|
-
store: IFlowRunStore
|
110
|
+
store: IFlowRunStore | None = None,
|
109
111
|
agent_logger: IAgentLogger | None = None,
|
110
112
|
) -> Flow[FlowArgumentsT] | Callable[[IGenerator[FlowArgumentsT]], Flow[FlowArgumentsT]]:
|
111
113
|
if fn is None:
|
goose/_internal/state.py
CHANGED
@@ -166,7 +166,9 @@ class FlowRun[FlowArgumentsT: FlowArguments]:
|
|
166
166
|
)
|
167
167
|
|
168
168
|
@classmethod
|
169
|
-
def load
|
169
|
+
def load[T: FlowArguments](
|
170
|
+
cls, *, serialized_flow_run: SerializedFlowRun, flow_arguments_model: type[T]
|
171
|
+
) -> "FlowRun[T]":
|
170
172
|
flow_run_state = json.loads(serialized_flow_run)
|
171
173
|
raw_node_states = flow_run_state["node_states"]
|
172
174
|
node_states: dict[tuple[str, int], str] = {}
|
@@ -175,7 +177,7 @@ class FlowRun[FlowArgumentsT: FlowArguments]:
|
|
175
177
|
node_states[(task_name, int(index))] = value
|
176
178
|
flow_arguments = flow_arguments_model.model_validate(flow_run_state["flow_arguments"])
|
177
179
|
|
178
|
-
flow_run =
|
180
|
+
flow_run = FlowRun(flow_arguments_model=flow_arguments_model)
|
179
181
|
flow_run._node_states = node_states
|
180
182
|
flow_run._flow_arguments = flow_arguments
|
181
183
|
|
goose/_internal/store.py
CHANGED
@@ -2,29 +2,23 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
from typing import Protocol
|
4
4
|
|
5
|
-
from goose._internal.
|
6
|
-
from goose._internal.state import FlowArguments, SerializedFlowRun
|
5
|
+
from goose._internal.state import SerializedFlowRun
|
7
6
|
|
8
7
|
|
9
|
-
class IFlowRunStore
|
10
|
-
def __init__(self, *, flow_name: str
|
11
|
-
async def get(self, *, run_id: str) ->
|
8
|
+
class IFlowRunStore(Protocol):
|
9
|
+
def __init__(self, *, flow_name: str) -> None: ...
|
10
|
+
async def get(self, *, run_id: str) -> SerializedFlowRun | None: ...
|
12
11
|
async def save(self, *, run_id: str, run: SerializedFlowRun) -> None: ...
|
13
12
|
async def delete(self, *, run_id: str) -> None: ...
|
14
13
|
|
15
14
|
|
16
|
-
class InMemoryFlowRunStore
|
17
|
-
def __init__(self, *, flow_name: str
|
15
|
+
class InMemoryFlowRunStore(IFlowRunStore):
|
16
|
+
def __init__(self, *, flow_name: str) -> None:
|
18
17
|
self._flow_name = flow_name
|
19
|
-
self._flow_arguments_model = flow_arguments_model
|
20
18
|
self._runs: dict[str, SerializedFlowRun] = {}
|
21
19
|
|
22
|
-
async def get(self, *, run_id: str) ->
|
23
|
-
|
24
|
-
if serialized_flow_run is not None:
|
25
|
-
return FlowRun.load(
|
26
|
-
serialized_flow_run=serialized_flow_run, flow_arguments_model=self._flow_arguments_model
|
27
|
-
)
|
20
|
+
async def get(self, *, run_id: str) -> SerializedFlowRun | None:
|
21
|
+
return self._runs.get(run_id)
|
28
22
|
|
29
23
|
async def save(self, *, run_id: str, run: SerializedFlowRun) -> None:
|
30
24
|
self._runs[run_id] = run
|
goose/_internal/task.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
import hashlib
|
1
2
|
from collections.abc import Awaitable, Callable
|
2
3
|
from typing import Any, overload
|
3
4
|
|
5
|
+
from pydantic import BaseModel
|
6
|
+
|
4
7
|
from goose._internal.agent import Agent, GeminiModel, SystemMessage, UserMessage
|
5
8
|
from goose._internal.conversation import Conversation
|
6
9
|
from goose._internal.result import Result, TextResult
|
@@ -105,11 +108,31 @@ class Task[**P, R: Result]:
|
|
105
108
|
)
|
106
109
|
|
107
110
|
def __hash_task_call(self, *args: P.args, **kwargs: P.kwargs) -> int:
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
def update_hash(argument: Any, current_hash: Any = hashlib.sha256()) -> None:
|
112
|
+
try:
|
113
|
+
if isinstance(argument, list | tuple | set):
|
114
|
+
for item in argument:
|
115
|
+
update_hash(item, current_hash)
|
116
|
+
elif isinstance(argument, dict):
|
117
|
+
for key, value in argument.items():
|
118
|
+
update_hash(key, current_hash)
|
119
|
+
update_hash(value, current_hash)
|
120
|
+
elif isinstance(argument, BaseModel):
|
121
|
+
update_hash(argument.model_dump_json())
|
122
|
+
elif isinstance(argument, bytes):
|
123
|
+
current_hash.update(argument)
|
124
|
+
elif isinstance(argument, Agent):
|
125
|
+
current_hash.update(b"AGENT")
|
126
|
+
else:
|
127
|
+
current_hash.update(str(argument).encode())
|
128
|
+
except TypeError:
|
129
|
+
raise Honk(f"Unhashable argument to task {self.name}: {argument}")
|
130
|
+
|
131
|
+
result = hashlib.sha256()
|
132
|
+
update_hash(args, result)
|
133
|
+
update_hash(kwargs, result)
|
134
|
+
|
135
|
+
return int(result.hexdigest(), 16)
|
113
136
|
|
114
137
|
def __get_current_flow_run(self) -> FlowRun[Any]:
|
115
138
|
run = get_current_flow_run()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: goose-py
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.5
|
4
4
|
Summary: A tool for AI workflows based on human-computer collaboration and structured output.
|
5
5
|
Author-email: Nash Taylor <nash@chelle.ai>, Joshua Cook <joshua@chelle.ai>, Michael Sankur <michael@chelle.ai>
|
6
6
|
Requires-Python: >=3.12
|
@@ -6,13 +6,13 @@ goose/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
goose/runs.py,sha256=kAHw08ayGbwzSH_p-CfsQDvTcA4H09nUuq6zt3gIFxo,170
|
7
7
|
goose/_internal/agent.py,sha256=l0pKfShovrs238sKAr-zubtcacYm82TGwQHcBWVJm2g,5875
|
8
8
|
goose/_internal/conversation.py,sha256=1OZQ_N6QZE7L_ZpXG2bjoWkVQ-G7h0JvKkqswmQWG58,1202
|
9
|
-
goose/_internal/flow.py,sha256=
|
9
|
+
goose/_internal/flow.py,sha256=05U2f5i8ofQWDjghhomwuuEPMk-ftzXn7BVl_s7pIf8,4203
|
10
10
|
goose/_internal/result.py,sha256=-eZJn-2sPo7rHZ38Sz6IAHXqiJ-Ss39esEoFGimJEBI,155
|
11
|
-
goose/_internal/state.py,sha256=
|
12
|
-
goose/_internal/store.py,sha256
|
13
|
-
goose/_internal/task.py,sha256=
|
11
|
+
goose/_internal/state.py,sha256=LmMxhr3OrilYRHRxw1xYnl_dUkndaayLej83ccjfOGs,6583
|
12
|
+
goose/_internal/store.py,sha256=GMW0wBpxESmRBLfL_lFKEi9x2P6Wd6-gZ7AWjWBTUmA,904
|
13
|
+
goose/_internal/task.py,sha256=2ScqedrBXZueFzQ73MWOFed8HdhOvFz_S6B54zBOKjc,6114
|
14
14
|
goose/_internal/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
goose/_internal/types/agent.py,sha256=rNVt2gEr_m4_8tGFgcdichpPp8xhOS5GY0kN2C4tiE8,2153
|
16
|
-
goose_py-0.9.
|
17
|
-
goose_py-0.9.
|
18
|
-
goose_py-0.9.
|
16
|
+
goose_py-0.9.5.dist-info/METADATA,sha256=LZ0eKUr1kLNQ5918kiGWdXn6xKYWzd_dlWsG9ZycSV4,441
|
17
|
+
goose_py-0.9.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
18
|
+
goose_py-0.9.5.dist-info/RECORD,,
|
File without changes
|