google-adk 0.5.0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/adk/agents/base_agent.py +76 -30
- google/adk/agents/base_agent.py.orig +330 -0
- google/adk/agents/callback_context.py +0 -5
- google/adk/agents/llm_agent.py +122 -30
- google/adk/agents/loop_agent.py +1 -1
- google/adk/agents/parallel_agent.py +7 -0
- google/adk/agents/readonly_context.py +7 -1
- google/adk/agents/run_config.py +1 -1
- google/adk/agents/sequential_agent.py +31 -0
- google/adk/agents/transcription_entry.py +4 -2
- google/adk/artifacts/gcs_artifact_service.py +1 -1
- google/adk/artifacts/in_memory_artifact_service.py +1 -1
- google/adk/auth/auth_credential.py +6 -1
- google/adk/auth/auth_preprocessor.py +7 -1
- google/adk/auth/auth_tool.py +3 -4
- google/adk/cli/agent_graph.py +5 -5
- google/adk/cli/browser/index.html +2 -2
- google/adk/cli/browser/{main-ULN5R5I5.js → main-QOEMUXM4.js} +44 -45
- google/adk/cli/cli.py +7 -7
- google/adk/cli/cli_deploy.py +7 -2
- google/adk/cli/cli_eval.py +172 -99
- google/adk/cli/cli_tools_click.py +147 -64
- google/adk/cli/fast_api.py +330 -148
- google/adk/cli/fast_api.py.orig +174 -80
- google/adk/cli/utils/common.py +23 -0
- google/adk/cli/utils/evals.py +83 -1
- google/adk/cli/utils/logs.py +13 -5
- google/adk/code_executors/__init__.py +3 -1
- google/adk/code_executors/built_in_code_executor.py +52 -0
- google/adk/evaluation/__init__.py +1 -1
- google/adk/evaluation/agent_evaluator.py +168 -128
- google/adk/evaluation/eval_case.py +102 -0
- google/adk/evaluation/eval_set.py +37 -0
- google/adk/evaluation/eval_sets_manager.py +42 -0
- google/adk/evaluation/evaluation_generator.py +88 -113
- google/adk/evaluation/evaluator.py +56 -0
- google/adk/evaluation/local_eval_sets_manager.py +264 -0
- google/adk/evaluation/response_evaluator.py +106 -2
- google/adk/evaluation/trajectory_evaluator.py +83 -2
- google/adk/events/event.py +6 -1
- google/adk/events/event_actions.py +6 -1
- google/adk/examples/example_util.py +3 -2
- google/adk/flows/llm_flows/_code_execution.py +9 -1
- google/adk/flows/llm_flows/audio_transcriber.py +4 -3
- google/adk/flows/llm_flows/base_llm_flow.py +54 -15
- google/adk/flows/llm_flows/functions.py +9 -8
- google/adk/flows/llm_flows/instructions.py +13 -5
- google/adk/flows/llm_flows/single_flow.py +1 -1
- google/adk/memory/__init__.py +1 -1
- google/adk/memory/_utils.py +23 -0
- google/adk/memory/base_memory_service.py +23 -21
- google/adk/memory/base_memory_service.py.orig +76 -0
- google/adk/memory/in_memory_memory_service.py +57 -25
- google/adk/memory/memory_entry.py +37 -0
- google/adk/memory/vertex_ai_rag_memory_service.py +38 -15
- google/adk/models/anthropic_llm.py +16 -9
- google/adk/models/gemini_llm_connection.py +11 -11
- google/adk/models/google_llm.py +9 -2
- google/adk/models/google_llm.py.orig +305 -0
- google/adk/models/lite_llm.py +77 -21
- google/adk/models/llm_response.py +14 -2
- google/adk/models/registry.py +1 -1
- google/adk/runners.py +65 -41
- google/adk/sessions/__init__.py +1 -1
- google/adk/sessions/base_session_service.py +6 -33
- google/adk/sessions/database_session_service.py +58 -65
- google/adk/sessions/in_memory_session_service.py +106 -24
- google/adk/sessions/session.py +3 -0
- google/adk/sessions/vertex_ai_session_service.py +23 -45
- google/adk/telemetry.py +3 -0
- google/adk/tools/__init__.py +4 -7
- google/adk/tools/{built_in_code_execution_tool.py → _built_in_code_execution_tool.py} +11 -0
- google/adk/tools/_memory_entry_utils.py +30 -0
- google/adk/tools/agent_tool.py +9 -9
- google/adk/tools/apihub_tool/apihub_toolset.py +55 -74
- google/adk/tools/application_integration_tool/application_integration_toolset.py +107 -85
- google/adk/tools/application_integration_tool/clients/connections_client.py +20 -0
- google/adk/tools/application_integration_tool/clients/integration_client.py +6 -6
- google/adk/tools/application_integration_tool/integration_connector_tool.py +69 -26
- google/adk/tools/base_toolset.py +58 -0
- google/adk/tools/enterprise_search_tool.py +65 -0
- google/adk/tools/function_parameter_parse_util.py +2 -2
- google/adk/tools/google_api_tool/__init__.py +18 -70
- google/adk/tools/google_api_tool/google_api_tool.py +11 -5
- google/adk/tools/google_api_tool/google_api_toolset.py +126 -0
- google/adk/tools/google_api_tool/google_api_toolsets.py +102 -0
- google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py +40 -42
- google/adk/tools/langchain_tool.py +96 -49
- google/adk/tools/load_memory_tool.py +14 -5
- google/adk/tools/mcp_tool/__init__.py +3 -2
- google/adk/tools/mcp_tool/mcp_session_manager.py +153 -16
- google/adk/tools/mcp_tool/mcp_session_manager.py.orig +322 -0
- google/adk/tools/mcp_tool/mcp_tool.py +12 -12
- google/adk/tools/mcp_tool/mcp_toolset.py +155 -195
- google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py +32 -7
- google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py +31 -31
- google/adk/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.py +1 -1
- google/adk/tools/preload_memory_tool.py +27 -18
- google/adk/tools/retrieval/__init__.py +1 -1
- google/adk/tools/retrieval/vertex_ai_rag_retrieval.py +1 -1
- google/adk/tools/toolbox_toolset.py +79 -0
- google/adk/tools/transfer_to_agent_tool.py +0 -1
- google/adk/version.py +1 -1
- {google_adk-0.5.0.dist-info → google_adk-1.0.0.dist-info}/METADATA +7 -5
- google_adk-1.0.0.dist-info/RECORD +195 -0
- google/adk/agents/remote_agent.py +0 -50
- google/adk/tools/google_api_tool/google_api_tool_set.py +0 -110
- google/adk/tools/google_api_tool/google_api_tool_sets.py +0 -112
- google/adk/tools/toolbox_tool.py +0 -46
- google_adk-0.5.0.dist-info/RECORD +0 -180
- {google_adk-0.5.0.dist-info → google_adk-1.0.0.dist-info}/WHEEL +0 -0
- {google_adk-0.5.0.dist-info → google_adk-1.0.0.dist-info}/entry_points.txt +0 -0
- {google_adk-0.5.0.dist-info → google_adk-1.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -12,46 +12,44 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
import abc
|
16
15
|
|
17
|
-
from
|
18
|
-
from pydantic import Field
|
16
|
+
from __future__ import annotations
|
19
17
|
|
20
|
-
from
|
21
|
-
from
|
18
|
+
from abc import ABC
|
19
|
+
from abc import abstractmethod
|
20
|
+
from typing import TYPE_CHECKING
|
22
21
|
|
22
|
+
from pydantic import BaseModel
|
23
|
+
from pydantic import Field
|
23
24
|
|
24
|
-
|
25
|
-
"""Represents a single memory retrieval result.
|
26
|
-
|
27
|
-
Attributes:
|
28
|
-
session_id: The session id associated with the memory.
|
29
|
-
events: A list of events in the session.
|
30
|
-
"""
|
25
|
+
from .memory_entry import MemoryEntry
|
31
26
|
|
32
|
-
|
33
|
-
|
27
|
+
if TYPE_CHECKING:
|
28
|
+
from ..sessions.session import Session
|
34
29
|
|
35
30
|
|
36
31
|
class SearchMemoryResponse(BaseModel):
|
37
32
|
"""Represents the response from a memory search.
|
38
33
|
|
39
34
|
Attributes:
|
40
|
-
memories: A list of memory
|
35
|
+
memories: A list of memory entries that relate to the search query.
|
41
36
|
"""
|
42
37
|
|
43
|
-
memories: list[
|
38
|
+
memories: list[MemoryEntry] = Field(default_factory=list)
|
44
39
|
|
45
40
|
|
46
|
-
class BaseMemoryService(
|
41
|
+
class BaseMemoryService(ABC):
|
47
42
|
"""Base class for memory services.
|
48
43
|
|
49
44
|
The service provides functionalities to ingest sessions into memory so that
|
50
45
|
the memory can be used for user queries.
|
51
46
|
"""
|
52
47
|
|
53
|
-
@
|
54
|
-
async def add_session_to_memory(
|
48
|
+
@abstractmethod
|
49
|
+
async def add_session_to_memory(
|
50
|
+
self,
|
51
|
+
session: Session,
|
52
|
+
):
|
55
53
|
"""Adds a session to the memory service.
|
56
54
|
|
57
55
|
A session may be added multiple times during its lifetime.
|
@@ -60,9 +58,13 @@ class BaseMemoryService(abc.ABC):
|
|
60
58
|
session: The session to add.
|
61
59
|
"""
|
62
60
|
|
63
|
-
@
|
61
|
+
@abstractmethod
|
64
62
|
async def search_memory(
|
65
|
-
self,
|
63
|
+
self,
|
64
|
+
*,
|
65
|
+
app_name: str,
|
66
|
+
user_id: str,
|
67
|
+
query: str,
|
66
68
|
) -> SearchMemoryResponse:
|
67
69
|
"""Searches for sessions that match the query.
|
68
70
|
|
@@ -0,0 +1,76 @@
|
|
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.
|
14
|
+
|
15
|
+
import abc
|
16
|
+
|
17
|
+
from pydantic import BaseModel
|
18
|
+
from pydantic import Field
|
19
|
+
|
20
|
+
from ..events.event import Event
|
21
|
+
from ..sessions.session import Session
|
22
|
+
|
23
|
+
|
24
|
+
class MemoryResult(BaseModel):
|
25
|
+
"""Represents a single memory retrieval result.
|
26
|
+
|
27
|
+
Attributes:
|
28
|
+
session_id: The session id associated with the memory.
|
29
|
+
events: A list of events in the session.
|
30
|
+
"""
|
31
|
+
|
32
|
+
session_id: str
|
33
|
+
events: list[Event]
|
34
|
+
|
35
|
+
|
36
|
+
class SearchMemoryResponse(BaseModel):
|
37
|
+
"""Represents the response from a memory search.
|
38
|
+
|
39
|
+
Attributes:
|
40
|
+
memories: A list of memory results matching the search query.
|
41
|
+
"""
|
42
|
+
|
43
|
+
memories: list[MemoryResult] = Field(default_factory=list)
|
44
|
+
|
45
|
+
|
46
|
+
class BaseMemoryService(abc.ABC):
|
47
|
+
"""Base class for memory services.
|
48
|
+
|
49
|
+
The service provides functionalities to ingest sessions into memory so that
|
50
|
+
the memory can be used for user queries.
|
51
|
+
"""
|
52
|
+
|
53
|
+
@abc.abstractmethod
|
54
|
+
async def add_session_to_memory(self, session: Session):
|
55
|
+
"""Adds a session to the memory service.
|
56
|
+
|
57
|
+
A session may be added multiple times during its lifetime.
|
58
|
+
|
59
|
+
Args:
|
60
|
+
session: The session to add.
|
61
|
+
"""
|
62
|
+
|
63
|
+
@abc.abstractmethod
|
64
|
+
async def search_memory(
|
65
|
+
self, *, app_name: str, user_id: str, query: str
|
66
|
+
) -> SearchMemoryResponse:
|
67
|
+
"""Searches for sessions that match the query.
|
68
|
+
|
69
|
+
Args:
|
70
|
+
app_name: The name of the application.
|
71
|
+
user_id: The id of the user.
|
72
|
+
query: The query to search for.
|
73
|
+
|
74
|
+
Returns:
|
75
|
+
A SearchMemoryResponse containing the matching memories.
|
76
|
+
"""
|
@@ -12,11 +12,31 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
from
|
15
|
+
|
16
|
+
from __future__ import annotations
|
17
|
+
|
18
|
+
import re
|
19
|
+
from typing import TYPE_CHECKING
|
20
|
+
|
21
|
+
from typing_extensions import override
|
22
|
+
|
23
|
+
from . import _utils
|
17
24
|
from .base_memory_service import BaseMemoryService
|
18
|
-
from .base_memory_service import MemoryResult
|
19
25
|
from .base_memory_service import SearchMemoryResponse
|
26
|
+
from .memory_entry import MemoryEntry
|
27
|
+
|
28
|
+
if TYPE_CHECKING:
|
29
|
+
from ..events.event import Event
|
30
|
+
from ..sessions.session import Session
|
31
|
+
|
32
|
+
|
33
|
+
def _user_key(app_name: str, user_id: str):
|
34
|
+
return f'{app_name}/{user_id}'
|
35
|
+
|
36
|
+
|
37
|
+
def _extract_words_lower(text: str) -> set[str]:
|
38
|
+
"""Extracts words from a string and converts them to lowercase."""
|
39
|
+
return set([word.lower() for word in re.findall(r'[A-Za-z]+', text)])
|
20
40
|
|
21
41
|
|
22
42
|
class InMemoryMemoryService(BaseMemoryService):
|
@@ -26,37 +46,49 @@ class InMemoryMemoryService(BaseMemoryService):
|
|
26
46
|
"""
|
27
47
|
|
28
48
|
def __init__(self):
|
29
|
-
self.
|
30
|
-
"""
|
49
|
+
self._session_events: dict[str, dict[str, list[Event]]] = {}
|
50
|
+
"""Keys are app_name/user_id, session_id. Values are session event lists."""
|
31
51
|
|
52
|
+
@override
|
32
53
|
async def add_session_to_memory(self, session: Session):
|
33
|
-
|
34
|
-
self.
|
35
|
-
|
54
|
+
user_key = _user_key(session.app_name, session.user_id)
|
55
|
+
self._session_events[user_key] = self._session_events.get(
|
56
|
+
_user_key(session.app_name, session.user_id), {}
|
57
|
+
)
|
58
|
+
self._session_events[user_key][session.id] = [
|
59
|
+
event
|
60
|
+
for event in session.events
|
61
|
+
if event.content and event.content.parts
|
36
62
|
]
|
37
63
|
|
64
|
+
@override
|
38
65
|
async def search_memory(
|
39
66
|
self, *, app_name: str, user_id: str, query: str
|
40
67
|
) -> SearchMemoryResponse:
|
41
|
-
|
42
|
-
|
68
|
+
user_key = _user_key(app_name, user_id)
|
69
|
+
if user_key not in self._session_events:
|
70
|
+
return SearchMemoryResponse()
|
71
|
+
|
72
|
+
words_in_query = set(query.lower().split())
|
43
73
|
response = SearchMemoryResponse()
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
matched_events = []
|
48
|
-
for event in events:
|
74
|
+
|
75
|
+
for session_events in self._session_events[user_key].values():
|
76
|
+
for event in session_events:
|
49
77
|
if not event.content or not event.content.parts:
|
50
78
|
continue
|
51
|
-
|
52
|
-
|
53
|
-
for keyword in keywords:
|
54
|
-
if keyword in text:
|
55
|
-
matched_events.append(event)
|
56
|
-
break
|
57
|
-
if matched_events:
|
58
|
-
session_id = key.split('/')[-1]
|
59
|
-
response.memories.append(
|
60
|
-
MemoryResult(session_id=session_id, events=matched_events)
|
79
|
+
words_in_event = _extract_words_lower(
|
80
|
+
' '.join([part.text for part in event.content.parts if part.text])
|
61
81
|
)
|
82
|
+
if not words_in_event:
|
83
|
+
continue
|
84
|
+
|
85
|
+
if any(query_word in words_in_event for query_word in words_in_query):
|
86
|
+
response.memories.append(
|
87
|
+
MemoryEntry(
|
88
|
+
content=event.content,
|
89
|
+
author=event.author,
|
90
|
+
timestamp=_utils.format_timestamp(event.timestamp),
|
91
|
+
)
|
92
|
+
)
|
93
|
+
|
62
94
|
return response
|
@@ -0,0 +1,37 @@
|
|
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.
|
14
|
+
|
15
|
+
|
16
|
+
from __future__ import annotations
|
17
|
+
|
18
|
+
from typing import Optional
|
19
|
+
|
20
|
+
from google.genai import types
|
21
|
+
from pydantic import BaseModel
|
22
|
+
|
23
|
+
|
24
|
+
class MemoryEntry(BaseModel):
|
25
|
+
"""Represent one memory entry."""
|
26
|
+
|
27
|
+
content: types.Content
|
28
|
+
"""The main content of the memory."""
|
29
|
+
|
30
|
+
author: Optional[str] = None
|
31
|
+
"""The author of the memory."""
|
32
|
+
|
33
|
+
timestamp: Optional[str] = None
|
34
|
+
"""The timestamp when the original content of this memory happened.
|
35
|
+
|
36
|
+
This string will be forwarded to LLM. Preferred format is ISO 8601 format.
|
37
|
+
"""
|
@@ -12,20 +12,28 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
|
16
|
+
from __future__ import annotations
|
17
|
+
|
15
18
|
from collections import OrderedDict
|
16
19
|
import json
|
17
20
|
import os
|
18
21
|
import tempfile
|
22
|
+
from typing import Optional
|
23
|
+
from typing import TYPE_CHECKING
|
19
24
|
|
20
25
|
from google.genai import types
|
21
26
|
from typing_extensions import override
|
22
27
|
from vertexai.preview import rag
|
23
28
|
|
24
|
-
from
|
25
|
-
from ..sessions.session import Session
|
29
|
+
from . import _utils
|
26
30
|
from .base_memory_service import BaseMemoryService
|
27
|
-
from .base_memory_service import MemoryResult
|
28
31
|
from .base_memory_service import SearchMemoryResponse
|
32
|
+
from .memory_entry import MemoryEntry
|
33
|
+
|
34
|
+
if TYPE_CHECKING:
|
35
|
+
from ..events.event import Event
|
36
|
+
from ..sessions.session import Session
|
29
37
|
|
30
38
|
|
31
39
|
class VertexAiRagMemoryService(BaseMemoryService):
|
@@ -33,8 +41,8 @@ class VertexAiRagMemoryService(BaseMemoryService):
|
|
33
41
|
|
34
42
|
def __init__(
|
35
43
|
self,
|
36
|
-
rag_corpus: str = None,
|
37
|
-
similarity_top_k: int = None,
|
44
|
+
rag_corpus: Optional[str] = None,
|
45
|
+
similarity_top_k: Optional[int] = None,
|
38
46
|
vector_distance_threshold: float = 10,
|
39
47
|
):
|
40
48
|
"""Initializes a VertexAiRagMemoryService.
|
@@ -47,8 +55,10 @@ class VertexAiRagMemoryService(BaseMemoryService):
|
|
47
55
|
vector_distance_threshold: Only returns contexts with vector distance
|
48
56
|
smaller than the threshold..
|
49
57
|
"""
|
50
|
-
self.
|
51
|
-
rag_resources=[
|
58
|
+
self._vertex_rag_store = types.VertexRagStore(
|
59
|
+
rag_resources=[
|
60
|
+
types.VertexRagStoreRagResource(rag_corpus=rag_corpus),
|
61
|
+
],
|
52
62
|
similarity_top_k=similarity_top_k,
|
53
63
|
vector_distance_threshold=vector_distance_threshold,
|
54
64
|
)
|
@@ -79,7 +89,11 @@ class VertexAiRagMemoryService(BaseMemoryService):
|
|
79
89
|
output_string = "\n".join(output_lines)
|
80
90
|
temp_file.write(output_string)
|
81
91
|
temp_file_path = temp_file.name
|
82
|
-
|
92
|
+
|
93
|
+
if not self._vertex_rag_store.rag_resources:
|
94
|
+
raise ValueError("Rag resources must be set.")
|
95
|
+
|
96
|
+
for rag_resource in self._vertex_rag_store.rag_resources:
|
83
97
|
rag.upload_file(
|
84
98
|
corpus_name=rag_resource.rag_corpus,
|
85
99
|
path=temp_file_path,
|
@@ -95,12 +109,14 @@ class VertexAiRagMemoryService(BaseMemoryService):
|
|
95
109
|
self, *, app_name: str, user_id: str, query: str
|
96
110
|
) -> SearchMemoryResponse:
|
97
111
|
"""Searches for sessions that match the query using rag.retrieval_query."""
|
112
|
+
from ..events.event import Event
|
113
|
+
|
98
114
|
response = rag.retrieval_query(
|
99
115
|
text=query,
|
100
|
-
rag_resources=self.
|
101
|
-
rag_corpora=self.
|
102
|
-
similarity_top_k=self.
|
103
|
-
vector_distance_threshold=self.
|
116
|
+
rag_resources=self._vertex_rag_store.rag_resources,
|
117
|
+
rag_corpora=self._vertex_rag_store.rag_corpora,
|
118
|
+
similarity_top_k=self._vertex_rag_store.similarity_top_k,
|
119
|
+
vector_distance_threshold=self._vertex_rag_store.vector_distance_threshold,
|
104
120
|
)
|
105
121
|
|
106
122
|
memory_results = []
|
@@ -144,9 +160,16 @@ class VertexAiRagMemoryService(BaseMemoryService):
|
|
144
160
|
for session_id, event_lists in session_events_map.items():
|
145
161
|
for events in _merge_event_lists(event_lists):
|
146
162
|
sorted_events = sorted(events, key=lambda e: e.timestamp)
|
147
|
-
|
148
|
-
|
149
|
-
|
163
|
+
|
164
|
+
memory_results.extend([
|
165
|
+
MemoryEntry(
|
166
|
+
author=event.author,
|
167
|
+
content=event.content,
|
168
|
+
timestamp=_utils.format_timestamp(event.timestamp),
|
169
|
+
)
|
170
|
+
for event in sorted_events
|
171
|
+
if event.content
|
172
|
+
])
|
150
173
|
return SearchMemoryResponse(memories=memory_results)
|
151
174
|
|
152
175
|
|
@@ -24,8 +24,9 @@ from typing import AsyncGenerator
|
|
24
24
|
from typing import Generator
|
25
25
|
from typing import Iterable
|
26
26
|
from typing import Literal
|
27
|
-
from typing import Optional
|
27
|
+
from typing import Optional
|
28
28
|
from typing import TYPE_CHECKING
|
29
|
+
from typing import Union
|
29
30
|
|
30
31
|
from anthropic import AnthropicVertex
|
31
32
|
from anthropic import NOT_GIVEN
|
@@ -42,7 +43,7 @@ if TYPE_CHECKING:
|
|
42
43
|
|
43
44
|
__all__ = ["Claude"]
|
44
45
|
|
45
|
-
logger = logging.getLogger(__name__)
|
46
|
+
logger = logging.getLogger("google_adk." + __name__)
|
46
47
|
|
47
48
|
MAX_TOKEN = 1024
|
48
49
|
|
@@ -140,15 +141,15 @@ def message_to_generate_content_response(
|
|
140
141
|
role="model",
|
141
142
|
parts=[content_block_to_part(cb) for cb in message.content],
|
142
143
|
),
|
144
|
+
usage_metadata=types.GenerateContentResponseUsageMetadata(
|
145
|
+
prompt_token_count=message.usage.input_tokens,
|
146
|
+
candidates_token_count=message.usage.output_tokens,
|
147
|
+
total_token_count=(
|
148
|
+
message.usage.input_tokens + message.usage.output_tokens
|
149
|
+
),
|
150
|
+
),
|
143
151
|
# TODO: Deal with these later.
|
144
152
|
# finish_reason=to_google_genai_finish_reason(message.stop_reason),
|
145
|
-
# usage_metadata=types.GenerateContentResponseUsageMetadata(
|
146
|
-
# prompt_token_count=message.usage.input_tokens,
|
147
|
-
# candidates_token_count=message.usage.output_tokens,
|
148
|
-
# total_token_count=(
|
149
|
-
# message.usage.input_tokens + message.usage.output_tokens
|
150
|
-
# ),
|
151
|
-
# ),
|
152
153
|
)
|
153
154
|
|
154
155
|
|
@@ -196,6 +197,12 @@ def function_declaration_to_tool_param(
|
|
196
197
|
|
197
198
|
|
198
199
|
class Claude(BaseLlm):
|
200
|
+
""" "Integration with Claude models served from Vertex AI.
|
201
|
+
|
202
|
+
Attributes:
|
203
|
+
model: The name of the Claude model.
|
204
|
+
"""
|
205
|
+
|
199
206
|
model: str = "claude-3-5-sonnet-v2@20241022"
|
200
207
|
|
201
208
|
@staticmethod
|
@@ -21,7 +21,7 @@ from google.genai import types
|
|
21
21
|
from .base_llm_connection import BaseLlmConnection
|
22
22
|
from .llm_response import LlmResponse
|
23
23
|
|
24
|
-
logger = logging.getLogger(__name__)
|
24
|
+
logger = logging.getLogger('google_adk.' + __name__)
|
25
25
|
|
26
26
|
|
27
27
|
class GeminiLlmConnection(BaseLlmConnection):
|
@@ -149,16 +149,16 @@ class GeminiLlmConnection(BaseLlmConnection):
|
|
149
149
|
message.server_content.input_transcription
|
150
150
|
and message.server_content.input_transcription.text
|
151
151
|
):
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
152
|
+
user_text = message.server_content.input_transcription.text
|
153
|
+
parts = [
|
154
|
+
types.Part.from_text(
|
155
|
+
text=user_text,
|
156
|
+
)
|
157
|
+
]
|
158
|
+
llm_response = LlmResponse(
|
159
|
+
content=types.Content(role='user', parts=parts)
|
160
|
+
)
|
161
|
+
yield llm_response
|
162
162
|
if (
|
163
163
|
message.server_content.output_transcription
|
164
164
|
and message.server_content.output_transcription.text
|
google/adk/models/google_llm.py
CHANGED
@@ -11,6 +11,8 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
+
|
15
|
+
|
14
16
|
from __future__ import annotations
|
15
17
|
|
16
18
|
import contextlib
|
@@ -34,7 +36,7 @@ from .llm_response import LlmResponse
|
|
34
36
|
if TYPE_CHECKING:
|
35
37
|
from .llm_request import LlmRequest
|
36
38
|
|
37
|
-
logger = logging.getLogger(__name__)
|
39
|
+
logger = logging.getLogger('google_adk.' + __name__)
|
38
40
|
|
39
41
|
_NEW_LINE = '\n'
|
40
42
|
_EXCLUDED_PART_FIELD = {'inline_data': {'data'}}
|
@@ -121,6 +123,7 @@ class Gemini(BaseLlm):
|
|
121
123
|
content=types.ModelContent(
|
122
124
|
parts=[types.Part.from_text(text=text)],
|
123
125
|
),
|
126
|
+
usage_metadata=llm_response.usage_metadata,
|
124
127
|
)
|
125
128
|
text = ''
|
126
129
|
yield llm_response
|
@@ -174,9 +177,13 @@ class Gemini(BaseLlm):
|
|
174
177
|
@cached_property
|
175
178
|
def _live_api_client(self) -> Client:
|
176
179
|
if self._api_backend == 'vertex':
|
180
|
+
# use beta version for vertex api
|
181
|
+
api_version = 'v1beta1'
|
177
182
|
# use default api version for vertex
|
178
183
|
return Client(
|
179
|
-
http_options=types.HttpOptions(
|
184
|
+
http_options=types.HttpOptions(
|
185
|
+
headers=self._tracking_headers, api_version=api_version
|
186
|
+
)
|
180
187
|
)
|
181
188
|
else:
|
182
189
|
# use v1alpha for ml_dev
|