goose-py 0.7.1__py3-none-any.whl → 0.7.3__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.
@@ -1,12 +1,9 @@
1
+ from typing import Self
2
+
1
3
  from pydantic import BaseModel
2
4
 
3
5
  from goose._internal.result import Result
4
- from goose._internal.types.agent import (
5
- AssistantMessage,
6
- LLMMessage,
7
- SystemMessage,
8
- UserMessage,
9
- )
6
+ from goose._internal.types.agent import AssistantMessage, LLMMessage, SystemMessage, UserMessage
10
7
 
11
8
 
12
9
  class Conversation[R: Result](BaseModel):
@@ -31,3 +28,8 @@ class Conversation[R: Result](BaseModel):
31
28
  messages.append(AssistantMessage(text=self.result_messages[-1].model_dump_json()).render())
32
29
 
33
30
  return messages
31
+
32
+ def undo(self) -> Self:
33
+ self.user_messages.pop()
34
+ self.result_messages.pop()
35
+ return self
goose/_internal/state.py CHANGED
@@ -61,6 +61,17 @@ class NodeState[ResultT: Result](BaseModel):
61
61
  self.conversation.user_messages.append(message)
62
62
  return self
63
63
 
64
+ def edit_last_result(self, *, result: ResultT) -> Self:
65
+ if len(self.conversation.result_messages) == 0:
66
+ raise Honk("Node awaiting response, has no result")
67
+
68
+ self.conversation.result_messages[-1] = result
69
+ return self
70
+
71
+ def undo(self) -> Self:
72
+ self.conversation.undo()
73
+ return self
74
+
64
75
 
65
76
  class FlowRun:
66
77
  def __init__(self) -> None:
@@ -115,7 +126,7 @@ class FlowRun:
115
126
  self._flow_args = args
116
127
  self._flow_kwargs = kwargs
117
128
 
118
- def add_node_state(self, node_state: NodeState[Any], /) -> None:
129
+ def upsert_node_state(self, node_state: NodeState[Any], /) -> None:
119
130
  key = (node_state.task_name, node_state.index)
120
131
  self._node_states[key] = node_state.model_dump_json()
121
132
 
goose/_internal/task.py CHANGED
@@ -59,15 +59,27 @@ class Task[**P, R: Result]:
59
59
 
60
60
  result = await self.__adapt(conversation=node_state.conversation, agent=flow_run.agent)
61
61
  node_state.add_result(result=result)
62
- flow_run.add_node_state(node_state)
62
+ flow_run.upsert_node_state(node_state)
63
63
 
64
64
  return result
65
65
 
66
+ def edit(self, *, result: R, index: int = 0) -> None:
67
+ flow_run = self.__get_current_flow_run()
68
+ node_state = flow_run.get(task=self, index=index)
69
+ node_state.edit_last_result(result=result)
70
+ flow_run.upsert_node_state(node_state)
71
+
72
+ def undo(self, *, index: int = 0) -> None:
73
+ flow_run = self.__get_current_flow_run()
74
+ node_state = flow_run.get(task=self, index=index)
75
+ node_state.undo()
76
+ flow_run.upsert_node_state(node_state)
77
+
66
78
  async def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
67
79
  flow_run = self.__get_current_flow_run()
68
80
  node_state = flow_run.get_next(task=self)
69
81
  result = await self.generate(node_state, *args, **kwargs)
70
- flow_run.add_node_state(node_state)
82
+ flow_run.upsert_node_state(node_state)
71
83
  return result
72
84
 
73
85
  async def __adapt(self, *, conversation: Conversation[R], agent: Agent) -> R:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: goose-py
3
- Version: 0.7.1
3
+ Version: 0.7.3
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
@@ -5,14 +5,14 @@ goose/flow.py,sha256=A1bzNIjnoVXRFm6LGhQglxVnKMP0vEVfvTubTol7Kww,58
5
5
  goose/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  goose/runs.py,sha256=HHcky_IbmY9HWBjpXJgOcH2Ko0N39qADsGIPR8QYpek,160
7
7
  goose/_internal/agent.py,sha256=l0pKfShovrs238sKAr-zubtcacYm82TGwQHcBWVJm2g,5875
8
- goose/_internal/conversation.py,sha256=BiWxWN2W-0fMMLgVRaVYld5_5-AttA3M5KF8JGznVwg,1081
8
+ goose/_internal/conversation.py,sha256=1OZQ_N6QZE7L_ZpXG2bjoWkVQ-G7h0JvKkqswmQWG58,1202
9
9
  goose/_internal/flow.py,sha256=KGT6NpkMY8q_N1yKwWrxfTbhwcu5AwdHtgCPqCdL3F8,3266
10
10
  goose/_internal/result.py,sha256=-eZJn-2sPo7rHZ38Sz6IAHXqiJ-Ss39esEoFGimJEBI,155
11
- goose/_internal/state.py,sha256=dKXSNMVzeM_2h0YuyMatU1I57REAzttuYBJmoUMy3ag,5703
11
+ goose/_internal/state.py,sha256=mXwSkTQq5Y6xLSRgvfUPILmK5nbiA-sp8Nunjcra5n4,6045
12
12
  goose/_internal/store.py,sha256=vIxPIpechF_lEQlQ8JT1NDySDfHe3-eMHEWeTqVbscg,946
13
- goose/_internal/task.py,sha256=cHzS7TTDXruPwXDK8P03zs3HUiJqAXECuPuAM3Oo5Tw,4685
13
+ goose/_internal/task.py,sha256=YoSJdjBxBxJwEXzFnkFDuD9F0A8FvUr-cYvN9xq72qo,5183
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.7.1.dist-info/METADATA,sha256=b_FEa3StNuozZAxU6W_qXdEVzW98W6nLpibqcqNhh9s,441
17
- goose_py-0.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
- goose_py-0.7.1.dist-info/RECORD,,
16
+ goose_py-0.7.3.dist-info/METADATA,sha256=w3bf_pM-AV69T0p7Cq6aa4o_023_kOIc5FoPjjxX7-k,441
17
+ goose_py-0.7.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ goose_py-0.7.3.dist-info/RECORD,,