From 89d464c305db3541ccf20a3b9e015d7be3bd4f6c Mon Sep 17 00:00:00 2001 From: Ebony Louis <55366651+EbonyLouis@users.noreply.github.com> Date: Fri, 17 Jan 2025 09:00:38 -0500 Subject: [PATCH] docs: updating guides to provide more clarity around moderator (#628) --- docs/configuration.md | 3 +++ docs/plugins/providers.md | 11 ++++++++++- packages/exchange/src/exchange/providers/bedrock.py | 2 +- packages/exchange/tests/test_summarizer.py | 6 +++--- src/goose/cli/prompt/lexer.py | 2 +- src/goose/synopsis/toolkit.py | 6 +++--- src/goose/toolkit/lint.py | 12 ++++++------ tests/toolkit/test_utils.py | 11 ++--------- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index a322ec12..c2df7978 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -40,6 +40,9 @@ Rules designed to control or manage the output of the model. Moderators that cur - `passive`: does not actively intervene in every response - `truncate`: truncates the first contexts when the contexts exceed the max token size +- `synopsis`: instead of truncating, it uses LLMs to summarize and condense context dynamically, keeping relevant information while staying under the token limit. + +> **Important:** `synopsis` only works when the `synopsis` toolkit is enabled. Be sure to update your [`profile.yml` configurations](https://block.github.io/goose/guidance/getting-started.html#configuring-goose-with-the-profilesyaml-file) to enable both. #### toolkits diff --git a/docs/plugins/providers.md b/docs/plugins/providers.md index 719ef084..1cdf0e00 100644 --- a/docs/plugins/providers.md +++ b/docs/plugins/providers.md @@ -23,7 +23,12 @@ default: provider: anthropic processor: claude-3-5-sonnet-20241022 accelerator: claude-3-5-sonnet-20241022 + moderator: synopsis + toolkits: + - name: synopsis + requires: {} ``` +> **Important** Anthropic performs the best when both the `synopsis` toolkit and moderator are enabled. ### Azure @@ -68,8 +73,12 @@ default: provider: google processor: gemini-1.5-flash accelerator: gemini-1.5-flash + moderator: truncate + toolkits: + - name: developer + requires: {} ``` - +> **Important** Gemini performs the best when both the `developer` toolkit and `truncate` moderator are enabled. ### Ollama For Ollama, refer to the setup process on [Ollama's site](https://ollama.com/) for obtaining necessary credentials. Make sure your environment has all the required tokens set up. diff --git a/packages/exchange/src/exchange/providers/bedrock.py b/packages/exchange/src/exchange/providers/bedrock.py index f766c8d1..2fe4c88c 100644 --- a/packages/exchange/src/exchange/providers/bedrock.py +++ b/packages/exchange/src/exchange/providers/bedrock.py @@ -119,7 +119,7 @@ class AwsClient(httpx.Client): credential_scope = f"{date_stamp}/{self.region}/{service}/aws4_request" string_to_sign = ( f"{algorithm}\n{amz_date}\n{credential_scope}\n" - f'{hashlib.sha256(canonical_request.encode("utf-8")).hexdigest()}' + f"{hashlib.sha256(canonical_request.encode('utf-8')).hexdigest()}" ) # Create the signing key diff --git a/packages/exchange/tests/test_summarizer.py b/packages/exchange/tests/test_summarizer.py index 7920fe31..0e6ccbe6 100644 --- a/packages/exchange/tests/test_summarizer.py +++ b/packages/exchange/tests/test_summarizer.py @@ -75,9 +75,9 @@ def test_context_summarizer_rewrite(exchange_instance: Exchange, summarizer_inst # Ensure roles alternate in the output for i in range(1, len(exchange_instance.messages)): - assert ( - exchange_instance.messages[i - 1].role != exchange_instance.messages[i].role - ), "Messages must alternate between user and assistant" + assert exchange_instance.messages[i - 1].role != exchange_instance.messages[i].role, ( + "Messages must alternate between user and assistant" + ) MESSAGE_SEQUENCE = [ diff --git a/src/goose/cli/prompt/lexer.py b/src/goose/cli/prompt/lexer.py index e00fd207..41ac4396 100644 --- a/src/goose/cli/prompt/lexer.py +++ b/src/goose/cli/prompt/lexer.py @@ -13,7 +13,7 @@ from prompt_toolkit.lexers import Lexer def completion_for_command(target_string: str) -> re.Pattern[str]: escaped_string = re.escape(target_string) vals = [f"(?:{escaped_string[:i]}(?=$))" for i in range(len(escaped_string), 0, -1)] - return re.compile(rf'(? re.Pattern[str]: diff --git a/src/goose/synopsis/toolkit.py b/src/goose/synopsis/toolkit.py index ea9b88c2..2bf70426 100644 --- a/src/goose/synopsis/toolkit.py +++ b/src/goose/synopsis/toolkit.py @@ -46,9 +46,9 @@ class SynopsisDeveloper(Toolkit): working_dir (str, optional): The directory to change to. source_path (str, optional): The file to source before running the command. """ - assert any( - [command, working_dir, source_path] - ), "At least one of the parameters for bash shell must be provided." + assert any([command, working_dir, source_path]), ( + "At least one of the parameters for bash shell must be provided." + ) bash_tool = Bash(notifier=self.notifier, exchange_view=self.exchange_view) outputs = [] diff --git a/src/goose/toolkit/lint.py b/src/goose/toolkit/lint.py index a12335c7..6b30c28d 100644 --- a/src/goose/toolkit/lint.py +++ b/src/goose/toolkit/lint.py @@ -7,9 +7,9 @@ def lint_toolkits() -> None: first_line_of_docstring = toolkit.__doc__.split("\n")[0] assert len(first_line_of_docstring.split(" ")) > 5, f"`{toolkit_name}` toolkit docstring is too short" assert len(first_line_of_docstring.split(" ")) < 12, f"`{toolkit_name}` toolkit docstring is too long" - assert first_line_of_docstring[ - 0 - ].isupper(), f"`{toolkit_name}` toolkit docstring must start with a capital letter" + assert first_line_of_docstring[0].isupper(), ( + f"`{toolkit_name}` toolkit docstring must start with a capital letter" + ) def lint_providers() -> None: @@ -18,6 +18,6 @@ def lint_providers() -> None: first_line_of_docstring = provider.__doc__.split("\n")[0] assert len(first_line_of_docstring.split(" ")) > 5, f"`{provider_name}` provider docstring is too short" assert len(first_line_of_docstring.split(" ")) < 20, f"`{provider_name}` provider docstring is too long" - assert first_line_of_docstring[ - 0 - ].isupper(), f"`{provider_name}` provider docstring must start with a capital letter" + assert first_line_of_docstring[0].isupper(), ( + f"`{provider_name}` provider docstring must start with a capital letter" + ) diff --git a/tests/toolkit/test_utils.py b/tests/toolkit/test_utils.py index b5b45ac9..b4cd22da 100644 --- a/tests/toolkit/test_utils.py +++ b/tests/toolkit/test_utils.py @@ -2,14 +2,7 @@ from goose.toolkit.utils import parse_plan def test_parse_plan_simple(): - plan_str = ( - "Here is python repo\n" - "-use uv\n" - "-do not use poetry\n\n" - "Now you should:\n\n" - "-Open a file\n" - "-Run a test" - ) + plan_str = "Here is python repo\n-use uv\n-do not use poetry\n\nNow you should:\n\n-Open a file\n-Run a test" expected_result = { "kickoff_message": "Here is python repo\n-use uv\n-do not use poetry\n\nNow you should:", "tasks": ["Open a file", "Run a test"], @@ -57,7 +50,7 @@ def test_parse_plan_empty_kickoff_message(): def test_parse_plan_with_numbers(): - plan_str = "Here is python repo\n" "Now you should:\n\n" "-1 Open a file\n" "-2 Run a test" + plan_str = "Here is python repo\nNow you should:\n\n-1 Open a file\n-2 Run a test" expected_result = { "kickoff_message": "Here is python repo\nNow you should:", "tasks": ["1 Open a file", "2 Run a test"],