mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-12-19 03:42:22 -06:00
No public description
PiperOrigin-RevId: 748777998
This commit is contained in:
committed by
hangfei
parent
290058eb05
commit
61d4be2d76
1
tests/integration/fixture/context_update_test/OWNERS
Normal file
1
tests/integration/fixture/context_update_test/OWNERS
Normal file
@@ -0,0 +1 @@
|
||||
gkcng
|
||||
15
tests/integration/fixture/context_update_test/__init__.py
Normal file
15
tests/integration/fixture/context_update_test/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from . import agent
|
||||
43
tests/integration/fixture/context_update_test/agent.py
Normal file
43
tests/integration/fixture/context_update_test/agent.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from typing import List
|
||||
from typing import Union
|
||||
|
||||
from google.adk import Agent
|
||||
from google.adk.tools import ToolContext
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def update_fc(
|
||||
data_one: str,
|
||||
data_two: Union[int, float, str],
|
||||
data_three: list[str],
|
||||
data_four: List[Union[int, float, str]],
|
||||
tool_context: ToolContext,
|
||||
):
|
||||
"""Simply ask to update these variables in the context"""
|
||||
tool_context.actions.update_state("data_one", data_one)
|
||||
tool_context.actions.update_state("data_two", data_two)
|
||||
tool_context.actions.update_state("data_three", data_three)
|
||||
tool_context.actions.update_state("data_four", data_four)
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-1.5-flash",
|
||||
name="root_agent",
|
||||
instruction="Call tools",
|
||||
flow="auto",
|
||||
tools=[update_fc],
|
||||
)
|
||||
@@ -0,0 +1,582 @@
|
||||
{
|
||||
"id": "ead43200-b575-4241-9248-233b4be4f29a",
|
||||
"context": {
|
||||
"_time": "2024-12-01 09:02:43.531503",
|
||||
"data_one": "RRRR",
|
||||
"data_two": "3.141529",
|
||||
"data_three": [
|
||||
"apple",
|
||||
"banana"
|
||||
],
|
||||
"data_four": [
|
||||
"1",
|
||||
"hello",
|
||||
"3.14"
|
||||
]
|
||||
},
|
||||
"events": [
|
||||
{
|
||||
"invocation_id": "6BGrtKJu",
|
||||
"author": "user",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "hi"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"options": {},
|
||||
"id": "ltzQTqR4",
|
||||
"timestamp": 1733043686.8428597
|
||||
},
|
||||
{
|
||||
"invocation_id": "6BGrtKJu",
|
||||
"author": "root_agent",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hello! 👋 How can I help you today? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"options": {
|
||||
"partial": false
|
||||
},
|
||||
"id": "ClSROx8b",
|
||||
"timestamp": 1733043688.1030986
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"author": "user",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "update data_one to be RRRR, data_two to be 3.141529, data_three to be apple and banana, data_four to be 1, hello, and 3.14"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"options": {},
|
||||
"id": "yxigGwIZ",
|
||||
"timestamp": 1733043745.9900541
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"author": "root_agent",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"function_call": {
|
||||
"args": {
|
||||
"data_four": [
|
||||
"1",
|
||||
"hello",
|
||||
"3.14"
|
||||
],
|
||||
"data_two": "3.141529",
|
||||
"data_three": [
|
||||
"apple",
|
||||
"banana"
|
||||
],
|
||||
"data_one": "RRRR"
|
||||
},
|
||||
"name": "update_fc"
|
||||
}
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"options": {
|
||||
"partial": false
|
||||
},
|
||||
"id": "8V6de8th",
|
||||
"timestamp": 1733043747.4545543
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"author": "root_agent",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"function_response": {
|
||||
"name": "update_fc",
|
||||
"response": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"options": {
|
||||
"update_context": {
|
||||
"data_one": "RRRR",
|
||||
"data_two": "3.141529",
|
||||
"data_three": [
|
||||
"apple",
|
||||
"banana"
|
||||
],
|
||||
"data_four": [
|
||||
"1",
|
||||
"hello",
|
||||
"3.14"
|
||||
]
|
||||
},
|
||||
"function_call_event_id": "8V6de8th"
|
||||
},
|
||||
"id": "dkTj5v8B",
|
||||
"timestamp": 1733043747.457031
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"author": "root_agent",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "OK. I've updated the data. Anything else? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"options": {
|
||||
"partial": false
|
||||
},
|
||||
"id": "OZ77XR41",
|
||||
"timestamp": 1733043748.7901294
|
||||
}
|
||||
],
|
||||
"past_events": [],
|
||||
"pending_events": {},
|
||||
"artifacts": {},
|
||||
"event_logs": [
|
||||
{
|
||||
"invocation_id": "6BGrtKJu",
|
||||
"event_id": "ClSROx8b",
|
||||
"model_request": {
|
||||
"model": "gemini-1.5-flash",
|
||||
"contents": [
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "hi"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"system_instruction": "You are an agent. Your name is root_agent.\nCall tools",
|
||||
"tools": [
|
||||
{
|
||||
"function_declarations": [
|
||||
{
|
||||
"description": "Hello",
|
||||
"name": "update_fc",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"data_one": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_two": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_three": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"data_four": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"any_of": [
|
||||
{
|
||||
"type": "INTEGER"
|
||||
},
|
||||
{
|
||||
"type": "NUMBER"
|
||||
},
|
||||
{
|
||||
"type": "STRING"
|
||||
}
|
||||
],
|
||||
"type": "STRING"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"model_response": {
|
||||
"candidates": [
|
||||
{
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hello! 👋 How can I help you today? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"avg_logprobs": -0.15831730915949896,
|
||||
"finish_reason": "STOP",
|
||||
"safety_ratings": [
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.071777344,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.07080078
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.16308594,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.14160156
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.09423828,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.037841797
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.059326172,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.02368164
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"model_version": "gemini-1.5-flash-001",
|
||||
"usage_metadata": {
|
||||
"candidates_token_count": 13,
|
||||
"prompt_token_count": 32,
|
||||
"total_token_count": 45
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"event_id": "8V6de8th",
|
||||
"model_request": {
|
||||
"model": "gemini-1.5-flash",
|
||||
"contents": [
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "hi"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hello! 👋 How can I help you today? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "update data_one to be RRRR, data_two to be 3.141529, data_three to be apple and banana, data_four to be 1, hello, and 3.14"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"system_instruction": "You are an agent. Your name is root_agent.\nCall tools",
|
||||
"tools": [
|
||||
{
|
||||
"function_declarations": [
|
||||
{
|
||||
"description": "Hello",
|
||||
"name": "update_fc",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"data_one": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_two": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_three": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"data_four": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"any_of": [
|
||||
{
|
||||
"type": "INTEGER"
|
||||
},
|
||||
{
|
||||
"type": "NUMBER"
|
||||
},
|
||||
{
|
||||
"type": "STRING"
|
||||
}
|
||||
],
|
||||
"type": "STRING"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"model_response": {
|
||||
"candidates": [
|
||||
{
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"function_call": {
|
||||
"args": {
|
||||
"data_four": [
|
||||
"1",
|
||||
"hello",
|
||||
"3.14"
|
||||
],
|
||||
"data_two": "3.141529",
|
||||
"data_three": [
|
||||
"apple",
|
||||
"banana"
|
||||
],
|
||||
"data_one": "RRRR"
|
||||
},
|
||||
"name": "update_fc"
|
||||
}
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"avg_logprobs": -2.100960955431219e-6,
|
||||
"finish_reason": "STOP",
|
||||
"safety_ratings": [
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.12158203,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.13671875
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.421875,
|
||||
"severity": "HARM_SEVERITY_LOW",
|
||||
"severity_score": 0.24511719
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.15722656,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.072753906
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.083984375,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.03564453
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"model_version": "gemini-1.5-flash-001",
|
||||
"usage_metadata": {
|
||||
"candidates_token_count": 32,
|
||||
"prompt_token_count": 94,
|
||||
"total_token_count": 126
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"invocation_id": "M3dUcVa8",
|
||||
"event_id": "OZ77XR41",
|
||||
"model_request": {
|
||||
"model": "gemini-1.5-flash",
|
||||
"contents": [
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "hi"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Hello! 👋 How can I help you today? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "update data_one to be RRRR, data_two to be 3.141529, data_three to be apple and banana, data_four to be 1, hello, and 3.14"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"function_call": {
|
||||
"args": {
|
||||
"data_four": [
|
||||
"1",
|
||||
"hello",
|
||||
"3.14"
|
||||
],
|
||||
"data_two": "3.141529",
|
||||
"data_three": [
|
||||
"apple",
|
||||
"banana"
|
||||
],
|
||||
"data_one": "RRRR"
|
||||
},
|
||||
"name": "update_fc"
|
||||
}
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"function_response": {
|
||||
"name": "update_fc",
|
||||
"response": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"system_instruction": "You are an agent. Your name is root_agent.\nCall tools",
|
||||
"tools": [
|
||||
{
|
||||
"function_declarations": [
|
||||
{
|
||||
"description": "Hello",
|
||||
"name": "update_fc",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"data_one": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_two": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"data_three": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"data_four": {
|
||||
"type": "ARRAY",
|
||||
"items": {
|
||||
"any_of": [
|
||||
{
|
||||
"type": "INTEGER"
|
||||
},
|
||||
{
|
||||
"type": "NUMBER"
|
||||
},
|
||||
{
|
||||
"type": "STRING"
|
||||
}
|
||||
],
|
||||
"type": "STRING"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"model_response": {
|
||||
"candidates": [
|
||||
{
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "OK. I've updated the data. Anything else? \n"
|
||||
}
|
||||
],
|
||||
"role": "model"
|
||||
},
|
||||
"avg_logprobs": -0.22089435373033797,
|
||||
"finish_reason": "STOP",
|
||||
"safety_ratings": [
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.04663086,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.09423828
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.18554688,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.111328125
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.071777344,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.03112793
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"probability": "NEGLIGIBLE",
|
||||
"probability_score": 0.043945313,
|
||||
"severity": "HARM_SEVERITY_NEGLIGIBLE",
|
||||
"severity_score": 0.057373047
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"model_version": "gemini-1.5-flash-001",
|
||||
"usage_metadata": {
|
||||
"candidates_token_count": 14,
|
||||
"prompt_token_count": 129,
|
||||
"total_token_count": 143
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user