Skip to content

Commit

Permalink
Merge pull request #991 from PrefectHQ/controlflow-docs
Browse files Browse the repository at this point in the history
add controlflow tool
  • Loading branch information
zzstoatzz authored Nov 4, 2024
2 parents bab41dd + 45ff8ae commit 8d1a51a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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)",
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions cookbook/slackbot/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ 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 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.
"""
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"
Expand Down

0 comments on commit 8d1a51a

Please sign in to comment.