Skip to content

Commit 721b634

Browse files
committed
fix: only construct agent when explicitly requested as a listener argument
1 parent f10f94d commit 721b634

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

slack_bolt/kwargs_injection/async_utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def build_async_required_kwargs(
8686
all_available_args[k] = v
8787

8888
# Defer agent creation to avoid constructing AsyncBoltAgent on every request
89-
if "agent" in required_arg_names or "args" in required_arg_names:
89+
if "agent" in required_arg_names:
9090
from slack_bolt.agent.async_agent import AsyncBoltAgent
9191

9292
all_available_args["agent"] = AsyncBoltAgent(
@@ -96,12 +96,11 @@ def build_async_required_kwargs(
9696
team_id=request.context.team_id,
9797
user_id=request.context.user_id,
9898
)
99-
if "agent" in required_arg_names:
100-
warnings.warn(
101-
"The agent listener argument is experimental and may change in future versions.",
102-
category=ExperimentalWarning,
103-
stacklevel=2, # Point to the caller, not this internal helper
104-
)
99+
warnings.warn(
100+
"The agent listener argument is experimental and may change in future versions.",
101+
category=ExperimentalWarning,
102+
stacklevel=2, # Point to the caller, not this internal helper
103+
)
105104

106105
if len(required_arg_names) > 0:
107106
# To support instance/class methods in a class for listeners/middleware,

slack_bolt/kwargs_injection/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def build_required_kwargs(
8585
all_available_args[k] = v
8686

8787
# Defer agent creation to avoid constructing BoltAgent on every request
88-
if "agent" in required_arg_names or "args" in required_arg_names:
88+
if "agent" in required_arg_names:
8989
from slack_bolt.agent.agent import BoltAgent
9090

9191
all_available_args["agent"] = BoltAgent(
@@ -95,12 +95,11 @@ def build_required_kwargs(
9595
team_id=request.context.team_id,
9696
user_id=request.context.user_id,
9797
)
98-
if "agent" in required_arg_names:
99-
warnings.warn(
100-
"The agent listener argument is experimental and may change in future versions.",
101-
category=ExperimentalWarning,
102-
stacklevel=2, # Point to the caller, not this internal helper
103-
)
98+
warnings.warn(
99+
"The agent listener argument is experimental and may change in future versions.",
100+
category=ExperimentalWarning,
101+
stacklevel=2, # Point to the caller, not this internal helper
102+
)
104103

105104
if len(required_arg_names) > 0:
106105
# To support instance/class methods in a class for listeners/middleware,

0 commit comments

Comments
 (0)