Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Agents & Assistants support #1162

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

seratch
Copy link
Member

@seratch seratch commented Sep 17, 2024

This pull request adds the newly added assistant feature to bolt-python. Our teram is still working on the design, so some of the details may be adjusted before merging. This PR relies on https://github.com/slackapi/python-slack-sdk/releases/tag/v3.33.1

assistant = Assistant()
# You can use your own thread_context_store if you want
# from slack_bolt.slack_sdk_assistant.thread_context_store import FileAssistantThreadContextStore
# assistant = Assistant(thread_context_store=FileAssistantThreadContextStore())

@assistant.thread_started
def start_thread(say: Say, set_suggested_prompts: SetSuggestedPrompts):
    say(":wave: Hi, how can I help you today?")
    set_suggested_prompts(
        prompts=[
            "What does SLACK stand for?",
            "When Slack was released?",
        ],
    )

@assistant.user_message
def answer_inquiries(
    payload: dict,
    logger: logging.Logger,
    set_title: SetTitle,
    set_status: SetStatus,
    say: Say,
    get_thread_context: GetThreadContext,
):
    try:
        set_title(payload["text"])
        set_status("Typing...")
        time.sleep(0.3)
        set_status("Still typing...")
        time.sleep(0.3)
        thread_context = get_thread_context()
        if thread_context is not None:
            channel = thread_context.channel_id
            say(f"Ah, you're referring to <#{channel}>! Do you need help with the channel?")
        else:
            say("Here you are! blah-blah-blah...")
    except Exception as e:
        logger.exception(f"Failed to respond to an inquiry: {e}")
        say(f":warning: Sorry, something went wrong during processing your request (error: {e})")

app.use(assistant)

Category (place an x in each of the [ ])

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements (place an x in each [ ])

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

@seratch seratch added this to the 1.21.0 milestone Sep 17, 2024
@seratch seratch self-assigned this Sep 17, 2024
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 81.87067% with 157 lines in your changes missing coverage. Please review.

Project coverage is 90.85%. Comparing base (35842a5) to head (bfd73cf).

Files with missing lines Patch % Lines
slack_bolt/middleware/assistant/assistant.py 65.90% 45 Missing ⚠️
slack_bolt/middleware/assistant/async_assistant.py 65.64% 45 Missing ⚠️
...xt/assistant/thread_context_store/file/__init__.py 37.03% 17 Missing ⚠️
...istant/thread_context_store/default_async_store.py 74.07% 7 Missing ⚠️
...xt/assistant/thread_context_store/default_store.py 74.07% 7 Missing ⚠️
slack_bolt/request/payload_utils.py 78.57% 6 Missing ⚠️
slack_bolt/request/internals.py 78.94% 4 Missing ⚠️
...lack_bolt/context/assistant/assistant_utilities.py 95.91% 2 Missing ⚠️
...olt/context/assistant/async_assistant_utilities.py 96.07% 2 Missing ⚠️
...text/assistant/thread_context_store/async_store.py 71.42% 2 Missing ⚠️
... and 15 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1162      +/-   ##
==========================================
- Coverage   92.02%   90.85%   -1.17%     
==========================================
  Files         195      221      +26     
  Lines        6631     7491     +860     
==========================================
+ Hits         6102     6806     +704     
- Misses        529      685     +156     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant