Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions claude-agent-sdk/listeners/events/app_mentioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from logging import Logger

from slack_bolt.agent.async_agent import AsyncBoltAgent
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Good news, AsyncBoltAgent works!

from slack_bolt.context.say.async_say import AsyncSay
from slack_sdk.web.async_client import AsyncWebClient

Expand All @@ -22,7 +23,11 @@


async def handle_app_mentioned(
client: AsyncWebClient, event: dict, logger: Logger, say: AsyncSay
client: AsyncWebClient,
event: dict,
agent: AsyncBoltAgent,
logger: Logger,
say: AsyncSay,
):
"""Handle @Casey mentions in channels."""
try:
Expand Down Expand Up @@ -73,9 +78,9 @@ async def handle_app_mentioned(
)

# Stream response in thread with feedback buttons
streamer = await client.chat_stream(
streamer = await agent.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_team_id=team_id, # chat_stream helper cannot infer event["team"] from client
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: In Bolt Python, we should fix the helper to resolveevent["team"].

recipient_user_id=user_id,
thread_ts=thread_ts,
)
Expand Down
16 changes: 7 additions & 9 deletions claude-agent-sdk/listeners/events/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
from logging import Logger

from slack_bolt.agent.async_agent import AsyncBoltAgent
from slack_bolt.context.say.async_say import AsyncSay
from slack_sdk.web.async_client import AsyncWebClient

Expand All @@ -21,7 +22,11 @@


async def handle_message(
client: AsyncWebClient, event: dict, logger: Logger, say: AsyncSay
client: AsyncWebClient,
event: dict,
agent: AsyncBoltAgent,
logger: Logger,
say: AsyncSay,
):
"""Handle direct messages sent to Casey."""
# Skip bot messages and message subtypes (edits, deletes, etc.)
Expand All @@ -34,10 +39,8 @@ async def handle_message(

try:
channel_id = event["channel"]
team_id = event.get("team")
text = event.get("text", "")
thread_ts = event.get("thread_ts") or event["ts"]
user_id = event.get("user")

# Get session ID for conversation context
existing_session_id = session_store.get_session(channel_id, thread_ts)
Expand Down Expand Up @@ -70,12 +73,7 @@ async def handle_message(
)

# Stream response in thread with feedback buttons
streamer = await client.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
thread_ts=thread_ts,
)
streamer = await agent.chat_stream()
await streamer.append(markdown_text=response_text)
feedback_blocks = create_feedback_block()
await streamer.stop(blocks=feedback_blocks)
Expand Down
5 changes: 3 additions & 2 deletions claude-agent-sdk/listeners/views/issue_modal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from logging import Logger

from slack_bolt import Ack
from slack_bolt.agent.async_agent import AsyncBoltAgent
from slack_sdk.web.async_client import AsyncWebClient

from agent import run_casey_agent
Expand All @@ -9,7 +10,7 @@


async def handle_issue_submission(
ack: Ack, body: dict, client: AsyncWebClient, logger: Logger
ack: Ack, body: dict, client: AsyncWebClient, agent: AsyncBoltAgent, logger: Logger
):
"""Handle modal submission: open DM, post issue, and run Casey agent."""
await ack()
Expand Down Expand Up @@ -60,7 +61,7 @@ async def handle_issue_submission(
response_text, new_session_id = await run_casey_agent(user_message)

# Stream the response in thread with feedback buttons
streamer = await client.chat_stream(
streamer = await agent.chat_stream(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: issue_modal.py is a poor implementation.

When a user presses a button on the App Home and submit the modal, a DM is sent with the message.

Ideally, the message event handler should stream a response.

However, currently the response is handled inside the issue_modal.py (here) because the message event filters out all bot messages. Since we're in the App Home / Issue Modal Submission, there is no channel or thread. So, chat_stream() has no hope of resolving it.

The good news is that we can still provide the arguments required to customize it. So that's working well!

channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
Expand Down
10 changes: 6 additions & 4 deletions openai-agents-sdk/listeners/events/app_mentioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from logging import Logger

from agents import Runner
from slack_bolt import Say
from slack_bolt import BoltAgent, Say
from slack_sdk import WebClient

from agent import CaseyDeps, casey_agent
Expand All @@ -22,7 +22,9 @@
CONTEXTUAL_EMOJIS = ["+1", "raised_hands", "rocket", "tada", "bulb", "fire"]


def handle_app_mentioned(client: WebClient, event: dict, logger: Logger, say: Say):
def handle_app_mentioned(
client: WebClient, event: dict, agent: BoltAgent, logger: Logger, say: Say
):
"""Handle @Casey mentions in channels."""
try:
channel_id = event["channel"]
Expand Down Expand Up @@ -81,9 +83,9 @@ def handle_app_mentioned(client: WebClient, event: dict, logger: Logger, say: Sa
result = Runner.run_sync(casey_agent, input=input_items, context=deps)

# Stream response in thread with feedback buttons
streamer = client.chat_stream(
streamer = agent.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_team_id=team_id, # chat_stream helper cannot infer event["team"] from client
recipient_user_id=user_id,
thread_ts=thread_ts,
)
Expand Down
14 changes: 5 additions & 9 deletions openai-agents-sdk/listeners/events/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import Logger

from agents import Runner
from slack_bolt import Say
from slack_bolt import BoltAgent, Say
from slack_sdk import WebClient

from agent import CaseyDeps, casey_agent
Expand All @@ -21,7 +21,9 @@
CONTEXTUAL_EMOJIS = ["+1", "raised_hands", "rocket", "tada", "bulb", "fire"]


def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):
def handle_message(
client: WebClient, event: dict, agent: BoltAgent, logger: Logger, say: Say
):
"""Handle direct messages sent to Casey."""
# Skip bot messages and message subtypes (edits, deletes, etc.)
if event.get("bot_id") or event.get("subtype"):
Expand All @@ -33,7 +35,6 @@ def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):

try:
channel_id = event["channel"]
team_id = event.get("team")
text = event.get("text", "")
thread_ts = event.get("thread_ts") or event["ts"]
user_id = event["user"]
Expand Down Expand Up @@ -79,12 +80,7 @@ def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):
result = Runner.run_sync(casey_agent, input=input_items, context=deps)

# Stream response in thread with feedback buttons
streamer = client.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
thread_ts=thread_ts,
)
streamer = agent.chat_stream()
streamer.append(markdown_text=result.final_output)
feedback_blocks = create_feedback_block()
streamer.stop(blocks=feedback_blocks)
Expand Down
8 changes: 5 additions & 3 deletions openai-agents-sdk/listeners/views/issue_modal.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from logging import Logger

from agents import Runner
from slack_bolt import Ack
from slack_bolt import Ack, BoltAgent
from slack_sdk import WebClient

from agent import CaseyDeps, casey_agent
from conversation import conversation_store
from listeners.views.feedback_block import create_feedback_block


def handle_issue_submission(ack: Ack, body: dict, client: WebClient, logger: Logger):
def handle_issue_submission(
ack: Ack, body: dict, client: WebClient, agent: BoltAgent, logger: Logger
):
"""Handle modal submission: open DM, post issue, and run Casey agent."""
ack()

Expand Down Expand Up @@ -65,7 +67,7 @@ def handle_issue_submission(ack: Ack, body: dict, client: WebClient, logger: Log
result = Runner.run_sync(casey_agent, input=user_message, context=deps)

# Stream the response in thread with feedback buttons
streamer = client.chat_stream(
streamer = agent.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
Expand Down
10 changes: 6 additions & 4 deletions pydantic-ai/listeners/events/app_mentioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from logging import Logger

from slack_bolt import Say
from slack_bolt import BoltAgent, Say
from slack_sdk import WebClient

from agent import DEFAULT_MODEL, CaseyDeps, casey_agent
Expand All @@ -21,7 +21,9 @@
CONTEXTUAL_EMOJIS = ["+1", "raised_hands", "rocket", "tada", "bulb", "fire"]


def handle_app_mentioned(client: WebClient, event: dict, logger: Logger, say: Say):
def handle_app_mentioned(
client: WebClient, event: dict, agent: BoltAgent, logger: Logger, say: Say
):
"""Handle @Casey mentions in channels."""
try:
channel_id = event["channel"]
Expand Down Expand Up @@ -80,9 +82,9 @@ def handle_app_mentioned(client: WebClient, event: dict, logger: Logger, say: Sa
)

# Stream response in thread with feedback buttons
streamer = client.chat_stream(
streamer = agent.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_team_id=team_id, # chat_stream helper cannot infer event["team"] from client
recipient_user_id=user_id,
thread_ts=thread_ts,
)
Expand Down
14 changes: 5 additions & 9 deletions pydantic-ai/listeners/events/message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
from logging import Logger

from slack_bolt import Say
from slack_bolt import BoltAgent, Say
from slack_sdk import WebClient

from agent import DEFAULT_MODEL, CaseyDeps, casey_agent
Expand All @@ -20,7 +20,9 @@
CONTEXTUAL_EMOJIS = ["+1", "raised_hands", "rocket", "tada", "bulb", "fire"]


def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):
def handle_message(
client: WebClient, event: dict, agent: BoltAgent, logger: Logger, say: Say
):
"""Handle direct messages sent to Casey."""
# Skip bot messages and message subtypes (edits, deletes, etc.)
if event.get("bot_id") or event.get("subtype"):
Expand All @@ -32,7 +34,6 @@ def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):

try:
channel_id = event["channel"]
team_id = event.get("team")
text = event.get("text", "")
thread_ts = event.get("thread_ts") or event["ts"]
user_id = event["user"]
Expand Down Expand Up @@ -77,12 +78,7 @@ def handle_message(client: WebClient, event: dict, logger: Logger, say: Say):
)

# Stream response in thread with feedback buttons
streamer = client.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
thread_ts=thread_ts,
)
streamer = agent.chat_stream()
streamer.append(markdown_text=result.output)
feedback_blocks = create_feedback_block()
streamer.stop(blocks=feedback_blocks)
Expand Down
8 changes: 5 additions & 3 deletions pydantic-ai/listeners/views/issue_modal.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from logging import Logger

from slack_bolt import Ack
from slack_bolt import Ack, BoltAgent
from slack_sdk import WebClient

from agent import DEFAULT_MODEL, CaseyDeps, casey_agent
from conversation import conversation_store
from listeners.views.feedback_block import create_feedback_block


def handle_issue_submission(ack: Ack, body: dict, client: WebClient, logger: Logger):
def handle_issue_submission(
ack: Ack, body: dict, client: WebClient, agent: BoltAgent, logger: Logger
):
"""Handle modal submission: open DM, post issue, and run Casey agent."""
ack()

Expand Down Expand Up @@ -64,7 +66,7 @@ def handle_issue_submission(ack: Ack, body: dict, client: WebClient, logger: Log
result = casey_agent.run_sync(user_message, model=DEFAULT_MODEL, deps=deps)

# Stream the response in thread with feedback buttons
streamer = client.chat_stream(
streamer = agent.chat_stream(
channel=channel_id,
recipient_team_id=team_id,
recipient_user_id=user_id,
Expand Down