Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-file-contents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/discussion_answering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand All @@ -24,7 +24,7 @@ jobs:

- name: Authenticate to Google Cloud
id: auth
uses: 'google-github-actions/auth@v2'
uses: 'google-github-actions/auth@v3'
with:
credentials_json: '${{ secrets.ADK_GCP_SA_KEY }}'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pyink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/upload-adk-docs-to-vertex-ai-search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Clone adk-docs repository
run: git clone https://github.com/google/adk-docs.git /tmp/adk-docs
Expand All @@ -28,7 +28,7 @@ jobs:

- name: Authenticate to Google Cloud
id: auth
uses: 'google-github-actions/auth@v2'
uses: 'google-github-actions/auth@v3'
with:
credentials_json: '${{ secrets.ADK_GCP_SA_KEY }}'

Expand Down
15 changes: 13 additions & 2 deletions contributing/samples/api_registry_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@
root_agent = LlmAgent(
model="gemini-2.0-flash",
name="bigquery_assistant",
instruction="""
Help user access their BigQuery data via API Registry tools.
instruction=f"""
You are a helpful data analyst assistant with access to BigQuery. The project ID is: {PROJECT_ID}

When users ask about data:
- Use the project ID {PROJECT_ID} when calling BigQuery tools.
- First, explore available datasets and tables to understand what data exists.
- Check table schemas to understand the structure before querying.
- Write clear, efficient SQL queries to answer their questions.
- Explain your findings in simple, non-technical language.

Mandatory Requirements:
- Always use the BigQuery tools to fetch real data rather than making assumptions.
- For all BigQuery operations, use project_id: {PROJECT_ID}.
""",
tools=[registry_tools],
)
12 changes: 12 additions & 0 deletions src/google/adk/cli/utils/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

logger = logging.getLogger("google_adk." + __name__)

_BUILT_IN_SESSION_SERVICE_KEY = "__adk_built_in_session_service__"


def create_local_database_session_service(
*,
Expand Down Expand Up @@ -124,6 +126,16 @@ def __init__(

async def _get_service(self, app_name: str) -> BaseSessionService:
async with self._service_lock:
if app_name.startswith("__"):
service = self._services.get(_BUILT_IN_SESSION_SERVICE_KEY)
if service is not None:
return service
service = create_local_database_session_service(
base_dir=self._agents_root,
)
self._services[_BUILT_IN_SESSION_SERVICE_KEY] = service
return service

storage_name = self._app_name_to_dir.get(app_name, app_name)
service = self._services.get(storage_name)
if service is not None:
Expand Down
28 changes: 22 additions & 6 deletions src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,12 @@ def _is_ollama_chat_provider(
model: Optional[str], custom_llm_provider: Optional[str]
) -> bool:
"""Returns True when requests should be normalized for ollama_chat."""
if custom_llm_provider and custom_llm_provider.lower() == "ollama_chat":
if (
custom_llm_provider
and custom_llm_provider.strip().lower() == "ollama_chat"
):
return True
if model and model.lower().startswith("ollama_chat"):
if model and model.strip().lower().startswith("ollama_chat"):
return True
return False

Expand All @@ -644,11 +647,24 @@ def _flatten_ollama_content(
join them with newlines, and fall back to a JSON string for non-text content.
If both text and non-text parts are present, only the text parts are kept.
"""
if not isinstance(content, list):
if content is None or isinstance(content, str):
return content

# `OpenAIMessageContent` is typed as `Iterable[...]` in LiteLLM. Some
# providers or LiteLLM versions may hand back tuples or other iterables.
if isinstance(content, dict):
try:
return json.dumps(content)
except TypeError:
return str(content)

try:
blocks = list(content)
except TypeError:
return str(content)

text_parts = []
for block in content:
for block in blocks:
if isinstance(block, dict) and block.get("type") == "text":
text_value = block.get("text")
if text_value:
Expand All @@ -658,9 +674,9 @@ def _flatten_ollama_content(
return _NEW_LINE.join(text_parts)

try:
return json.dumps(content)
return json.dumps(blocks)
except TypeError:
return str(content)
return str(blocks)


def _normalize_ollama_chat_messages(
Expand Down
12 changes: 12 additions & 0 deletions tests/unittests/cli/utils/test_local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ async def test_per_agent_session_service_respects_app_name_alias(
assert (tmp_path / folder_name / ".adk" / "session.db").exists()


@pytest.mark.asyncio
async def test_per_agent_session_service_routes_built_in_agents_to_root_dot_adk(
tmp_path: Path,
) -> None:
service = PerAgentDatabaseSessionService(agents_root=tmp_path)

await service.create_session(app_name="__helper", user_id="user")

assert not (tmp_path / "__helper").exists()
assert (tmp_path / ".adk" / "session.db").exists()


def test_create_local_database_session_service_returns_sqlite(
tmp_path: Path,
) -> None:
Expand Down
11 changes: 11 additions & 0 deletions tests/unittests/models/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,17 @@ async def test_generate_content_async_custom_provider_flattens_content(
assert "Describe this image." in message_content


def test_flatten_ollama_content_accepts_tuple_blocks():
from google.adk.models.lite_llm import _flatten_ollama_content

content = (
{"type": "text", "text": "first"},
{"type": "text", "text": "second"},
)
flattened = _flatten_ollama_content(content)
assert flattened == "first\nsecond"


@pytest.mark.asyncio
async def test_content_to_message_param_user_message():
content = types.Content(
Expand Down
Loading