google-adk 0.0.3__py3-none-any.whl → 0.0.4__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/run_config.py +4 -0
- google/adk/auth/auth_preprocessor.py +19 -16
- google/adk/cli/browser/index.html +1 -1
- google/adk/cli/browser/{main-SY2WYYGV.js → main-CU22TRPI.js} +30 -30
- google/adk/cli/cli.py +8 -8
- google/adk/cli/cli_deploy.py +2 -4
- google/adk/cli/cli_tools_click.py +6 -6
- google/adk/flows/llm_flows/contents.py +21 -1
- google/adk/flows/llm_flows/functions.py +3 -1
- google/adk/models/google_llm.py +0 -1
- google/adk/runners.py +13 -2
- google/adk/version.py +1 -1
- {google_adk-0.0.3.dist-info → google_adk-0.0.4.dist-info}/METADATA +4 -2
- google_adk-0.0.4.dist-info/RECORD +175 -0
- {google_adk-0.0.3.dist-info → google_adk-0.0.4.dist-info}/WHEEL +1 -1
- google_adk-0.0.4.dist-info/licenses/LICENSE +202 -0
- google/adk/._version.py +0 -0
- google/adk/docs/Makefile +0 -20
- google/adk/docs/build/doctrees/google-adk.doctree +0 -0
- google/adk/docs/build/html/_sources/google-adk.rst.txt +0 -98
- google/adk/docs/build/html/_sources/index.rst.txt +0 -7
- google/adk/docs/build/html/_static/autodoc_pydantic.css +0 -27
- google/adk/docs/build/html/_static/basic.css +0 -925
- google/adk/docs/build/html/_static/debug.css +0 -85
- google/adk/docs/build/html/_static/doctools.js +0 -156
- google/adk/docs/build/html/_static/documentation_options.js +0 -29
- google/adk/docs/build/html/_static/file.png +0 -0
- google/adk/docs/build/html/_static/language_data.js +0 -199
- google/adk/docs/build/html/_static/minus.png +0 -0
- google/adk/docs/build/html/_static/plus.png +0 -0
- google/adk/docs/build/html/_static/pygments.css +0 -274
- google/adk/docs/build/html/_static/scripts/furo-extensions.js +0 -16
- google/adk/docs/build/html/_static/scripts/furo.js +0 -19
- google/adk/docs/build/html/_static/scripts/furo.js.LICENSE.txt +0 -7
- google/adk/docs/build/html/_static/scripts/furo.js.map +0 -1
- google/adk/docs/build/html/_static/searchtools.js +0 -620
- google/adk/docs/build/html/_static/skeleton.css +0 -312
- google/adk/docs/build/html/_static/sphinx_highlight.js +0 -170
- google/adk/docs/build/html/_static/styles/furo-extensions.css +0 -18
- google/adk/docs/build/html/_static/styles/furo-extensions.css.map +0 -1
- google/adk/docs/build/html/_static/styles/furo.css +0 -18
- google/adk/docs/build/html/_static/styles/furo.css.map +0 -1
- google/adk/docs/build/html/genindex.html +0 -861
- google/adk/docs/build/html/google-adk.html +0 -5461
- google/adk/docs/build/html/index.html +0 -567
- google/adk/docs/build/html/objects.inv +0 -0
- google/adk/docs/build/html/py-modindex.html +0 -373
- google/adk/docs/build/html/search.html +0 -333
- google/adk/docs/build/html/searchindex.js +0 -17
- google/adk/docs/source/conf.py +0 -133
- google/adk/docs/source/google-adk.rst +0 -98
- google/adk/docs/source/index.rst +0 -7
- google/adk/tests/__init__.py +0 -14
- google/adk/tests/integration/.env.example +0 -10
- google/adk/tests/integration/__init__.py +0 -18
- google/adk/tests/integration/conftest.py +0 -119
- google/adk/tests/integration/fixture/__init__.py +0 -14
- google/adk/tests/integration/fixture/agent_with_config/__init__.py +0 -15
- google/adk/tests/integration/fixture/agent_with_config/agent.py +0 -88
- google/adk/tests/integration/fixture/callback_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/callback_agent/agent.py +0 -105
- google/adk/tests/integration/fixture/context_update_test/OWNERS +0 -1
- google/adk/tests/integration/fixture/context_update_test/__init__.py +0 -15
- google/adk/tests/integration/fixture/context_update_test/agent.py +0 -43
- google/adk/tests/integration/fixture/context_update_test/successful_test.session.json +0 -582
- google/adk/tests/integration/fixture/context_variable_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/context_variable_agent/agent.py +0 -115
- google/adk/tests/integration/fixture/customer_support_ma/__init__.py +0 -15
- google/adk/tests/integration/fixture/customer_support_ma/agent.py +0 -172
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/agent.py +0 -338
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/order_query.test.json +0 -69
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/test_config.json +0 -6
- google/adk/tests/integration/fixture/flow_complex_spark/__init__.py +0 -15
- google/adk/tests/integration/fixture/flow_complex_spark/agent.py +0 -182
- google/adk/tests/integration/fixture/flow_complex_spark/sample.session.json +0 -190
- google/adk/tests/integration/fixture/hello_world_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/hello_world_agent/agent.py +0 -95
- google/adk/tests/integration/fixture/hello_world_agent/roll_die.test.json +0 -24
- google/adk/tests/integration/fixture/hello_world_agent/test_config.json +0 -6
- google/adk/tests/integration/fixture/home_automation_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/home_automation_agent/agent.py +0 -304
- google/adk/tests/integration/fixture/home_automation_agent/simple_test.test.json +0 -5
- google/adk/tests/integration/fixture/home_automation_agent/simple_test2.test.json +0 -5
- google/adk/tests/integration/fixture/home_automation_agent/test_config.json +0 -5
- google/adk/tests/integration/fixture/home_automation_agent/test_files/dependent_tool_calls.test.json +0 -18
- google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/eval_data.test.json +0 -17
- google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/test_config.json +0 -6
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_multi_turn_conversation.test.json +0 -18
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test.test.json +0 -17
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test2.test.json +0 -5
- google/adk/tests/integration/fixture/home_automation_agent/test_files/test_config.json +0 -5
- google/adk/tests/integration/fixture/tool_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/tool_agent/agent.py +0 -218
- google/adk/tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf +0 -0
- google/adk/tests/integration/fixture/trip_planner_agent/__init__.py +0 -15
- google/adk/tests/integration/fixture/trip_planner_agent/agent.py +0 -110
- google/adk/tests/integration/fixture/trip_planner_agent/initial.session.json +0 -13
- google/adk/tests/integration/fixture/trip_planner_agent/test_config.json +0 -5
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/initial.session.json +0 -13
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/test_config.json +0 -5
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/trip_inquiry_sub_agent.test.json +0 -7
- google/adk/tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json +0 -19
- google/adk/tests/integration/models/__init__.py +0 -14
- google/adk/tests/integration/models/test_google_llm.py +0 -65
- google/adk/tests/integration/test_callback.py +0 -70
- google/adk/tests/integration/test_context_variable.py +0 -67
- google/adk/tests/integration/test_evalute_agent_in_fixture.py +0 -76
- google/adk/tests/integration/test_multi_agent.py +0 -28
- google/adk/tests/integration/test_multi_turn.py +0 -42
- google/adk/tests/integration/test_single_agent.py +0 -23
- google/adk/tests/integration/test_sub_agent.py +0 -26
- google/adk/tests/integration/test_system_instruction.py +0 -177
- google/adk/tests/integration/test_tools.py +0 -287
- google/adk/tests/integration/test_with_test_file.py +0 -34
- google/adk/tests/integration/tools/__init__.py +0 -14
- google/adk/tests/integration/utils/__init__.py +0 -16
- google/adk/tests/integration/utils/asserts.py +0 -75
- google/adk/tests/integration/utils/test_runner.py +0 -97
- google/adk/tests/unittests/__init__.py +0 -14
- google/adk/tests/unittests/agents/__init__.py +0 -14
- google/adk/tests/unittests/agents/test_base_agent.py +0 -407
- google/adk/tests/unittests/agents/test_langgraph_agent.py +0 -191
- google/adk/tests/unittests/agents/test_llm_agent_callbacks.py +0 -138
- google/adk/tests/unittests/agents/test_llm_agent_fields.py +0 -231
- google/adk/tests/unittests/agents/test_loop_agent.py +0 -136
- google/adk/tests/unittests/agents/test_parallel_agent.py +0 -92
- google/adk/tests/unittests/agents/test_sequential_agent.py +0 -114
- google/adk/tests/unittests/artifacts/__init__.py +0 -14
- google/adk/tests/unittests/artifacts/test_artifact_service.py +0 -276
- google/adk/tests/unittests/auth/test_auth_handler.py +0 -575
- google/adk/tests/unittests/conftest.py +0 -73
- google/adk/tests/unittests/fast_api/__init__.py +0 -14
- google/adk/tests/unittests/fast_api/test_fast_api.py +0 -269
- google/adk/tests/unittests/flows/__init__.py +0 -14
- google/adk/tests/unittests/flows/llm_flows/__init__.py +0 -14
- google/adk/tests/unittests/flows/llm_flows/_test_examples.py +0 -142
- google/adk/tests/unittests/flows/llm_flows/test_agent_transfer.py +0 -311
- google/adk/tests/unittests/flows/llm_flows/test_functions_long_running.py +0 -244
- google/adk/tests/unittests/flows/llm_flows/test_functions_request_euc.py +0 -346
- google/adk/tests/unittests/flows/llm_flows/test_functions_sequential.py +0 -93
- google/adk/tests/unittests/flows/llm_flows/test_functions_simple.py +0 -258
- google/adk/tests/unittests/flows/llm_flows/test_identity.py +0 -66
- google/adk/tests/unittests/flows/llm_flows/test_instructions.py +0 -164
- google/adk/tests/unittests/flows/llm_flows/test_model_callbacks.py +0 -142
- google/adk/tests/unittests/flows/llm_flows/test_other_configs.py +0 -46
- google/adk/tests/unittests/flows/llm_flows/test_tool_callbacks.py +0 -269
- google/adk/tests/unittests/models/__init__.py +0 -14
- google/adk/tests/unittests/models/test_google_llm.py +0 -224
- google/adk/tests/unittests/models/test_litellm.py +0 -804
- google/adk/tests/unittests/models/test_models.py +0 -60
- google/adk/tests/unittests/sessions/__init__.py +0 -14
- google/adk/tests/unittests/sessions/test_session_service.py +0 -227
- google/adk/tests/unittests/sessions/test_vertex_ai_session_service.py +0 -246
- google/adk/tests/unittests/streaming/__init__.py +0 -14
- google/adk/tests/unittests/streaming/test_streaming.py +0 -50
- google/adk/tests/unittests/tools/__init__.py +0 -14
- google/adk/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +0 -499
- google/adk/tests/unittests/tools/apihub_tool/test_apihub_toolset.py +0 -204
- google/adk/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py +0 -600
- google/adk/tests/unittests/tools/application_integration_tool/clients/test_integration_client.py +0 -630
- google/adk/tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py +0 -345
- google/adk/tests/unittests/tools/google_api_tool/__init__.py +0 -13
- google/adk/tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py +0 -657
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_auto_auth_credential_exchanger.py +0 -145
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_base_auth_credential_exchanger.py +0 -68
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py +0 -153
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_service_account_exchanger.py +0 -196
- google/adk/tests/unittests/tools/openapi_tool/auth/test_auth_helper.py +0 -573
- google/adk/tests/unittests/tools/openapi_tool/common/test_common.py +0 -436
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test.yaml +0 -1367
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +0 -628
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py +0 -139
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py +0 -406
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py +0 -966
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_tool_auth_handler.py +0 -201
- google/adk/tests/unittests/tools/retrieval/__init__.py +0 -14
- google/adk/tests/unittests/tools/retrieval/test_vertex_ai_rag_retrieval.py +0 -147
- google/adk/tests/unittests/tools/test_agent_tool.py +0 -167
- google/adk/tests/unittests/tools/test_base_tool.py +0 -141
- google/adk/tests/unittests/tools/test_build_function_declaration.py +0 -277
- google/adk/tests/unittests/utils.py +0 -304
- google_adk-0.0.3.dist-info/RECORD +0 -340
- {google_adk-0.0.3.dist-info → google_adk-0.0.4.dist-info}/entry_points.txt +0 -0
@@ -1,66 +0,0 @@
|
|
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
|
-
from google.adk.agents import Agent
|
16
|
-
from google.adk.flows.llm_flows import identity
|
17
|
-
from google.adk.models import LlmRequest
|
18
|
-
from google.genai import types
|
19
|
-
import pytest
|
20
|
-
|
21
|
-
from ... import utils
|
22
|
-
|
23
|
-
|
24
|
-
@pytest.mark.asyncio
|
25
|
-
async def test_no_description():
|
26
|
-
request = LlmRequest(
|
27
|
-
model="gemini-1.5-flash",
|
28
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
29
|
-
)
|
30
|
-
agent = Agent(model="gemini-1.5-flash", name="agent")
|
31
|
-
invocation_context = utils.create_invocation_context(agent=agent)
|
32
|
-
|
33
|
-
async for _ in identity.request_processor.run_async(
|
34
|
-
invocation_context,
|
35
|
-
request,
|
36
|
-
):
|
37
|
-
pass
|
38
|
-
|
39
|
-
assert request.config.system_instruction == (
|
40
|
-
"""You are an agent. Your internal name is "agent"."""
|
41
|
-
)
|
42
|
-
|
43
|
-
|
44
|
-
@pytest.mark.asyncio
|
45
|
-
async def test_with_description():
|
46
|
-
request = LlmRequest(
|
47
|
-
model="gemini-1.5-flash",
|
48
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
49
|
-
)
|
50
|
-
agent = Agent(
|
51
|
-
model="gemini-1.5-flash",
|
52
|
-
name="agent",
|
53
|
-
description="test description",
|
54
|
-
)
|
55
|
-
invocation_context = utils.create_invocation_context(agent=agent)
|
56
|
-
|
57
|
-
async for _ in identity.request_processor.run_async(
|
58
|
-
invocation_context,
|
59
|
-
request,
|
60
|
-
):
|
61
|
-
pass
|
62
|
-
|
63
|
-
assert request.config.system_instruction == "\n\n".join([
|
64
|
-
'You are an agent. Your internal name is "agent".',
|
65
|
-
' The description about you is "test description"',
|
66
|
-
])
|
@@ -1,164 +0,0 @@
|
|
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
|
-
from google.adk.agents import Agent
|
16
|
-
from google.adk.agents.readonly_context import ReadonlyContext
|
17
|
-
from google.adk.flows.llm_flows import instructions
|
18
|
-
from google.adk.models import LlmRequest
|
19
|
-
from google.adk.sessions import Session
|
20
|
-
from google.genai import types
|
21
|
-
import pytest
|
22
|
-
|
23
|
-
from ... import utils
|
24
|
-
|
25
|
-
|
26
|
-
@pytest.mark.asyncio
|
27
|
-
async def test_build_system_instruction():
|
28
|
-
request = LlmRequest(
|
29
|
-
model="gemini-1.5-flash",
|
30
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
31
|
-
)
|
32
|
-
agent = Agent(
|
33
|
-
model="gemini-1.5-flash",
|
34
|
-
name="agent",
|
35
|
-
instruction=("""Use the echo_info tool to echo { customerId }, \
|
36
|
-
{{customer_int }, { non-identifier-float}}, \
|
37
|
-
{'key1': 'value1'} and {{'key2': 'value2'}}."""),
|
38
|
-
)
|
39
|
-
invocation_context = utils.create_invocation_context(agent=agent)
|
40
|
-
invocation_context.session = Session(
|
41
|
-
app_name="test_app",
|
42
|
-
user_id="test_user",
|
43
|
-
id="test_id",
|
44
|
-
state={"customerId": "1234567890", "customer_int": 30},
|
45
|
-
)
|
46
|
-
|
47
|
-
async for _ in instructions.request_processor.run_async(
|
48
|
-
invocation_context,
|
49
|
-
request,
|
50
|
-
):
|
51
|
-
pass
|
52
|
-
|
53
|
-
assert request.config.system_instruction == (
|
54
|
-
"""Use the echo_info tool to echo 1234567890, 30, \
|
55
|
-
{ non-identifier-float}}, {'key1': 'value1'} and {{'key2': 'value2'}}."""
|
56
|
-
)
|
57
|
-
|
58
|
-
|
59
|
-
@pytest.mark.asyncio
|
60
|
-
async def test_function_system_instruction():
|
61
|
-
def build_function_instruction(readonly_context: ReadonlyContext) -> str:
|
62
|
-
return (
|
63
|
-
"This is the function agent instruction for invocation:"
|
64
|
-
f" {readonly_context.invocation_id}."
|
65
|
-
)
|
66
|
-
|
67
|
-
request = LlmRequest(
|
68
|
-
model="gemini-1.5-flash",
|
69
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
70
|
-
)
|
71
|
-
agent = Agent(
|
72
|
-
model="gemini-1.5-flash",
|
73
|
-
name="agent",
|
74
|
-
instruction=build_function_instruction,
|
75
|
-
)
|
76
|
-
invocation_context = utils.create_invocation_context(agent=agent)
|
77
|
-
invocation_context.session = Session(
|
78
|
-
app_name="test_app",
|
79
|
-
user_id="test_user",
|
80
|
-
id="test_id",
|
81
|
-
state={"customerId": "1234567890", "customer_int": 30},
|
82
|
-
)
|
83
|
-
|
84
|
-
async for _ in instructions.request_processor.run_async(
|
85
|
-
invocation_context,
|
86
|
-
request,
|
87
|
-
):
|
88
|
-
pass
|
89
|
-
|
90
|
-
assert request.config.system_instruction == (
|
91
|
-
"This is the function agent instruction for invocation: test_id."
|
92
|
-
)
|
93
|
-
|
94
|
-
|
95
|
-
@pytest.mark.asyncio
|
96
|
-
async def test_global_system_instruction():
|
97
|
-
sub_agent = Agent(
|
98
|
-
model="gemini-1.5-flash",
|
99
|
-
name="sub_agent",
|
100
|
-
instruction="This is the sub agent instruction.",
|
101
|
-
)
|
102
|
-
root_agent = Agent(
|
103
|
-
model="gemini-1.5-flash",
|
104
|
-
name="root_agent",
|
105
|
-
global_instruction="This is the global instruction.",
|
106
|
-
sub_agents=[sub_agent],
|
107
|
-
)
|
108
|
-
request = LlmRequest(
|
109
|
-
model="gemini-1.5-flash",
|
110
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
111
|
-
)
|
112
|
-
invocation_context = utils.create_invocation_context(agent=sub_agent)
|
113
|
-
invocation_context.session = Session(
|
114
|
-
app_name="test_app",
|
115
|
-
user_id="test_user",
|
116
|
-
id="test_id",
|
117
|
-
state={"customerId": "1234567890", "customer_int": 30},
|
118
|
-
)
|
119
|
-
|
120
|
-
async for _ in instructions.request_processor.run_async(
|
121
|
-
invocation_context,
|
122
|
-
request,
|
123
|
-
):
|
124
|
-
pass
|
125
|
-
|
126
|
-
assert request.config.system_instruction == (
|
127
|
-
"This is the global instruction.\n\nThis is the sub agent instruction."
|
128
|
-
)
|
129
|
-
|
130
|
-
|
131
|
-
@pytest.mark.asyncio
|
132
|
-
async def test_build_system_instruction_with_namespace():
|
133
|
-
request = LlmRequest(
|
134
|
-
model="gemini-1.5-flash",
|
135
|
-
config=types.GenerateContentConfig(system_instruction=""),
|
136
|
-
)
|
137
|
-
agent = Agent(
|
138
|
-
model="gemini-1.5-flash",
|
139
|
-
name="agent",
|
140
|
-
instruction=(
|
141
|
-
"""Use the echo_info tool to echo { customerId }, {app:key}, {user:key}, {a:key}."""
|
142
|
-
),
|
143
|
-
)
|
144
|
-
invocation_context = utils.create_invocation_context(agent=agent)
|
145
|
-
invocation_context.session = Session(
|
146
|
-
app_name="test_app",
|
147
|
-
user_id="test_user",
|
148
|
-
id="test_id",
|
149
|
-
state={
|
150
|
-
"customerId": "1234567890",
|
151
|
-
"app:key": "app_value",
|
152
|
-
"user:key": "user_value",
|
153
|
-
},
|
154
|
-
)
|
155
|
-
|
156
|
-
async for _ in instructions.request_processor.run_async(
|
157
|
-
invocation_context,
|
158
|
-
request,
|
159
|
-
):
|
160
|
-
pass
|
161
|
-
|
162
|
-
assert request.config.system_instruction == (
|
163
|
-
"""Use the echo_info tool to echo 1234567890, app_value, user_value, {a:key}."""
|
164
|
-
)
|
@@ -1,142 +0,0 @@
|
|
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
|
-
from typing import Any
|
16
|
-
from typing import Optional
|
17
|
-
|
18
|
-
from google.adk.agents import Agent
|
19
|
-
from google.adk.agents.callback_context import CallbackContext
|
20
|
-
from google.adk.models import LlmRequest
|
21
|
-
from google.adk.models import LlmResponse
|
22
|
-
from google.genai import types
|
23
|
-
from pydantic import BaseModel
|
24
|
-
import pytest
|
25
|
-
|
26
|
-
from ... import utils
|
27
|
-
|
28
|
-
|
29
|
-
class MockBeforeModelCallback(BaseModel):
|
30
|
-
mock_response: str
|
31
|
-
|
32
|
-
def __call__(
|
33
|
-
self,
|
34
|
-
callback_context: CallbackContext,
|
35
|
-
llm_request: LlmRequest,
|
36
|
-
) -> LlmResponse:
|
37
|
-
return LlmResponse(
|
38
|
-
content=utils.ModelContent(
|
39
|
-
[types.Part.from_text(text=self.mock_response)]
|
40
|
-
)
|
41
|
-
)
|
42
|
-
|
43
|
-
|
44
|
-
class MockAfterModelCallback(BaseModel):
|
45
|
-
mock_response: str
|
46
|
-
|
47
|
-
def __call__(
|
48
|
-
self,
|
49
|
-
callback_context: CallbackContext,
|
50
|
-
llm_response: LlmResponse,
|
51
|
-
) -> LlmResponse:
|
52
|
-
return LlmResponse(
|
53
|
-
content=utils.ModelContent(
|
54
|
-
[types.Part.from_text(text=self.mock_response)]
|
55
|
-
)
|
56
|
-
)
|
57
|
-
|
58
|
-
|
59
|
-
def noop_callback(**kwargs) -> Optional[LlmResponse]:
|
60
|
-
pass
|
61
|
-
|
62
|
-
|
63
|
-
def test_before_model_callback():
|
64
|
-
responses = ['model_response']
|
65
|
-
mock_model = utils.MockModel.create(responses=responses)
|
66
|
-
agent = Agent(
|
67
|
-
name='root_agent',
|
68
|
-
model=mock_model,
|
69
|
-
before_model_callback=MockBeforeModelCallback(
|
70
|
-
mock_response='before_model_callback'
|
71
|
-
),
|
72
|
-
)
|
73
|
-
|
74
|
-
runner = utils.InMemoryRunner(agent)
|
75
|
-
assert utils.simplify_events(runner.run('test')) == [
|
76
|
-
('root_agent', 'before_model_callback'),
|
77
|
-
]
|
78
|
-
|
79
|
-
|
80
|
-
def test_before_model_callback_noop():
|
81
|
-
responses = ['model_response']
|
82
|
-
mock_model = utils.MockModel.create(responses=responses)
|
83
|
-
agent = Agent(
|
84
|
-
name='root_agent',
|
85
|
-
model=mock_model,
|
86
|
-
before_model_callback=noop_callback,
|
87
|
-
)
|
88
|
-
|
89
|
-
runner = utils.InMemoryRunner(agent)
|
90
|
-
assert utils.simplify_events(runner.run('test')) == [
|
91
|
-
('root_agent', 'model_response'),
|
92
|
-
]
|
93
|
-
|
94
|
-
|
95
|
-
def test_before_model_callback_end():
|
96
|
-
responses = ['model_response']
|
97
|
-
mock_model = utils.MockModel.create(responses=responses)
|
98
|
-
agent = Agent(
|
99
|
-
name='root_agent',
|
100
|
-
model=mock_model,
|
101
|
-
before_model_callback=MockBeforeModelCallback(
|
102
|
-
mock_response='before_model_callback',
|
103
|
-
),
|
104
|
-
)
|
105
|
-
|
106
|
-
runner = utils.InMemoryRunner(agent)
|
107
|
-
assert utils.simplify_events(runner.run('test')) == [
|
108
|
-
('root_agent', 'before_model_callback'),
|
109
|
-
]
|
110
|
-
|
111
|
-
|
112
|
-
def test_after_model_callback():
|
113
|
-
responses = ['model_response']
|
114
|
-
mock_model = utils.MockModel.create(responses=responses)
|
115
|
-
agent = Agent(
|
116
|
-
name='root_agent',
|
117
|
-
model=mock_model,
|
118
|
-
after_model_callback=MockAfterModelCallback(
|
119
|
-
mock_response='after_model_callback'
|
120
|
-
),
|
121
|
-
)
|
122
|
-
|
123
|
-
runner = utils.InMemoryRunner(agent)
|
124
|
-
assert utils.simplify_events(runner.run('test')) == [
|
125
|
-
('root_agent', 'after_model_callback'),
|
126
|
-
]
|
127
|
-
|
128
|
-
|
129
|
-
@pytest.mark.asyncio
|
130
|
-
async def test_after_model_callback_noop():
|
131
|
-
responses = ['model_response']
|
132
|
-
mock_model = utils.MockModel.create(responses=responses)
|
133
|
-
agent = Agent(
|
134
|
-
name='root_agent',
|
135
|
-
model=mock_model,
|
136
|
-
after_model_callback=noop_callback,
|
137
|
-
)
|
138
|
-
|
139
|
-
runner = utils.TestInMemoryRunner(agent)
|
140
|
-
assert utils.simplify_events(
|
141
|
-
await runner.run_async_with_new_session('test')
|
142
|
-
) == [('root_agent', 'model_response')]
|
@@ -1,46 +0,0 @@
|
|
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
|
-
from google.adk.agents import Agent
|
16
|
-
from google.adk.tools import ToolContext
|
17
|
-
from google.genai.types import Part
|
18
|
-
from pydantic import BaseModel
|
19
|
-
|
20
|
-
from ... import utils
|
21
|
-
|
22
|
-
|
23
|
-
def test_output_schema():
|
24
|
-
class CustomOutput(BaseModel):
|
25
|
-
custom_field: str
|
26
|
-
|
27
|
-
response = [
|
28
|
-
'response1',
|
29
|
-
]
|
30
|
-
mockModel = utils.MockModel.create(responses=response)
|
31
|
-
root_agent = Agent(
|
32
|
-
name='root_agent',
|
33
|
-
model=mockModel,
|
34
|
-
output_schema=CustomOutput,
|
35
|
-
disallow_transfer_to_parent=True,
|
36
|
-
disallow_transfer_to_peers=True,
|
37
|
-
)
|
38
|
-
|
39
|
-
runner = utils.InMemoryRunner(root_agent)
|
40
|
-
|
41
|
-
assert utils.simplify_events(runner.run('test1')) == [
|
42
|
-
('root_agent', 'response1'),
|
43
|
-
]
|
44
|
-
assert len(mockModel.requests) == 1
|
45
|
-
assert mockModel.requests[0].config.response_schema == CustomOutput
|
46
|
-
assert mockModel.requests[0].config.response_mime_type == 'application/json'
|
@@ -1,269 +0,0 @@
|
|
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
|
-
from typing import Any
|
16
|
-
|
17
|
-
from google.adk.agents import Agent
|
18
|
-
from google.adk.tools import BaseTool
|
19
|
-
from google.adk.tools import ToolContext
|
20
|
-
from google.genai import types
|
21
|
-
from google.genai.types import Part
|
22
|
-
from pydantic import BaseModel
|
23
|
-
|
24
|
-
from ... import utils
|
25
|
-
|
26
|
-
|
27
|
-
def simple_function(input_str: str) -> str:
|
28
|
-
return {'result': input_str}
|
29
|
-
|
30
|
-
|
31
|
-
class MockBeforeToolCallback(BaseModel):
|
32
|
-
mock_response: dict[str, object]
|
33
|
-
modify_tool_request: bool = False
|
34
|
-
|
35
|
-
def __call__(
|
36
|
-
self,
|
37
|
-
tool: BaseTool,
|
38
|
-
args: dict[str, Any],
|
39
|
-
tool_context: ToolContext,
|
40
|
-
) -> dict[str, object]:
|
41
|
-
if self.modify_tool_request:
|
42
|
-
args['input_str'] = 'modified_input'
|
43
|
-
return None
|
44
|
-
return self.mock_response
|
45
|
-
|
46
|
-
|
47
|
-
class MockAfterToolCallback(BaseModel):
|
48
|
-
mock_response: dict[str, object]
|
49
|
-
modify_tool_request: bool = False
|
50
|
-
modify_tool_response: bool = False
|
51
|
-
|
52
|
-
def __call__(
|
53
|
-
self,
|
54
|
-
tool: BaseTool,
|
55
|
-
args: dict[str, Any],
|
56
|
-
tool_context: ToolContext,
|
57
|
-
tool_response: dict[str, Any] = None,
|
58
|
-
) -> dict[str, object]:
|
59
|
-
if self.modify_tool_request:
|
60
|
-
args['input_str'] = 'modified_input'
|
61
|
-
return None
|
62
|
-
if self.modify_tool_response:
|
63
|
-
tool_response['result'] = 'modified_output'
|
64
|
-
return tool_response
|
65
|
-
return self.mock_response
|
66
|
-
|
67
|
-
|
68
|
-
def noop_callback(
|
69
|
-
**kwargs,
|
70
|
-
) -> dict[str, object]:
|
71
|
-
pass
|
72
|
-
|
73
|
-
|
74
|
-
def test_before_tool_callback():
|
75
|
-
responses = [
|
76
|
-
types.Part.from_function_call(name='simple_function', args={}),
|
77
|
-
'response1',
|
78
|
-
]
|
79
|
-
mock_model = utils.MockModel.create(responses=responses)
|
80
|
-
agent = Agent(
|
81
|
-
name='root_agent',
|
82
|
-
model=mock_model,
|
83
|
-
before_tool_callback=MockBeforeToolCallback(
|
84
|
-
mock_response={'test': 'before_tool_callback'}
|
85
|
-
),
|
86
|
-
tools=[simple_function],
|
87
|
-
)
|
88
|
-
|
89
|
-
runner = utils.InMemoryRunner(agent)
|
90
|
-
assert utils.simplify_events(runner.run('test')) == [
|
91
|
-
('root_agent', Part.from_function_call(name='simple_function', args={})),
|
92
|
-
(
|
93
|
-
'root_agent',
|
94
|
-
Part.from_function_response(
|
95
|
-
name='simple_function', response={'test': 'before_tool_callback'}
|
96
|
-
),
|
97
|
-
),
|
98
|
-
('root_agent', 'response1'),
|
99
|
-
]
|
100
|
-
|
101
|
-
|
102
|
-
def test_before_tool_callback_noop():
|
103
|
-
responses = [
|
104
|
-
types.Part.from_function_call(
|
105
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
106
|
-
),
|
107
|
-
'response1',
|
108
|
-
]
|
109
|
-
mock_model = utils.MockModel.create(responses=responses)
|
110
|
-
agent = Agent(
|
111
|
-
name='root_agent',
|
112
|
-
model=mock_model,
|
113
|
-
before_tool_callback=noop_callback,
|
114
|
-
tools=[simple_function],
|
115
|
-
)
|
116
|
-
|
117
|
-
runner = utils.InMemoryRunner(agent)
|
118
|
-
assert utils.simplify_events(runner.run('test')) == [
|
119
|
-
(
|
120
|
-
'root_agent',
|
121
|
-
Part.from_function_call(
|
122
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
123
|
-
),
|
124
|
-
),
|
125
|
-
(
|
126
|
-
'root_agent',
|
127
|
-
Part.from_function_response(
|
128
|
-
name='simple_function',
|
129
|
-
response={'result': 'simple_function_call'},
|
130
|
-
),
|
131
|
-
),
|
132
|
-
('root_agent', 'response1'),
|
133
|
-
]
|
134
|
-
|
135
|
-
|
136
|
-
def test_before_tool_callback_modify_tool_request():
|
137
|
-
responses = [
|
138
|
-
types.Part.from_function_call(name='simple_function', args={}),
|
139
|
-
'response1',
|
140
|
-
]
|
141
|
-
mock_model = utils.MockModel.create(responses=responses)
|
142
|
-
agent = Agent(
|
143
|
-
name='root_agent',
|
144
|
-
model=mock_model,
|
145
|
-
before_tool_callback=MockBeforeToolCallback(
|
146
|
-
mock_response={'test': 'before_tool_callback'},
|
147
|
-
modify_tool_request=True,
|
148
|
-
),
|
149
|
-
tools=[simple_function],
|
150
|
-
)
|
151
|
-
|
152
|
-
runner = utils.InMemoryRunner(agent)
|
153
|
-
assert utils.simplify_events(runner.run('test')) == [
|
154
|
-
('root_agent', Part.from_function_call(name='simple_function', args={})),
|
155
|
-
(
|
156
|
-
'root_agent',
|
157
|
-
Part.from_function_response(
|
158
|
-
name='simple_function',
|
159
|
-
response={'result': 'modified_input'},
|
160
|
-
),
|
161
|
-
),
|
162
|
-
('root_agent', 'response1'),
|
163
|
-
]
|
164
|
-
|
165
|
-
|
166
|
-
def test_after_tool_callback():
|
167
|
-
responses = [
|
168
|
-
types.Part.from_function_call(
|
169
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
170
|
-
),
|
171
|
-
'response1',
|
172
|
-
]
|
173
|
-
mock_model = utils.MockModel.create(responses=responses)
|
174
|
-
agent = Agent(
|
175
|
-
name='root_agent',
|
176
|
-
model=mock_model,
|
177
|
-
after_tool_callback=MockAfterToolCallback(
|
178
|
-
mock_response={'test': 'after_tool_callback'}
|
179
|
-
),
|
180
|
-
tools=[simple_function],
|
181
|
-
)
|
182
|
-
|
183
|
-
runner = utils.InMemoryRunner(agent)
|
184
|
-
assert utils.simplify_events(runner.run('test')) == [
|
185
|
-
(
|
186
|
-
'root_agent',
|
187
|
-
Part.from_function_call(
|
188
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
189
|
-
),
|
190
|
-
),
|
191
|
-
(
|
192
|
-
'root_agent',
|
193
|
-
Part.from_function_response(
|
194
|
-
name='simple_function', response={'test': 'after_tool_callback'}
|
195
|
-
),
|
196
|
-
),
|
197
|
-
('root_agent', 'response1'),
|
198
|
-
]
|
199
|
-
|
200
|
-
|
201
|
-
def test_after_tool_callback_noop():
|
202
|
-
responses = [
|
203
|
-
types.Part.from_function_call(
|
204
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
205
|
-
),
|
206
|
-
'response1',
|
207
|
-
]
|
208
|
-
mock_model = utils.MockModel.create(responses=responses)
|
209
|
-
agent = Agent(
|
210
|
-
name='root_agent',
|
211
|
-
model=mock_model,
|
212
|
-
after_tool_callback=noop_callback,
|
213
|
-
tools=[simple_function],
|
214
|
-
)
|
215
|
-
|
216
|
-
runner = utils.InMemoryRunner(agent)
|
217
|
-
assert utils.simplify_events(runner.run('test')) == [
|
218
|
-
(
|
219
|
-
'root_agent',
|
220
|
-
Part.from_function_call(
|
221
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
222
|
-
),
|
223
|
-
),
|
224
|
-
(
|
225
|
-
'root_agent',
|
226
|
-
Part.from_function_response(
|
227
|
-
name='simple_function',
|
228
|
-
response={'result': 'simple_function_call'},
|
229
|
-
),
|
230
|
-
),
|
231
|
-
('root_agent', 'response1'),
|
232
|
-
]
|
233
|
-
|
234
|
-
|
235
|
-
def test_after_tool_callback_modify_tool_response():
|
236
|
-
responses = [
|
237
|
-
types.Part.from_function_call(
|
238
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
239
|
-
),
|
240
|
-
'response1',
|
241
|
-
]
|
242
|
-
mock_model = utils.MockModel.create(responses=responses)
|
243
|
-
agent = Agent(
|
244
|
-
name='root_agent',
|
245
|
-
model=mock_model,
|
246
|
-
after_tool_callback=MockAfterToolCallback(
|
247
|
-
mock_response={'result': 'after_tool_callback'},
|
248
|
-
modify_tool_response=True,
|
249
|
-
),
|
250
|
-
tools=[simple_function],
|
251
|
-
)
|
252
|
-
|
253
|
-
runner = utils.InMemoryRunner(agent)
|
254
|
-
assert utils.simplify_events(runner.run('test')) == [
|
255
|
-
(
|
256
|
-
'root_agent',
|
257
|
-
Part.from_function_call(
|
258
|
-
name='simple_function', args={'input_str': 'simple_function_call'}
|
259
|
-
),
|
260
|
-
),
|
261
|
-
(
|
262
|
-
'root_agent',
|
263
|
-
Part.from_function_response(
|
264
|
-
name='simple_function',
|
265
|
-
response={'result': 'modified_output'},
|
266
|
-
),
|
267
|
-
),
|
268
|
-
('root_agent', 'response1'),
|
269
|
-
]
|
@@ -1,14 +0,0 @@
|
|
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
|
-
|