goose-py 0.7.1__tar.gz → 0.7.2__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 (35) hide show
  1. {goose_py-0.7.1 → goose_py-0.7.2}/PKG-INFO +1 -1
  2. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/conversation.py +8 -6
  3. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/state.py +4 -0
  4. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/task.py +6 -0
  5. {goose_py-0.7.1 → goose_py-0.7.2}/pyproject.toml +1 -1
  6. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_state.py +31 -0
  7. {goose_py-0.7.1 → goose_py-0.7.2}/uv.lock +1 -1
  8. {goose_py-0.7.1 → goose_py-0.7.2}/.envrc +0 -0
  9. {goose_py-0.7.1 → goose_py-0.7.2}/.github/workflows/publish.yml +0 -0
  10. {goose_py-0.7.1 → goose_py-0.7.2}/.gitignore +0 -0
  11. {goose_py-0.7.1 → goose_py-0.7.2}/.python-version +0 -0
  12. {goose_py-0.7.1 → goose_py-0.7.2}/.stubs/jsonpath_ng/__init__.pyi +0 -0
  13. {goose_py-0.7.1 → goose_py-0.7.2}/.stubs/litellm/__init__.pyi +0 -0
  14. {goose_py-0.7.1 → goose_py-0.7.2}/Makefile +0 -0
  15. {goose_py-0.7.1 → goose_py-0.7.2}/README.md +0 -0
  16. {goose_py-0.7.1 → goose_py-0.7.2}/goose/__init__.py +0 -0
  17. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/agent.py +0 -0
  18. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/flow.py +0 -0
  19. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/result.py +0 -0
  20. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/store.py +0 -0
  21. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/types/__init__.py +0 -0
  22. {goose_py-0.7.1 → goose_py-0.7.2}/goose/_internal/types/agent.py +0 -0
  23. {goose_py-0.7.1 → goose_py-0.7.2}/goose/agent.py +0 -0
  24. {goose_py-0.7.1 → goose_py-0.7.2}/goose/errors.py +0 -0
  25. {goose_py-0.7.1 → goose_py-0.7.2}/goose/flow.py +0 -0
  26. {goose_py-0.7.1 → goose_py-0.7.2}/goose/py.typed +0 -0
  27. {goose_py-0.7.1 → goose_py-0.7.2}/goose/runs.py +0 -0
  28. {goose_py-0.7.1 → goose_py-0.7.2}/tests/__init__.py +0 -0
  29. {goose_py-0.7.1 → goose_py-0.7.2}/tests/conftest.py +0 -0
  30. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_agent.py +0 -0
  31. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_complex_flow_arguments.py +0 -0
  32. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_downstream_task.py +0 -0
  33. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_jamming.py +0 -0
  34. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_looping.py +0 -0
  35. {goose_py-0.7.1 → goose_py-0.7.2}/tests/test_regenerate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: goose-py
3
- Version: 0.7.1
3
+ Version: 0.7.2
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
@@ -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
@@ -61,6 +61,10 @@ class NodeState[ResultT: Result](BaseModel):
61
61
  self.conversation.user_messages.append(message)
62
62
  return self
63
63
 
64
+ def undo(self) -> Self:
65
+ self.conversation.undo()
66
+ return self
67
+
64
68
 
65
69
  class FlowRun:
66
70
  def __init__(self) -> None:
@@ -63,6 +63,12 @@ class Task[**P, R: Result]:
63
63
 
64
64
  return result
65
65
 
66
+ def undo(self, *, 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.undo()
70
+ flow_run.add_node_state(node_state)
71
+
66
72
  async def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
67
73
  flow_run = self.__get_current_flow_run()
68
74
  node_state = flow_run.get_next(task=self)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "goose-py"
3
- version = "0.7.1"
3
+ version = "0.7.2"
4
4
  description = "A tool for AI workflows based on human-computer collaboration and structured output."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -1,9 +1,12 @@
1
1
  import random
2
2
  import string
3
+ from unittest.mock import Mock
3
4
 
4
5
  import pytest
6
+ from pytest_mock import MockerFixture
5
7
 
6
8
  from goose import Result, flow, task
9
+ from goose._internal.types.agent import SystemMessage, TextMessagePart, UserMessage
7
10
  from goose.errors import Honk
8
11
 
9
12
 
@@ -20,6 +23,15 @@ async def generate_random_word(*, n_characters: int) -> GeneratedWord:
20
23
  return GeneratedWord(word="".join(random.sample(string.ascii_lowercase, n_characters)))
21
24
 
22
25
 
26
+ @pytest.fixture
27
+ def generate_random_word_adapter(mocker: MockerFixture) -> Mock:
28
+ return mocker.patch.object(
29
+ generate_random_word,
30
+ "_Task__adapt",
31
+ return_value=GeneratedWord(word="__ADAPTED__"),
32
+ )
33
+
34
+
23
35
  @task
24
36
  async def make_sentence(*, words: list[GeneratedWord]) -> GeneratedSentence:
25
37
  return GeneratedSentence(sentence=" ".join([word.word for word in words]))
@@ -47,3 +59,22 @@ async def test_state_causes_caching() -> None:
47
59
  new_random_word = new_run.get(task=generate_random_word).result.word
48
60
 
49
61
  assert random_word == new_random_word # unchanged node is not re-generated
62
+
63
+
64
+ @pytest.mark.asyncio
65
+ @pytest.mark.usefixtures("generate_random_word_adapter")
66
+ async def test_state_undo() -> None:
67
+ async with with_state.start_run(run_id="2"):
68
+ await with_state.generate()
69
+
70
+ async with with_state.start_run(run_id="2"):
71
+ await generate_random_word.jam(
72
+ index=0,
73
+ user_message=UserMessage(parts=[TextMessagePart(text="Change it")]),
74
+ context=SystemMessage(parts=[TextMessagePart(text="Extra info")]),
75
+ )
76
+
77
+ async with with_state.start_run(run_id="2") as run:
78
+ generate_random_word.undo()
79
+
80
+ assert run.get(task=generate_random_word).result.word != "__ADAPTED__"
@@ -234,7 +234,7 @@ wheels = [
234
234
 
235
235
  [[package]]
236
236
  name = "goose-py"
237
- version = "0.7.1"
237
+ version = "0.7.2"
238
238
  source = { editable = "." }
239
239
  dependencies = [
240
240
  { name = "jsonpath-ng" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes