Describe the Bug:
In an application created using agents-cli, SlackRunner was configured in fast_api_app.py as shown in the code snippet below. While the application starts up and runs without any initial issues, sending a message from Slack triggers a validation error: ValueError: Invalid session_id 'C0BARCEJJ1K-1784622590.251599': must match ^[A-Za-z0-9_-]+$.
This issue occurs because SlackRunner automatically generates a session_id in the format of ChannelID-Timestamp (e.g., C0BARCEJJ1K-1784622043.820949) to keep track of the thread's conversation context. Because this generated ID contains a decimal point (.), it violates the regex validation pattern ^[A-Za-z0-9_-]+$ enforced by the session service, raising a ValueError.
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
from app.agent import app as adk_app
from app.agent import slack_root_agent
runner = Runner(
app=adk_app,
session_service=services.get_session_service(),
artifact_service=services.get_artifact_service(),
auto_create_session=True,
)
# Shared by the A2A path and the reasoning_engine adapter routes.
app.state.runner = runner
app.state.agent_app_name = adk_app.name
await attach_a2a_routes(
app,
agent=slack_root_agent,
runner=runner,
task_store=InMemoryTaskStore(),
rpc_path=f"/a2a/{adk_app.name}",
)
# 2. SlackRunner Initialization and Execution
slack_task = None
slack_bot_token = os.getenv("SLACK_BOT_TOKEN")
slack_app_token = os.getenv("SLACK_APP_TOKEN")
if slack_bot_token and slack_app_token:
slack_app = AsyncApp(token=slack_bot_token)
slack_runner = SlackRunner(slack_app=slack_app, runner=runner)
# We launch SlackRunner as a background task so it does not block FastAPI startup
slack_task = asyncio.create_task(
slack_runner.start(app_token=slack_app_token)
)
logger.log_text("SlackRunner started successfully in background.", severity="INFO")
else:
logger.log_text("Slack tokens missing; SlackRunner skipped.", severity="WARNING")
yield
Steps to Reproduce:
- Initialize a new project: agents-cli create --adk
- Add and configure SlackRunner in fast_api_app.py
- Run the application locally: uv run uvicorn app.fast_api_app:app --host 0.0.0.0 --port 8080
- Send a message to the bot in Slack (e.g., @slack_app Hi)
Expected Behavior:
The Root Agent should successfully process the incoming Slack event and respond normally in the channel or thread without throwing any errors.
Observed Behavior:
An error is raised immediately upon receiving a message, preventing the agent from responding. Below is the traceback captured in the logs:
⚡️ Bolt app is running!
ERROR:google_adk.google.adk.integrations.slack.slack_runner:Error running ADK agent for Slack:
Traceback (most recent call last):
File "/Users/iloh/source/slack-adk-agent/slack-agent/.venv/lib/python3.12/site-packages/google/adk/integrations/slack/slack_runner.py", line 86, in _handle_message
async for run_event in self.runner.run_async(
File "/Users/iloh/source/slack-adk-agent/slack-agent/.venv/lib/python3.12/site-packages/google/adk/runners.py", line 1074, in run_async
session = await self._get_or_create_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iloh/source/slack-adk-agent/slack-agent/.venv/lib/python3.12/site-packages/google/adk/runners.py", line 939, in _get_or_create_session
session = await self.session_service.get_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iloh/source/slack-adk-agent/slack-agent/.venv/lib/python3.12/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 232, in get_session
_validate_session_id(session_id)
File "/Users/iloh/source/slack-adk-agent/slack-agent/.venv/lib/python3.12/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 81, in _validate_session_id
raise ValueError(
ValueError: Invalid session_id 'C0BARCEJJ1K-1784622590.251599': must match ^[A-Za-z0-9_-]+$.
Environment Details:
- ADK Library Version (pip show google-adk): 2.5.0
- Desktop OS:macOS
- Python Version (python -V): 3.12.7
Model Information:
- Are you using LiteLLM: No
- Which model is being used: (e.g., gemini-3.5-flash)
Describe the Bug:
In an application created using agents-cli, SlackRunner was configured in fast_api_app.py as shown in the code snippet below. While the application starts up and runs without any initial issues, sending a message from Slack triggers a validation error: ValueError: Invalid session_id 'C0BARCEJJ1K-1784622590.251599': must match ^[A-Za-z0-9_-]+$.
This issue occurs because SlackRunner automatically generates a session_id in the format of ChannelID-Timestamp (e.g., C0BARCEJJ1K-1784622043.820949) to keep track of the thread's conversation context. Because this generated ID contains a decimal point (.), it violates the regex validation pattern ^[A-Za-z0-9_-]+$ enforced by the session service, raising a ValueError.
Steps to Reproduce:
Expected Behavior:
The Root Agent should successfully process the incoming Slack event and respond normally in the channel or thread without throwing any errors.
Observed Behavior:
An error is raised immediately upon receiving a message, preventing the agent from responding. Below is the traceback captured in the logs:
Environment Details:
Model Information: