Skip to content

Commit dcb086a

Browse files
authored
Merge branch 'main' into fix-issue-1641-database-session-service
2 parents f48e075 + 4e765ae commit dcb086a

33 files changed

+8777
-339
lines changed

.github/workflows/pr-commit-check.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# .github/workflows/pr-commit-check.yml
2+
# This GitHub Action workflow checks if a pull request has more than one commit.
3+
# If it does, it fails the check and instructs the user to squash their commits.
4+
5+
name: 'PR Commit Check'
6+
7+
# This workflow runs on pull request events.
8+
# It's configured to run on any pull request that is opened or synchronized (new commits pushed).
9+
on:
10+
pull_request:
11+
types: [opened, synchronize]
12+
13+
# Defines the jobs that will run as part of the workflow.
14+
jobs:
15+
check-commit-count:
16+
# The type of runner that the job will run on. 'ubuntu-latest' is a good default.
17+
runs-on: ubuntu-latest
18+
19+
# The steps that will be executed as part of the job.
20+
steps:
21+
# Step 1: Check out the code
22+
# This action checks out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
23+
- name: Checkout Code
24+
uses: actions/checkout@v4
25+
with:
26+
# We need to fetch all commits to accurately count them.
27+
# '0' means fetch all history for all branches and tags.
28+
fetch-depth: 0
29+
30+
# Step 2: Count the commits in the pull request
31+
# This step runs a script to get the number of commits in the PR.
32+
- name: Count Commits
33+
id: count_commits
34+
# We use `git rev-list --count` to count the commits.
35+
# ${{ github.event.pull_request.base.sha }} is the commit SHA of the base branch.
36+
# ${{ github.event.pull_request.head.sha }} is the commit SHA of the head branch (the PR branch).
37+
# The '..' syntax gives us the list of commits in the head branch that are not in the base branch.
38+
# The output of the command (the count) is stored in a step output variable named 'count'.
39+
run: |
40+
count=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
41+
echo "commit_count=$count" >> $GITHUB_OUTPUT
42+
43+
# Step 3: Check if the commit count is greater than 1
44+
# This step uses the output from the previous step to decide whether to pass or fail.
45+
- name: Check Commit Count
46+
# This step only runs if the 'commit_count' output from the 'count_commits' step is greater than 1.
47+
if: steps.count_commits.outputs.commit_count > 1
48+
# If the condition is met, the workflow will exit with a failure status.
49+
run: |
50+
echo "This pull request has ${{ steps.count_commits.outputs.commit_count }} commits."
51+
echo "Please squash them into a single commit before merging."
52+
echo "You can use git rebase -i HEAD~N"
53+
echo "...where N is the number of commits you want to squash together. The PR check conveniently tells you this number! For example, if the check says you have 3 commits, you would run: git rebase -i HEAD~3."
54+
echo "Because you have rewritten the commit history, you must use the --force flag to update the pull request: git push --force"
55+
exit 1
56+
57+
# Step 4: Success message
58+
# This step runs if the commit count is not greater than 1 (i.e., it's 1).
59+
- name: Success
60+
if: steps.count_commits.outputs.commit_count <= 1
61+
run: |
62+
echo "This pull request has a single commit. Great job!"

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ For any changes that impact user-facing documentation (guides, API reference, tu
147147
pytest ./tests/unittests
148148
```
149149

150-
NOTE: for accurately repro test failure, only include `test` and `eval` as
151-
extra dependencies.
150+
NOTE: for accurate repro of test failure, only include `test`, `eval` and
151+
`a2a` as extra dependencies.
152152

153153
```shell
154-
uv sync --extra test --extra eval
154+
uv sync --extra test --extra eval --extra a2a
155155
pytest ./tests/unittests
156156
```
157157

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ test = [
9595
# go/keep-sorted start
9696
"anthropic>=0.43.0", # For anthropic model tests
9797
"langchain-community>=0.3.17",
98-
"langgraph>=0.2.60", # For LangGraphAgent
98+
# langgraph 0.5 removed langgraph.graph.graph which we depend on
99+
"langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent
99100
"litellm>=1.71.2", # For LiteLLM tests
100101
"llama-index-readers-file>=0.4.0", # For retrieval tests
101102
"pytest-asyncio>=0.25.0",

src/google/adk/a2a/converters/part_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
import base64
2222
import json
2323
import logging
24-
import sys
2524
from typing import Optional
2625

2726
from .utils import _get_adk_metadata_key
2827

2928
try:
3029
from a2a import types as a2a_types
3130
except ImportError as e:
31+
import sys
32+
3233
if sys.version_info < (3, 10):
3334
raise ImportError(
34-
'A2A Tool requires Python 3.10 or above. Please upgrade your Python'
35-
' version.'
35+
'A2A requires Python 3.10 or above. Please upgrade your Python version.'
3636
) from e
3737
else:
3838
raise e

src/google/adk/a2a/converters/request_converter.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,19 @@
3333
from ...runners import RunConfig
3434
from ...utils.feature_decorator import working_in_progress
3535
from .part_converter import convert_a2a_part_to_genai_part
36-
from .utils import _from_a2a_context_id
37-
from .utils import _get_adk_metadata_key
3836

3937

40-
def _get_user_id(request: RequestContext, user_id_from_context: str) -> str:
38+
def _get_user_id(request: RequestContext) -> str:
4139
# Get user from call context if available (auth is enabled on a2a server)
42-
if request.call_context and request.call_context.user:
40+
if (
41+
request.call_context
42+
and request.call_context.user
43+
and request.call_context.user.user_name
44+
):
4345
return request.call_context.user.user_name
4446

45-
# Get user from context id if available
46-
if user_id_from_context:
47-
return user_id_from_context
48-
49-
# Get user from message metadata if available (client is an ADK agent)
50-
if request.message.metadata:
51-
user_id = request.message.metadata.get(_get_adk_metadata_key('user_id'))
52-
if user_id:
53-
return f'ADK_USER_{user_id}'
54-
55-
# Get user from task if available (client is a an ADK agent)
56-
if request.current_task:
57-
user_id = request.current_task.metadata.get(
58-
_get_adk_metadata_key('user_id')
59-
)
60-
if user_id:
61-
return f'ADK_USER_{user_id}'
62-
return (
63-
f'temp_user_{request.task_id}'
64-
if request.task_id
65-
else f'TEMP_USER_{request.message.messageId}'
66-
)
47+
# Get user from context id
48+
return f'A2A_USER_{request.context_id}'
6749

6850

6951
@working_in_progress
@@ -74,11 +56,9 @@ def convert_a2a_request_to_adk_run_args(
7456
if not request.message:
7557
raise ValueError('Request message cannot be None')
7658

77-
_, user_id, session_id = _from_a2a_context_id(request.context_id)
78-
7959
return {
80-
'user_id': _get_user_id(request, user_id),
81-
'session_id': session_id,
60+
'user_id': _get_user_id(request),
61+
'session_id': request.context_id,
8262
'new_message': genai_types.Content(
8363
role='user',
8464
parts=[
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)