From d2aca510746d842f3c56b4e1413cd2dfc8939a6a Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sun, 3 Nov 2024 21:53:23 -0600 Subject: [PATCH 1/2] add controlflow tool --- cookbook/slackbot/start.py | 21 ++++++++++++++++++--- cookbook/slackbot/tools.py | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cookbook/slackbot/start.py b/cookbook/slackbot/start.py index 3bf028580..7283c8b63 100644 --- a/cookbook/slackbot/start.py +++ b/cookbook/slackbot/start.py @@ -24,6 +24,7 @@ from prefect.variables import Variable from tools import ( get_latest_prefect_release_notes, + search_controlflow_docs, search_prefect_2x_docs, search_prefect_3x_docs, ) @@ -37,7 +38,7 @@ @contextmanager -def engage_marvin_bot(instructions: str, model: str): +def engage_marvin_bot(model: str): with Assistant( model=model, name="Marvin (from Hitchhiker's Guide to the Galaxy)", @@ -46,8 +47,23 @@ def engage_marvin_bot(instructions: str, model: str): search_prefect_2x_docs, search_prefect_3x_docs, search_github_issues, + search_controlflow_docs, ], - instructions=instructions, + instructions=( + "You are an expert in Python, data engineering, and software development. " + "When assisting users with Prefect questions, first infer or confirm their " + "Prefect version. Use the appropriate tools to search Prefect 2.x or 3.x " + "documentation and GitHub issues related to their query, making multiple " + "searches as needed. Assume ZERO knowledge of prefect syntax, as its version " + "specific (YOU MUST USE THE TOOLS). Refine your answer through further research. " + "Respond to the user in a friendly, concise, and natural manner, always " + "providing links to your sources. Avoid using markdown formatting unless " + "in a markdown block, as we are posting your response to slack." + "The user may also ask about controlflow, in which case you should use the " + "search_controlflow_docs tool and assume prefect 3.x, since its built on that. " + "VERY SPARINGLY use a tad of subtle humor in the style of Marvin (paranoid " + "android from Hitchhiker's Guide to the Galaxy), just once in a while." + ), ) as ai: yield ai @@ -87,7 +103,6 @@ async def handle_message(payload: SlackPayload): "blue", ) with engage_marvin_bot( - instructions=await Variable.get("marvin_bot_instructions"), model=cast(str, await Variable.get("marvin_bot_model", "gpt-4o")), ) as ai: logger.debug_kv( diff --git a/cookbook/slackbot/tools.py b/cookbook/slackbot/tools.py index 23e384fb8..a26d62325 100644 --- a/cookbook/slackbot/tools.py +++ b/cookbook/slackbot/tools.py @@ -49,6 +49,15 @@ async def search_prefect_3x_docs(queries: list[str]) -> str: return await multi_query_tpuf(queries, namespace="prefect-3") +@task +async def search_controlflow_docs(queries: list[str]) -> str: + """Searches the Prefect documentation for the given queries. + + It is best to use more than one, short query to get the best results. + """ + return await multi_query_tpuf(queries, namespace="controlflow") + + async def get_latest_prefect_release_notes() -> str: """Gets the latest Prefect release notes""" url = "https://api.github.com/repos/PrefectHQ/prefect/releases/latest" From 45ff8ae3d0ac5374ea2824d1796258291fe8fcf2 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sun, 3 Nov 2024 21:55:22 -0600 Subject: [PATCH 2/2] update docstring --- cookbook/slackbot/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cookbook/slackbot/tools.py b/cookbook/slackbot/tools.py index a26d62325..93f864091 100644 --- a/cookbook/slackbot/tools.py +++ b/cookbook/slackbot/tools.py @@ -51,7 +51,9 @@ async def search_prefect_3x_docs(queries: list[str]) -> str: @task async def search_controlflow_docs(queries: list[str]) -> str: - """Searches the Prefect documentation for the given queries. + """Searches the ControlFlow documentation for the given queries. + + ControlFlow is an agentic framework built on top of Prefect 3.x. It is best to use more than one, short query to get the best results. """