You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0299020cc4 | |||
| 5fd6a448de | |||
| 85ccacbf2d | |||
| d45084f311 | |||
| a61d20e3df | |||
| 41564de689 | |||
| 7f76af4d76 | |||
| e7d9cf359a | |||
| cc1ef3f2ad | |||
| 26f55fb5ab | |||
| a4adb739c0 | |||
| 180c2a934b | |||
| c565473bf8 | |||
| 357143c2aa | |||
| d5b3a89fe7 | |||
| e4317c9eb7 | |||
| 794a70edcd | |||
| f96cdc675c | |||
| 1393965720 | |||
| e2ba484b43 | |||
| 28abc306c3 | |||
| fcca0afdac | |||
| 905c20dad6 | |||
| 6dec235c13 | |||
| dbea793cf5 | |||
| a930633fad | |||
| fb3915da3b | |||
| 5824c89ee4 | |||
| 97d29a1d9f | |||
| a7b4c98253 | |||
| ad4226b3d8 | |||
| 9bec05ce86 | |||
| 81aa11f070 | |||
| 6f182821c4 | |||
| 88fe4c58a0 | |||
| a6b3c23f74 | |||
| 5846b24b71 | |||
| 24024f7fc4 | |||
| c74879d849 | |||
| 6595cda037 | |||
| 60d23c028f | |||
| eff5903175 | |||
| da677b7a34 | |||
| 4289e02854 | |||
| bcf1deb582 | |||
| 879064343c | |||
| 8f94a0c7b3 | |||
| 4f48ea1c08 | |||
| 3fddac5813 | |||
| 9b52ce28f5 | |||
| e8fb4ed3fc | |||
| 42f87a9c94 | |||
| d387ab0c38 | |||
| f12300113d | |||
| 6c0a0d69ca | |||
| 23b41c3f94 | |||
| 14933ba470 | |||
| b691904e57 | |||
| 641781bced | |||
| c4e09a2edb | |||
| acbbdb7266 | |||
| 27ce65ff50 | |||
| 926b0ef1a6 | |||
| dbbeb190b0 | |||
| 2a9ddec7e3 | |||
| 2ea4315e9f | |||
| 67b6fbbe01 | |||
| fcbf57466e | |||
| 504aa6ba06 | |||
| 08ac9a117e | |||
| 4ae8d72a8d | |||
| 21736067f9 | |||
| 9a9f7a3765 | |||
| aa7a98ad9d | |||
| 27b214df3e |
@@ -0,0 +1,73 @@
|
||||
# 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.
|
||||
|
||||
name: Check Pyink Formatting
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'src/**/*.py'
|
||||
- 'tests/**/*.py'
|
||||
- 'pyproject.toml'
|
||||
|
||||
jobs:
|
||||
pyink-check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install pyink
|
||||
run: |
|
||||
pip install pyink
|
||||
|
||||
- name: Detect changed Python files
|
||||
id: detect_changes
|
||||
run: |
|
||||
git fetch origin ${{ github.base_ref }}
|
||||
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.py$' || true)
|
||||
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
|
||||
|
||||
- name: Run pyink on changed files
|
||||
if: env.CHANGED_FILES != ''
|
||||
run: |
|
||||
echo "Changed Python files:"
|
||||
echo "$CHANGED_FILES"
|
||||
|
||||
# Run pyink --check
|
||||
set +e
|
||||
pyink --check --config pyproject.toml $CHANGED_FILES
|
||||
RESULT=$?
|
||||
set -e
|
||||
|
||||
if [ $RESULT -ne 0 ]; then
|
||||
echo ""
|
||||
echo "❌ Pyink formatting check failed!"
|
||||
echo "👉 To fix formatting, run locally:"
|
||||
echo ""
|
||||
echo " pyink --config pyproject.toml $CHANGED_FILES"
|
||||
echo ""
|
||||
exit $RESULT
|
||||
fi
|
||||
|
||||
- name: No changed Python files detected
|
||||
if: env.CHANGED_FILES == ''
|
||||
run: |
|
||||
echo "No Python files changed. Skipping pyink check."
|
||||
@@ -1,3 +1,17 @@
|
||||
# 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.
|
||||
|
||||
name: Python Unit Tests
|
||||
|
||||
on:
|
||||
@@ -36,6 +50,5 @@ jobs:
|
||||
source .venv/bin/activate
|
||||
pytest tests/unittests \
|
||||
--ignore=tests/unittests/artifacts/test_artifact_service.py \
|
||||
--ignore=tests/unittests/tools/application_integration_tool/clients/test_connections_client.py \
|
||||
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
|
||||
|
||||
|
||||
+58
-3
@@ -1,11 +1,66 @@
|
||||
# Changelog
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### âš BREAKING CHANGES
|
||||
|
||||
* Updated artifact and memory service interface to be async. Agents that
|
||||
interact with these services through callbacks or tools will now need to
|
||||
adjust their invocation methods to be async (using await), or ensure calls
|
||||
are wrapped in an asynchronous executor like asyncio.run(). Any service that
|
||||
extends the base interface must also be updated.
|
||||
|
||||
### Features
|
||||
|
||||
* Introduced the ability to chain model callbacks.
|
||||
* Added support for async agent and model callbacks.
|
||||
* Added input transcription support for live/streaming.
|
||||
* Captured all agent code error and display on UI.
|
||||
* Set param required tag to False by default in openapi_tool.
|
||||
* Updated evaluation functions to be asynchronous.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Ensured a unique ID is generated for every event.
|
||||
* Fixed the issue when openapi_specparser has parameter.required as None.
|
||||
* Updated the 'type' value on the items/properties nested structures for Anthropic models to adhere to JSON schema.
|
||||
* Fix litellm error issues.
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* Regenerated API docs.
|
||||
* Created a `developer` folder and added samples.
|
||||
* Updated the contributing guide.
|
||||
* Docstring improvements, typo fixings, GitHub action to enforce code styles on formatting and imports, etc.
|
||||
|
||||
## 0.4.0
|
||||
|
||||
### âš BREAKING CHANGES
|
||||
* Set the max size of strings in database columns. MySQL mandates that all VARCHAR-type fields must specify their lengths.
|
||||
* Extract content encode/decode logic to a shared util, resolve issues with JSON serialization, and update key length for DB table to avoid key too long issue in mysql.
|
||||
* Enhance `FunctionTool` to verify if the model is providing all the mandatory arguments.
|
||||
|
||||
### Features
|
||||
* Update ADK setup guide to improve onboarding experience.
|
||||
* feat: add ordering to recent events in database session service.
|
||||
* feat(llm_flows): support async before/after tool callbacks.
|
||||
* feat: Added --replay and --resume options to adk run cli. Check adk run --help for more details.
|
||||
* Created a new Integration Connector Tool (underlying of the ApplicationIntegrationToolSet) so that we do not force LLM to provide default value.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Don't send content with empty text to LLM.
|
||||
* Fix google search reading undefined for `renderedContent`.
|
||||
|
||||
### Miscellaneous Chores
|
||||
* Docstring improvements, typo fixings, github action to enfore code styles on formatting and imports, etc.
|
||||
|
||||
## 0.3.0
|
||||
|
||||
### âš BREAKING CHANGES
|
||||
|
||||
* Auth: expose `access_token` and `refresh_token` at top level of auth
|
||||
credentails, instead of a `dict`
|
||||
credentials, instead of a `dict`
|
||||
([commit](https://github.com/google/adk-python/commit/956fb912e8851b139668b1ccb8db10fd252a6990)).
|
||||
|
||||
### Features
|
||||
@@ -28,7 +83,7 @@
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* README.md impprovements.
|
||||
* README.md improvements.
|
||||
* Various code improvements.
|
||||
* Various typo fixes.
|
||||
* Bump min version of google-genai to 1.11.0.
|
||||
@@ -86,4 +141,4 @@
|
||||
* Built-in evaluation support
|
||||
* Development UI that makes local development easy
|
||||
* Deploy to Google Cloud Run, Agent Engine
|
||||
* (Experimental) Live(Bidi) auido/video agent support and Compositional Function Calling(CFC) support
|
||||
* (Experimental) Live(Bidi) audio/video agent support and Compositional Function Calling(CFC) support
|
||||
|
||||
+122
-2
@@ -2,6 +2,23 @@
|
||||
|
||||
We'd love to accept your patches and contributions to this project.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Before you begin](#before-you-begin)
|
||||
- [Sign our Contributor License Agreement](#sign-our-contributor-license-agreement)
|
||||
- [Review our community guidelines](#review-our-community-guidelines)
|
||||
- [Contribution workflow](#contribution-workflow)
|
||||
- [Finding Issues to Work On](#finding-issues-to-work-on)
|
||||
- [Requirement for PRs](#requirement-for-prs)
|
||||
- [Large or Complex Changes](#large-or-complex-changes)
|
||||
- [Testing Requirements](#testing-requirements)
|
||||
- [Unit Tests](#unit-tests)
|
||||
- [End-to-End (E2E) Tests](#manual-end-to-end-e2e-tests)
|
||||
- [Documentation](#documentation)
|
||||
- [Development Setup](#development-setup)
|
||||
- [Code reviews](#code-reviews)
|
||||
|
||||
|
||||
## Before you begin
|
||||
|
||||
### Sign our Contributor License Agreement
|
||||
@@ -23,14 +40,20 @@ sign a new one.
|
||||
This project follows
|
||||
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
|
||||
|
||||
## Contribution process
|
||||
## Contribution workflow
|
||||
|
||||
### Finding Issues to Work On
|
||||
|
||||
- Browse issues labeled **`good first issue`** (newcomer-friendly) or **`help wanted`** (general contributions).
|
||||
- For other issues, please kindly ask before contributing to avoid duplication.
|
||||
|
||||
|
||||
### Requirement for PRs
|
||||
|
||||
- All PRs, other than small documentation or typo fixes, should have a Issue assoicated. If not, please create one.
|
||||
- Small, focused PRs. Keep changes minimal—one concern per PR.
|
||||
- For bug fixes or features, please provide logs or screenshot after the fix is applied to help reviewers better understand the fix.
|
||||
- Please add corresponding testing for your code change if it's not covered by existing tests.
|
||||
- Please include a `testing plan` section in your PR to talk about how you will test. This will save time for PR review. See `Testing Requirements` section for more details.
|
||||
|
||||
### Large or Complex Changes
|
||||
For substantial features or architectural revisions:
|
||||
@@ -38,6 +61,103 @@ For substantial features or architectural revisions:
|
||||
- Open an Issue First: Outline your proposal, including design considerations and impact.
|
||||
- Gather Feedback: Discuss with maintainers and the community to ensure alignment and avoid duplicate work
|
||||
|
||||
### Testing Requirements
|
||||
|
||||
To maintain code quality and prevent regressions, all code changes must include comprehensive tests and verifiable end-to-end (E2E) evidence.
|
||||
|
||||
|
||||
#### Unit Tests
|
||||
|
||||
Please add or update unit tests for your change. Please include a summary of passed `pytest` results.
|
||||
|
||||
Requirements for unit tests:
|
||||
|
||||
- **Coverage:** Cover new features, edge cases, error conditions, and typical use cases.
|
||||
- **Location:** Add or update tests under `tests/unittests/`, following existing naming conventions (e.g., `test_<module>_<feature>.py`).
|
||||
- **Framework:** Use `pytest`. Tests should be:
|
||||
- Fast and isolated.
|
||||
- Written clearly with descriptive names.
|
||||
- Free of external dependencies (use mocks or fixtures as needed).
|
||||
- **Quality:** Aim for high readability and maintainability; include docstrings or comments for complex scenarios.
|
||||
|
||||
#### Manual End-to-End (E2E) Tests
|
||||
|
||||
Manual E2E tests ensure integrated flows work as intended. Your tests should cover all scenarios. Sometimes, it's also good to ensure relevant functionality is not impacted.
|
||||
|
||||
Depending on your change:
|
||||
|
||||
- **ADK Web:**
|
||||
- Use the `adk web` to verify functionality.
|
||||
- Capture and attach relevant screenshots demonstrating the UI/UX changes or outputs.
|
||||
- Label screenshots clearly in your PR description.
|
||||
|
||||
- **Runner:**
|
||||
- Provide the testing setup. For example, the agent definition, and the runner setup.
|
||||
- Execute the `runner` tool to reproduce workflows.
|
||||
- Include the command used and console output showing test results.
|
||||
- Highlight sections of the log that directly relate to your change.
|
||||
|
||||
### Documentation
|
||||
|
||||
For any changes that impact user-facing documentation (guides, API reference, tutorials), please open a PR in the [adk-docs](https://github.com/google/adk-docs) repository to update relevant part before or alongside your code PR.
|
||||
|
||||
### Development Setup
|
||||
1. **Clone the repository:**
|
||||
|
||||
```shell
|
||||
git clone git@github.com:google/adk-python.git
|
||||
cd adk-python
|
||||
```
|
||||
2. **Create and activate a virtual environment:**
|
||||
|
||||
```shell
|
||||
python -m venv .venv
|
||||
```
|
||||
|
||||
```shell
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
**windows**
|
||||
```shell
|
||||
source .\.venv\Scripts\activate
|
||||
```
|
||||
|
||||
```shell
|
||||
pip install uv
|
||||
```
|
||||
|
||||
3. **Install dependencies:**
|
||||
|
||||
```shell
|
||||
uv sync --all-extras
|
||||
```
|
||||
4. **Run unit tests:**
|
||||
|
||||
```shell
|
||||
uv run pytest ./tests/unittests
|
||||
```
|
||||
5. **Run pyink to format codebase:**
|
||||
|
||||
```shell
|
||||
uv run pyink --config pyproject.toml ./src
|
||||
```
|
||||
|
||||
6. **Build the package**
|
||||
```shell
|
||||
uv build
|
||||
```
|
||||
|
||||
7. **Local Testing**
|
||||
Have a simple testing folder setup as mentioned in the [quickstart](https://google.github.io/adk-docs/get-started/quickstart/)
|
||||
then install the local package with changes after building it using the below command to test the changes.
|
||||
|
||||
```shell
|
||||
uv pip install <YOUR_WHL_FILE_PATH>
|
||||
|
||||
[eg]: uv pip install <ADK_PROJECT_PATH>/dist/google_adk-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
### Code reviews
|
||||
|
||||
All submissions, including submissions by project members, require review. We
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
</h3>
|
||||
</html>
|
||||
|
||||
Agent Development Kit (ADK) is designed for developers seeking fine-grained
|
||||
control and flexibility when building advanced AI agents that are tightly
|
||||
integrated with services in Google Cloud. It allows you to define agent
|
||||
behavior, orchestration, and tool use directly in code, enabling robust
|
||||
debugging, versioning, and deployment anywhere – from your laptop to the cloud.
|
||||
Agent Development Kit (ADK) is a flexible and modular framework for developing and deploying AI agents. While optimized for Gemini and the Google ecosystem, ADK is model-agnostic, deployment-agnostic, and is built for compatibility with other frameworks. ADK was designed to make agent development feel more like software development, to make it easier for developers to create, deploy, and orchestrate agentic architectures that range from simple tasks to complex workflows.
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Application Integration Agent Sample
|
||||
|
||||
## Introduction
|
||||
|
||||
This sample demonstrates how to use the `ApplicationIntegrationToolset` within an ADK agent to interact with external applications, specifically Jira in this case. The agent (`agent.py`) is configured to manage Jira issues using a pre-configured Application Integration connection.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Set up Integration Connection:**
|
||||
* You need an existing [Integration connection](https://cloud.google.com/integration-connectors/docs/overview) configured to interact with your Jira instance. Follow the [documentation](https://google.github.io/adk-docs/tools/google-cloud-tools/#use-integration-connectors) to provision the Integration Connector in Google Cloud and then use this [documentation](https://cloud.google.com/integration-connectors/docs/connectors/jiracloud/configure) to create an JIRA connection. Note the `Connection Name`, `Project ID`, and `Location` of your connection.
|
||||
*
|
||||
|
||||
2. **Configure Environment Variables:**
|
||||
* Create a `.env` file in the same directory as `agent.py` (or add to your existing one).
|
||||
* Add the following variables to the `.env` file, replacing the placeholder values with your actual connection details:
|
||||
|
||||
```dotenv
|
||||
CONNECTION_NAME=<YOUR_JIRA_CONNECTION_NAME>
|
||||
CONNECTION_PROJECT=<YOUR_GOOGLE_CLOUD_PROJECT_ID>
|
||||
CONNECTION_LOCATION=<YOUR_CONNECTION_LOCATION>
|
||||
```
|
||||
|
||||
## How to Use
|
||||
|
||||
1. **Install Dependencies:** Ensure you have the necessary libraries installed (e.g., `google-adk`, `python-dotenv`).
|
||||
2. **Run the Agent:** Execute the agent script from your terminal:
|
||||
```bash
|
||||
python agent.py
|
||||
```
|
||||
3. **Interact:** Once the agent starts, you can interact with it by typing prompts related to Jira issue management.
|
||||
|
||||
## Sample Prompts
|
||||
|
||||
Here are some examples of how you can interact with the agent:
|
||||
|
||||
* `Can you list me all the issues ?`
|
||||
* `Can you list me all the projects ?`
|
||||
* `Can you create an issue: "Bug in product XYZ" in project ABC ?`
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,50 @@
|
||||
# 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.
|
||||
|
||||
"""Sample agent using Application Integration toolset."""
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.tools.application_integration_tool import ApplicationIntegrationToolset
|
||||
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
connection_name = os.getenv("CONNECTION_NAME")
|
||||
connection_project = os.getenv("CONNECTION_PROJECT")
|
||||
connection_location = os.getenv("CONNECTION_LOCATION")
|
||||
|
||||
|
||||
jira_tool = ApplicationIntegrationToolset(
|
||||
project=connection_project,
|
||||
location=connection_location,
|
||||
connection=connection_name,
|
||||
entity_operations={"Issues": [], "Projects": []},
|
||||
tool_name="jira_issue_manager",
|
||||
)
|
||||
|
||||
root_agent = LlmAgent(
|
||||
model="gemini-2.0-flash",
|
||||
name="Issue_Management_Agent",
|
||||
instruction="""
|
||||
You are an agent that helps manage issues in a JIRA instance.
|
||||
Be accurate in your responses based on the tool response. You can perform any formatting in the response that is appropriate or if asked by the user.
|
||||
If there is an error in the tool response, understand the error and try and see if you can fix the error and then and execute the tool again. For example if a variable or parameter is missing, try and see if you can find it in the request or user query or default it and then execute the tool again or check for other tools that could give you the details.
|
||||
If there are any math operations like count or max, min in the user request, call the tool to get the data and perform the math operations and then return the result in the response. For example for maximum, fetch the list and then do the math operation.
|
||||
""",
|
||||
tools=jira_tool.get_tools(),
|
||||
)
|
||||
+15
@@ -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
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
# 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 google.adk import Agent
|
||||
from google.adk.tools.tool_context import ToolContext
|
||||
from google.genai import types
|
||||
|
||||
|
||||
async def log_query(tool_context: ToolContext, query: str):
|
||||
"""Roll a die with the specified number of sides."""
|
||||
await tool_context.save_artifact('query', types.Part(text=query))
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model='gemini-2.0-flash-exp',
|
||||
name='log_agent',
|
||||
description='Log user query.',
|
||||
instruction="""Always log the user query and reploy "kk, I've logged."
|
||||
""",
|
||||
tools=[log_query],
|
||||
generate_content_config=types.GenerateContentConfig(
|
||||
safety_settings=[
|
||||
types.SafetySetting( # avoid false alarm about rolling dice.
|
||||
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
||||
threshold=types.HarmBlockThreshold.OFF,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,51 @@
|
||||
# OAuth Sample
|
||||
|
||||
## Introduction
|
||||
|
||||
This sample tests and demos the OAuth support in ADK via two tools:
|
||||
|
||||
* 1. bigquery_datasets_list:
|
||||
|
||||
List user's datasets.
|
||||
|
||||
* 2. bigquery_datasets_get:
|
||||
Get a dataset's details.
|
||||
|
||||
* 3. bigquery_datasets_insert:
|
||||
Create a new dataset.
|
||||
|
||||
* 4. bigquery_tables_list:
|
||||
List all tables in a dataset.
|
||||
|
||||
* 5. bigquery_tables_get:
|
||||
Get a table's details.
|
||||
|
||||
* 6. bigquery_tables_insert:
|
||||
Insert a new table into a dataset.
|
||||
|
||||
## How to use
|
||||
|
||||
* 1. Follow https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. to get your client id and client secret.
|
||||
Be sure to choose "web" as your client type.
|
||||
|
||||
* 2. Configure your .env file to add two variables:
|
||||
|
||||
* GOOGLE_CLIENT_ID={your client id}
|
||||
* GOOGLE_CLIENT_SECRET={your client secret}
|
||||
|
||||
Note: done't create a separate .env , instead put it to the same .env file that stores your Vertex AI or Dev ML credentials
|
||||
|
||||
* 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui to "Authorized redirect URIs".
|
||||
|
||||
Note: localhost here is just a hostname that you use to access the dev ui, replace it with the actual hostname you use to access the dev ui.
|
||||
|
||||
* 4. For 1st run, allow popup for localhost in Chrome.
|
||||
|
||||
## Sample prompt
|
||||
|
||||
* `Do I have any datasets in project sean-dev-agent ?`
|
||||
* `Do I have any tables under it ?`
|
||||
* `could you get me the details of this table ?`
|
||||
* `Can you help to create a new dataset in the same project? id : sean_test , location: us`
|
||||
* `could you show me the details of this new dataset ?`
|
||||
* `could you create a new table under this dataset ? table name : sean_test_table. column1 : name is id , type is integer, required. column2 : name is info , type is string, required. column3 : name is backup , type is string, optional.`
|
||||
@@ -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
|
||||
@@ -0,0 +1,84 @@
|
||||
# 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.
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from google.adk import Agent
|
||||
from google.adk.tools.google_api_tool import bigquery_tool_set
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
# Access the variable
|
||||
oauth_client_id = os.getenv("OAUTH_CLIENT_ID")
|
||||
oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET")
|
||||
bigquery_tool_set.configure_auth(oauth_client_id, oauth_client_secret)
|
||||
|
||||
bigquery_datasets_list = bigquery_tool_set.get_tool("bigquery_datasets_list")
|
||||
bigquery_datasets_get = bigquery_tool_set.get_tool("bigquery_datasets_get")
|
||||
bigquery_datasets_insert = bigquery_tool_set.get_tool(
|
||||
"bigquery_datasets_insert"
|
||||
)
|
||||
|
||||
bigquery_tables_list = bigquery_tool_set.get_tool("bigquery_tables_list")
|
||||
bigquery_tables_get = bigquery_tool_set.get_tool("bigquery_tables_get")
|
||||
bigquery_tables_insert = bigquery_tool_set.get_tool("bigquery_tables_insert")
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-2.0-flash",
|
||||
name="bigquery_agent",
|
||||
instruction="""
|
||||
You are a helpful Google BigQuery agent that help to manage users' data on Goolge BigQuery.
|
||||
Use the provided tools to conduct various operations on users' data in Google BigQuery.
|
||||
|
||||
Scenario 1:
|
||||
The user wants to query their biguqery datasets
|
||||
Use bigquery_datasets_list to query user's datasets
|
||||
|
||||
Scenario 2:
|
||||
The user wants to query the details of a specific dataset
|
||||
Use bigquery_datasets_get to get a dataset's details
|
||||
|
||||
Scenario 3:
|
||||
The user wants to create a new dataset
|
||||
Use bigquery_datasets_insert to create a new dataset
|
||||
|
||||
Scenario 4:
|
||||
The user wants to query their tables in a specific dataset
|
||||
Use bigquery_tables_list to list all tables in a dataset
|
||||
|
||||
Scenario 5:
|
||||
The user wants to query the details of a specific table
|
||||
Use bigquery_tables_get to get a table's details
|
||||
|
||||
Scenario 6:
|
||||
The user wants to insert a new table into a dataset
|
||||
Use bigquery_tables_insert to insert a new table into a dataset
|
||||
|
||||
Current user:
|
||||
<User>
|
||||
{userInfo?}
|
||||
</User>
|
||||
""",
|
||||
tools=[
|
||||
bigquery_datasets_list,
|
||||
bigquery_datasets_get,
|
||||
bigquery_datasets_insert,
|
||||
bigquery_tables_list,
|
||||
bigquery_tables_get,
|
||||
bigquery_tables_insert,
|
||||
],
|
||||
)
|
||||
@@ -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
|
||||
@@ -0,0 +1,100 @@
|
||||
# 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.
|
||||
|
||||
"""Data science agent."""
|
||||
|
||||
from google.adk.agents.llm_agent import Agent
|
||||
from google.adk.tools import built_in_code_execution
|
||||
|
||||
|
||||
def base_system_instruction():
|
||||
"""Returns: data science agent system instruction."""
|
||||
|
||||
return """
|
||||
# Guidelines
|
||||
|
||||
**Objective:** Assist the user in achieving their data analysis goals within the context of a Python Colab notebook, **with emphasis on avoiding assumptions and ensuring accuracy.** Reaching that goal can involve multiple steps. When you need to generate code, you **don't** need to solve the goal in one go. Only generate the next step at a time.
|
||||
|
||||
**Code Execution:** All code snippets provided will be executed within the Colab environment.
|
||||
|
||||
**Statefulness:** All code snippets are executed and the variables stays in the environment. You NEVER need to re-initialize variables. You NEVER need to reload files. You NEVER need to re-import libraries.
|
||||
|
||||
**Imported Libraries:** The following libraries are ALREADY imported and should NEVER be imported again:
|
||||
|
||||
```tool_code
|
||||
import io
|
||||
import math
|
||||
import re
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import scipy
|
||||
```
|
||||
|
||||
**Output Visibility:** Always print the output of code execution to visualize results, especially for data exploration and analysis. For example:
|
||||
- To look a the shape of a pandas.DataFrame do:
|
||||
```tool_code
|
||||
print(df.shape)
|
||||
```
|
||||
The output will be presented to you as:
|
||||
```tool_outputs
|
||||
(49, 7)
|
||||
|
||||
```
|
||||
- To display the result of a numerical computation:
|
||||
```tool_code
|
||||
x = 10 ** 9 - 12 ** 5
|
||||
print(f'{{x=}}')
|
||||
```
|
||||
The output will be presented to you as:
|
||||
```tool_outputs
|
||||
x=999751168
|
||||
|
||||
```
|
||||
- You **never** generate ```tool_outputs yourself.
|
||||
- You can then use this output to decide on next steps.
|
||||
- Print just variables (e.g., `print(f'{{variable=}}')`.
|
||||
|
||||
**No Assumptions:** **Crucially, avoid making assumptions about the nature of the data or column names.** Base findings solely on the data itself. Always use the information obtained from `explore_df` to guide your analysis.
|
||||
|
||||
**Available files:** Only use the files that are available as specified in the list of available files.
|
||||
|
||||
**Data in prompt:** Some queries contain the input data directly in the prompt. You have to parse that data into a pandas DataFrame. ALWAYS parse all the data. NEVER edit the data that are given to you.
|
||||
|
||||
**Answerability:** Some queries may not be answerable with the available data. In those cases, inform the user why you cannot process their query and suggest what type of data would be needed to fulfill their request.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-2.0-flash-001",
|
||||
name="data_science_agent",
|
||||
instruction=base_system_instruction() + """
|
||||
|
||||
|
||||
You need to assist the user with their queries by looking at the data and the context in the conversation.
|
||||
You final answer should summarize the code and code execution relavant to the user query.
|
||||
|
||||
You should include all pieces of data to answer the user query, such as the table from code execution results.
|
||||
If you cannot answer the question directly, you should follow the guidelines above to generate the next step.
|
||||
If the question can be answered directly with writing any code, you should do that.
|
||||
If you doesn't have enough data to answer the question, you should ask for clarification from the user.
|
||||
|
||||
You should NEVER install any package on your own like `pip install ...`.
|
||||
When plotting trends, you should make sure to sort and order the data by the x-axis.
|
||||
|
||||
|
||||
""",
|
||||
tools=[built_in_code_execution],
|
||||
)
|
||||
@@ -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
|
||||
@@ -0,0 +1,48 @@
|
||||
# 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 google.adk import Agent
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class WeahterData(BaseModel):
|
||||
temperature: str
|
||||
humidity: str
|
||||
wind_speed: str
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
name='root_agent',
|
||||
model='gemini-2.0-flash',
|
||||
instruction="""\
|
||||
Answer user's questions based on the data you have.
|
||||
|
||||
If you don't have the data, you can just say you don't know.
|
||||
|
||||
Here are the data you have for San Jose
|
||||
|
||||
* temperature: 26 C
|
||||
* humidity: 20%
|
||||
* wind_speed: 29 mph
|
||||
|
||||
Here are the data you have for Cupertino
|
||||
|
||||
* temperature: 16 C
|
||||
* humidity: 10%
|
||||
* wind_speed: 13 mph
|
||||
|
||||
""",
|
||||
output_schema=WeahterData,
|
||||
output_key='weather_data',
|
||||
)
|
||||
+15
@@ -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
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
# 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.
|
||||
|
||||
import random
|
||||
|
||||
from google.adk import Agent
|
||||
from google.adk.planners import BuiltInPlanner
|
||||
from google.adk.planners import PlanReActPlanner
|
||||
from google.adk.tools.tool_context import ToolContext
|
||||
from google.genai import types
|
||||
|
||||
|
||||
def roll_die(sides: int, tool_context: ToolContext) -> int:
|
||||
"""Roll a die and return the rolled result.
|
||||
|
||||
Args:
|
||||
sides: The integer number of sides the die has.
|
||||
|
||||
Returns:
|
||||
An integer of the result of rolling the die.
|
||||
"""
|
||||
result = random.randint(1, sides)
|
||||
if not 'rolls' in tool_context.state:
|
||||
tool_context.state['rolls'] = []
|
||||
|
||||
tool_context.state['rolls'] = tool_context.state['rolls'] + [result]
|
||||
return result
|
||||
|
||||
|
||||
async def check_prime(nums: list[int]) -> str:
|
||||
"""Check if a given list of numbers are prime.
|
||||
|
||||
Args:
|
||||
nums: The list of numbers to check.
|
||||
|
||||
Returns:
|
||||
A str indicating which number is prime.
|
||||
"""
|
||||
primes = set()
|
||||
for number in nums:
|
||||
number = int(number)
|
||||
if number <= 1:
|
||||
continue
|
||||
is_prime = True
|
||||
for i in range(2, int(number**0.5) + 1):
|
||||
if number % i == 0:
|
||||
is_prime = False
|
||||
break
|
||||
if is_prime:
|
||||
primes.add(number)
|
||||
return (
|
||||
'No prime numbers found.'
|
||||
if not primes
|
||||
else f"{', '.join(str(num) for num in primes)} are prime numbers."
|
||||
)
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model='gemini-2.5-pro-preview-03-25',
|
||||
# model='gemini-2.0-flash',
|
||||
name='data_processing_agent',
|
||||
description=(
|
||||
'hello world agent that can roll a dice of 8 sides and check prime'
|
||||
' numbers.'
|
||||
),
|
||||
instruction="""
|
||||
You roll dice and answer questions about the outcome of the dice rolls.
|
||||
You can roll dice of different sizes.
|
||||
You can use multiple tools in parallel by calling functions in parallel(in one request and in one round).
|
||||
It is ok to discuss previous dice roles, and comment on the dice rolls.
|
||||
When you are asked to roll a die, you must call the roll_die tool with the number of sides. Be sure to pass in an integer. Do not pass in a string.
|
||||
You should never roll a die on your own.
|
||||
When checking prime numbers, call the check_prime tool with a list of integers. Be sure to pass in a list of integers. You should never pass in a string.
|
||||
You should not check prime numbers before calling the tool.
|
||||
When you are asked to roll a die and check prime numbers, you should always make the following two function calls:
|
||||
1. You should first call the roll_die tool to get a roll. Wait for the function response before calling the check_prime tool.
|
||||
2. After you get the function response from roll_die tool, you should call the check_prime tool with the roll_die result.
|
||||
2.1 If user asks you to check primes based on previous rolls, make sure you include the previous rolls in the list.
|
||||
3. When you respond, you must include the roll_die result from step 1.
|
||||
You should always perform the previous 3 steps when asking for a roll and checking prime numbers.
|
||||
You should not rely on the previous history on prime results.
|
||||
""",
|
||||
tools=[
|
||||
roll_die,
|
||||
check_prime,
|
||||
],
|
||||
planner=BuiltInPlanner(
|
||||
thinking_config=types.ThinkingConfig(
|
||||
include_thoughts=True,
|
||||
),
|
||||
),
|
||||
# planner=PlanReActPlanner(),
|
||||
generate_content_config=types.GenerateContentConfig(
|
||||
safety_settings=[
|
||||
types.SafetySetting( # avoid false alarm about rolling dice.
|
||||
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
||||
threshold=types.HarmBlockThreshold.OFF,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
# 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.
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import warnings
|
||||
|
||||
import agent
|
||||
from dotenv import load_dotenv
|
||||
from google.adk import Runner
|
||||
from google.adk.artifacts import InMemoryArtifactService
|
||||
from google.adk.cli.utils import logs
|
||||
from google.adk.sessions import InMemorySessionService
|
||||
from google.adk.sessions import Session
|
||||
from google.genai import types
|
||||
|
||||
load_dotenv(override=True)
|
||||
warnings.filterwarnings('ignore', category=UserWarning)
|
||||
logs.log_to_tmp_folder()
|
||||
|
||||
|
||||
async def main():
|
||||
app_name = 'my_app'
|
||||
user_id_1 = 'user1'
|
||||
session_service = InMemorySessionService()
|
||||
artifact_service = InMemoryArtifactService()
|
||||
runner = Runner(
|
||||
app_name=app_name,
|
||||
agent=agent.root_agent,
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
)
|
||||
session_11 = session_service.create_session(app_name, user_id_1)
|
||||
|
||||
async def run_prompt(session: Session, new_message: str):
|
||||
content = types.Content(
|
||||
role='user', parts=[types.Part.from_text(text=new_message)]
|
||||
)
|
||||
print('** User says:', content.model_dump(exclude_none=True))
|
||||
async for event in runner.run_async(
|
||||
user_id=user_id_1,
|
||||
session_id=session.id,
|
||||
new_message=content,
|
||||
):
|
||||
if event.content.parts and event.content.parts[0].text:
|
||||
print(f'** {event.author}: {event.content.parts[0].text}')
|
||||
|
||||
start_time = time.time()
|
||||
print('Start time:', start_time)
|
||||
print('------------------------------------')
|
||||
await run_prompt(session_11, 'Hi')
|
||||
await run_prompt(session_11, 'Roll a die.')
|
||||
await run_prompt(session_11, 'Roll a die again.')
|
||||
await run_prompt(session_11, 'What numbers did I got?')
|
||||
end_time = time.time()
|
||||
print('------------------------------------')
|
||||
print('End time:', end_time)
|
||||
print('Total time:', end_time - start_time)
|
||||
|
||||
|
||||
def main_sync():
|
||||
app_name = 'my_app'
|
||||
user_id_1 = 'user1'
|
||||
session_service = InMemorySessionService()
|
||||
artifact_service = InMemoryArtifactService()
|
||||
runner = Runner(
|
||||
app_name=app_name,
|
||||
agent=agent.root_agent,
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
)
|
||||
session_11 = session_service.create_session(app_name, user_id_1)
|
||||
|
||||
def run_prompt(session: Session, new_message: str):
|
||||
content = types.Content(
|
||||
role='user', parts=[types.Part.from_text(text=new_message)]
|
||||
)
|
||||
print('** User says:', content.model_dump(exclude_none=True))
|
||||
for event in runner.run_sync(
|
||||
session=session,
|
||||
new_message=content,
|
||||
):
|
||||
if event.content.parts and event.content.parts[0].text:
|
||||
print(f'** {event.author}: {event.content.parts[0].text}')
|
||||
|
||||
start_time = time.time()
|
||||
print('Start time:', start_time)
|
||||
print('------------------------------------')
|
||||
run_prompt(session_11, 'Hi')
|
||||
run_prompt(session_11, 'Roll a die.')
|
||||
run_prompt(session_11, 'Roll a die again.')
|
||||
run_prompt(session_11, 'What numbers did I got?')
|
||||
end_time = time.time()
|
||||
print('------------------------------------')
|
||||
print('End time:', end_time)
|
||||
print('Total time:', end_time - start_time)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
main_sync()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user