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
153 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d809eb9d9 | |||
| f67ccf32c3 | |||
| 5115474f2b | |||
| de7c9c6509 | |||
| 9eef4464c6 | |||
| 1bfc7590b4 | |||
| 3f21a52853 | |||
| 74454170a3 | |||
| ae7d19a4c6 | |||
| 171b1145ee | |||
| 9932015f3b | |||
| 3f117391a5 | |||
| 0497fc578c | |||
| 3b5232c14f | |||
| 9e767b3fe1 | |||
| 2ad1f79422 | |||
| e278ca9541 | |||
| 9324801b75 | |||
| f592de4cc0 | |||
| 57de9634de | |||
| 729001fc0b | |||
| 0d7d7918b6 | |||
| 482099c925 | |||
| 021aaddf32 | |||
| 74b8841e62 | |||
| 186b5de826 | |||
| 03f167c1d3 | |||
| 93e8f020ed | |||
| a1ddf0b6cc | |||
| 801549f734 | |||
| f83504dffb | |||
| 11ca528090 | |||
| 76116c8008 | |||
| 939b45a1c8 | |||
| 015c667917 | |||
| 66a6f94fbc | |||
| 9e9dfa7472 | |||
| 5ee17a3268 | |||
| 370eed1c7a | |||
| 6e0ea01fcb | |||
| 2f006264ce | |||
| d0f117ebbc | |||
| dcb50effef | |||
| f384793649 | |||
| 05a853bc91 | |||
| 12507dc6cc | |||
| 755ce74550 | |||
| b72573c57d | |||
| eb076a9ee8 | |||
| fe5a5494e9 | |||
| f0e11c72ab | |||
| 770ecd8bb3 | |||
| e62e15e720 | |||
| a786f75968 | |||
| 01a21e40d0 | |||
| 69f7ed8d0e | |||
| ebfe8fe51c | |||
| cb000e5a94 | |||
| 01cf186299 | |||
| 04820cb0a7 | |||
| 509db3f9fb | |||
| 4d5760917d | |||
| d27fe90d37 | |||
| 1c23556225 | |||
| a71d9ea9a1 | |||
| fccd17df6f | |||
| 4c6820e78c | |||
| bdd678db31 | |||
| f298d07579 | |||
| c399c50be5 | |||
| 05917cabbd | |||
| 1804ca39a6 | |||
| 5b3204c356 | |||
| d161a2c3f7 | |||
| 95f994d7ca | |||
| 3ea9eca929 | |||
| 2214c1558f | |||
| 4a0751941b | |||
| 9c2358e2a5 | |||
| 3686608f8d | |||
| ada24d7171 | |||
| ee674ce0ef | |||
| 2cb74dd20e | |||
| 293f406148 | |||
| bc43a1196a | |||
| dc90c91ed1 | |||
| 22e4210b47 | |||
| b67182c50f | |||
| 71bd808a14 | |||
| b33bdb9a03 | |||
| fc40226ec0 | |||
| 14cf910ce6 | |||
| 00e0035c8a | |||
| 30947b48b8 | |||
| 825f5d4f2e | |||
| 6f00df3df0 | |||
| da55b5a943 | |||
| d046367826 | |||
| 9647426500 | |||
| 1f0fd7bfce | |||
| 66553b18c6 | |||
| 933f01b89f | |||
| d6cf660506 | |||
| 931fb338f8 | |||
| af978fe194 | |||
| 4def3f1bd3 | |||
| ff9de71869 | |||
| f6bdd555fb | |||
| cf06cc507a | |||
| 303af440ee | |||
| 82b8e304ec | |||
| 4188673b0f | |||
| 39f78dc28f | |||
| c4d5e3b298 | |||
| 08c9cf86c3 | |||
| dd8e9b71e5 | |||
| d740b93e03 | |||
| 2d84b13219 | |||
| 80813a75cf | |||
| d35b99e6dd | |||
| 722028801a | |||
| 57d1315533 | |||
| d19927b1bc | |||
| 6a04ff84ba | |||
| 27b229719e | |||
| 05a0c6b307 | |||
| df0892a7b8 | |||
| 660c2efa4d | |||
| 1237d5334f | |||
| 993f9971bb | |||
| 5462862795 | |||
| c39f24f072 | |||
| 847c8fd11a | |||
| f15f64af0f | |||
| 70a6bfae90 | |||
| 4c4cfb74ae | |||
| 812485fdfa | |||
| cdb4cac237 | |||
| 16014764b6 | |||
| 9a8c77e04a | |||
| 4c191ba6b9 | |||
| 2a0524692b | |||
| 166df01236 | |||
| c4ecef54bc | |||
| 415104743d | |||
| 33acb26565 | |||
| ac97fc638f | |||
| dc5c23c675 | |||
| 8c78945ec9 | |||
| 7dffb59096 | |||
| 4d7298e4f2 | |||
| 8963300518 | |||
| 2cbbf88135 |
@@ -1,5 +1,60 @@
|
||||
# Changelog
|
||||
|
||||
## 1.0.0
|
||||
|
||||
### âš BREAKING CHANGES
|
||||
|
||||
* Evaluation dataset schema is finalized with strong-type pydantic models.
|
||||
(previously saved eval file needs re-generation, for both adk eval cli and
|
||||
the eval tab in adk web UI).
|
||||
* `BuiltInCodeExecutor` (in code_executors package) replaces
|
||||
`BuiltInCodeExecutionTool` (previously in tools package).
|
||||
* All methods in services are now async, including session service, artifact
|
||||
service and memory service.
|
||||
* `list_events` and `close_session` methods are removed from session service.
|
||||
* agent.py file structure with MCP tools are now easier and simpler ([now](https://github.com/google/adk-python/blob/3b5232c14f48e1d5b170f3698d91639b079722c8/contributing/samples/mcp_stdio_server_agent/agent.py#L33) vs [before](https://github.com/google/adk-python/blob/a4adb739c0d86b9ae4587547d2653d568f6567f2/contributing/samples/mcp_agent/agent.py#L41)).
|
||||
Old format is not working anymore.
|
||||
* `Memory` schema and `MemoryService` is redesigned.
|
||||
* Mark various class attributes as private in the classes in the `tools` package.
|
||||
* Disabled session state injection if instruction provider is used.
|
||||
(so that you can have `{var_name}` in the instruction, which is required for code snippets)
|
||||
* Toolbox integration is revamped: tools/toolbox_tool.py → tools/toolbox_toolset.py.
|
||||
* Removes the experimental `remote_agent.py`. We'll redesign it and bring it back.
|
||||
|
||||
### Features
|
||||
|
||||
* Dev UI:
|
||||
* A brand new trace view for overall agent invocation.
|
||||
* A revamped evaluation tab and comparison view for checking eval results.
|
||||
* Introduced `BaseToolset` to allow dynamically add/remove tools for agents.
|
||||
* Revamped MCPToolset with the new BaseToolset interface.
|
||||
* Revamped GoogleApiTool, GoogleApiToolset and ApplicationIntegrationToolset with the new BaseToolset interface.
|
||||
* Resigned agent.py file structure when needing MCPToolset.
|
||||
* Added ToolboxToolset.
|
||||
* Redesigned strong-typed agent evaluation schema.
|
||||
* Allows users to create more cohesive eval sets.
|
||||
* Allows evals to be extended for non-text modality.
|
||||
* Allows for a structured interaction with the uber eval system.
|
||||
* Redesigned Memory schema and MemoryService interfaces.
|
||||
* Added token usage to LlmResponse.
|
||||
* Allowed specifying `--adk_version` in `adk deploy cloud_run` cli. Default is the current version.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed `adk deploy cloud_run` failing bug.
|
||||
* Fixed logs not being printed due to `google-auth` library.
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* Display full help text when adk cli receives invalid arguments.
|
||||
* `adk web` now binds `127.0.0.1` by default, instead of 0.0.0.0.
|
||||
* `InMemoryRunner` now takes `BaseAgent` in constructor.
|
||||
* Various docstring improvements.
|
||||
* Various UI tweaks.
|
||||
* Various bug fixes.
|
||||
* Update various contributing/samples for contributors to validate the implementation.
|
||||
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### âš BREAKING CHANGES
|
||||
|
||||
+27
-30
@@ -4,21 +4,21 @@ 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)
|
||||
- [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)
|
||||
- [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
|
||||
@@ -44,13 +44,13 @@ This project follows
|
||||
|
||||
### Finding Issues to Work On
|
||||
|
||||
- Browse issues labeled **`good first issue`** (newcomer-friendly) or **`help wanted`** (general contributions).
|
||||
- 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.
|
||||
- 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 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.
|
||||
@@ -72,12 +72,12 @@ Please add or update unit tests for your change. Please include a summary of pas
|
||||
|
||||
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).
|
||||
- **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
|
||||
@@ -86,15 +86,15 @@ Manual E2E tests ensure integrated flows work as intended. Your tests should cov
|
||||
|
||||
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.
|
||||
- **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.
|
||||
- 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
|
||||
@@ -117,19 +117,16 @@ For any changes that impact user-facing documentation (guides, API reference, tu
|
||||
```shell
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
|
||||
**windows**
|
||||
```shell
|
||||
source .\.venv\Scripts\activate
|
||||
```
|
||||
|
||||
```shell
|
||||
pip install uv
|
||||
```
|
||||
|
||||
3. **Install dependencies:**
|
||||
|
||||
```shell
|
||||
pip install uv
|
||||
uv sync --all-extras
|
||||
```
|
||||
4. **Run unit tests:**
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 463 KiB After Width: | Height: | Size: 413 KiB |
@@ -20,7 +20,6 @@ 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()
|
||||
|
||||
@@ -29,12 +28,12 @@ connection_project = os.getenv("CONNECTION_PROJECT")
|
||||
connection_location = os.getenv("CONNECTION_LOCATION")
|
||||
|
||||
|
||||
jira_tool = ApplicationIntegrationToolset(
|
||||
jira_toolset = ApplicationIntegrationToolset(
|
||||
project=connection_project,
|
||||
location=connection_location,
|
||||
connection=connection_name,
|
||||
entity_operations={"Issues": [], "Projects": []},
|
||||
tool_name="jira_issue_manager",
|
||||
tool_name_prefix="jira_issue_manager",
|
||||
)
|
||||
|
||||
root_agent = LlmAgent(
|
||||
@@ -46,5 +45,5 @@ root_agent = LlmAgent(
|
||||
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(),
|
||||
tools=[jira_toolset],
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ async def log_query(tool_context: ToolContext, query: str):
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model='gemini-2.0-flash-exp',
|
||||
model='gemini-2.0-flash',
|
||||
name='log_agent',
|
||||
description='Log user query.',
|
||||
instruction="""Always log the user query and reploy "kk, I've logged."
|
||||
|
||||
@@ -16,7 +16,7 @@ import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from google.adk import Agent
|
||||
from google.adk.tools.google_api_tool import bigquery_tool_set
|
||||
from google.adk.tools.google_api_tool import BigQueryToolset
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
@@ -24,24 +24,25 @@ 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"
|
||||
tools_to_expose = [
|
||||
"bigquery_datasets_list",
|
||||
"bigquery_datasets_get",
|
||||
"bigquery_datasets_insert",
|
||||
"bigquery_tables_list",
|
||||
"bigquery_tables_get",
|
||||
"bigquery_tables_insert",
|
||||
]
|
||||
bigquery_toolset = BigQueryToolset(
|
||||
client_id=oauth_client_id,
|
||||
client_secret=oauth_client_secret,
|
||||
tool_filter=tools_to_expose,
|
||||
)
|
||||
|
||||
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.
|
||||
You are a helpful Google BigQuery agent that help to manage users' data on Google BigQuery.
|
||||
Use the provided tools to conduct various operations on users' data in Google BigQuery.
|
||||
|
||||
Scenario 1:
|
||||
@@ -73,12 +74,5 @@ root_agent = Agent(
|
||||
{userInfo?}
|
||||
</User>
|
||||
""",
|
||||
tools=[
|
||||
bigquery_datasets_list,
|
||||
bigquery_datasets_get,
|
||||
bigquery_datasets_insert,
|
||||
bigquery_tables_list,
|
||||
bigquery_tables_get,
|
||||
bigquery_tables_insert,
|
||||
],
|
||||
tools=[bigquery_toolset],
|
||||
)
|
||||
|
||||
Executable
+198
@@ -0,0 +1,198 @@
|
||||
# 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."
|
||||
)
|
||||
|
||||
|
||||
async def before_agent_callback(callback_context):
|
||||
print('@before_agent_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def after_agent_callback(callback_context):
|
||||
print('@after_agent_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def before_model_callback(callback_context, llm_request):
|
||||
print('@before_model_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def after_model_callback(callback_context, llm_response):
|
||||
print('@after_model_callback')
|
||||
return None
|
||||
|
||||
|
||||
def after_agent_cb1(callback_context):
|
||||
print('@after_agent_cb1')
|
||||
|
||||
|
||||
def after_agent_cb2(callback_context):
|
||||
print('@after_agent_cb2')
|
||||
# ModelContent (or Content with role set to 'model') must be returned.
|
||||
# Otherwise, the event will be excluded from the context in the next turn.
|
||||
return types.ModelContent(
|
||||
parts=[
|
||||
types.Part(
|
||||
text='(stopped) after_agent_cb2',
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def after_agent_cb3(callback_context):
|
||||
print('@after_agent_cb3')
|
||||
|
||||
|
||||
def before_agent_cb1(callback_context):
|
||||
print('@before_agent_cb1')
|
||||
|
||||
|
||||
def before_agent_cb2(callback_context):
|
||||
print('@before_agent_cb2')
|
||||
|
||||
|
||||
def before_agent_cb3(callback_context):
|
||||
print('@before_agent_cb3')
|
||||
|
||||
|
||||
def before_tool_cb1(tool, args, tool_context):
|
||||
print('@before_tool_cb1')
|
||||
|
||||
|
||||
def before_tool_cb2(tool, args, tool_context):
|
||||
print('@before_tool_cb2')
|
||||
|
||||
|
||||
def before_tool_cb3(tool, args, tool_context):
|
||||
print('@before_tool_cb3')
|
||||
|
||||
|
||||
def after_tool_cb1(tool, args, tool_context, tool_response):
|
||||
print('@after_tool_cb1')
|
||||
|
||||
|
||||
def after_tool_cb2(tool, args, tool_context, tool_response):
|
||||
print('@after_tool_cb2')
|
||||
return {'test': 'after_tool_cb2', 'response': tool_response}
|
||||
|
||||
|
||||
def after_tool_cb3(tool, args, tool_context, tool_response):
|
||||
print('@after_tool_cb3')
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
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,
|
||||
# ),
|
||||
# ),
|
||||
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,
|
||||
),
|
||||
]
|
||||
),
|
||||
before_agent_callback=[
|
||||
before_agent_cb1,
|
||||
before_agent_cb2,
|
||||
before_agent_cb3,
|
||||
],
|
||||
after_agent_callback=[after_agent_cb1, after_agent_cb2, after_agent_cb3],
|
||||
before_model_callback=before_model_callback,
|
||||
after_model_callback=after_model_callback,
|
||||
before_tool_callback=[before_tool_cb1, before_tool_cb2, before_tool_cb3],
|
||||
after_tool_callback=[after_tool_cb1, after_tool_cb2, after_tool_cb3],
|
||||
)
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
# 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 = await session_service.create_session(
|
||||
app_name=app_name, user_id=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 with 100 sides')
|
||||
await run_prompt(session_11, 'Roll a die again with 100 sides.')
|
||||
await run_prompt(session_11, 'What numbers did I got?')
|
||||
print(
|
||||
await artifact_service.list_artifact_keys(
|
||||
app_name=app_name, user_id=user_id_1, session_id=session_11.id
|
||||
)
|
||||
)
|
||||
end_time = time.time()
|
||||
print('------------------------------------')
|
||||
print('End time:', end_time)
|
||||
print('Total time:', end_time - start_time)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
@@ -15,7 +15,7 @@
|
||||
"""Data science agent."""
|
||||
|
||||
from google.adk.agents.llm_agent import Agent
|
||||
from google.adk.tools import built_in_code_execution
|
||||
from google.adk.code_executors.built_in_code_executor import BuiltInCodeExecutor
|
||||
|
||||
|
||||
def base_system_instruction():
|
||||
@@ -96,5 +96,5 @@ When plotting trends, you should make sure to sort and order the data by the x-a
|
||||
|
||||
|
||||
""",
|
||||
tools=[built_in_code_execution],
|
||||
code_executor=BuiltInCodeExecutor(),
|
||||
)
|
||||
|
||||
+1
-40
@@ -41,7 +41,7 @@ async def main():
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
)
|
||||
session_11 = session_service.create_session(app_name, user_id_1)
|
||||
session_11 = await session_service.create_session(app_name, user_id_1)
|
||||
|
||||
async def run_prompt(session: Session, new_message: str):
|
||||
content = types.Content(
|
||||
@@ -69,44 +69,5 @@ async def main():
|
||||
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()
|
||||
@@ -65,60 +65,8 @@ async def check_prime(nums: list[int]) -> str:
|
||||
else f"{', '.join(str(num) for num in primes)} are prime numbers."
|
||||
)
|
||||
|
||||
|
||||
async def before_agent_callback(callback_context):
|
||||
print('@before_agent_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def after_agent_callback(callback_context):
|
||||
print('@after_agent_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def before_model_callback(callback_context, llm_request):
|
||||
print('@before_model_callback')
|
||||
return None
|
||||
|
||||
|
||||
async def after_model_callback(callback_context, llm_response):
|
||||
print('@after_model_callback')
|
||||
return None
|
||||
|
||||
|
||||
def after_agent_cb1(callback_context):
|
||||
print('@after_agent_cb1')
|
||||
|
||||
|
||||
def after_agent_cb2(callback_context):
|
||||
print('@after_agent_cb2')
|
||||
return types.Content(
|
||||
parts=[
|
||||
types.Part(
|
||||
text='(stopped) after_agent_cb2',
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def after_agent_cb3(callback_context):
|
||||
print('@after_agent_cb3')
|
||||
|
||||
|
||||
def before_agent_cb1(callback_context):
|
||||
print('@before_agent_cb1')
|
||||
|
||||
|
||||
def before_agent_cb2(callback_context):
|
||||
print('@before_agent_cb2')
|
||||
|
||||
|
||||
def before_agent_cb3(callback_context):
|
||||
print('@before_agent_cb3')
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model='gemini-2.0-flash-exp',
|
||||
model='gemini-2.0-flash',
|
||||
name='data_processing_agent',
|
||||
description=(
|
||||
'hello world agent that can roll a dice of 8 sides and check prime'
|
||||
@@ -158,12 +106,4 @@ root_agent = Agent(
|
||||
),
|
||||
]
|
||||
),
|
||||
before_agent_callback=[
|
||||
before_agent_cb1,
|
||||
before_agent_cb2,
|
||||
before_agent_cb3,
|
||||
],
|
||||
after_agent_callback=[after_agent_cb1, after_agent_cb2, after_agent_cb3],
|
||||
before_model_callback=before_model_callback,
|
||||
after_model_callback=after_model_callback,
|
||||
)
|
||||
|
||||
+6
-58
@@ -14,35 +14,27 @@
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import warnings
|
||||
|
||||
import agent
|
||||
from dotenv import load_dotenv
|
||||
from google.adk import Runner
|
||||
from google.adk.agents.run_config import RunConfig
|
||||
from google.adk.artifacts import InMemoryArtifactService
|
||||
from google.adk.cli.utils import logs
|
||||
from google.adk.sessions import InMemorySessionService
|
||||
from google.adk.runners import InMemoryRunner
|
||||
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,
|
||||
runner = InMemoryRunner(
|
||||
agent=agent.root_agent,
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
app_name=app_name,
|
||||
)
|
||||
session_11 = session_service.create_session(
|
||||
session_11 = await runner.session_service.create_session(
|
||||
app_name=app_name, user_id=user_id_1
|
||||
)
|
||||
|
||||
@@ -83,11 +75,11 @@ async def main():
|
||||
print('------------------------------------')
|
||||
await run_prompt(session_11, 'Hi')
|
||||
await run_prompt(session_11, 'Roll a die with 100 sides')
|
||||
await run_prompt(session_11, 'Roll a die again.')
|
||||
await run_prompt(session_11, 'Roll a die again with 100 sides.')
|
||||
await run_prompt(session_11, 'What numbers did I got?')
|
||||
await run_prompt_bytes(session_11, 'Hi bytes')
|
||||
print(
|
||||
await artifact_service.list_artifact_keys(
|
||||
await runner.artifact_service.list_artifact_keys(
|
||||
app_name=app_name, user_id=user_id_1, session_id=session_11.id
|
||||
)
|
||||
)
|
||||
@@ -97,49 +89,5 @@ async def main():
|
||||
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=app_name, user_id=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(
|
||||
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('------------------------------------')
|
||||
run_prompt(session_11, 'Hi')
|
||||
run_prompt(session_11, 'Roll a die with 100 sides.')
|
||||
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__':
|
||||
print('--------------ASYNC--------------------')
|
||||
asyncio.run(main())
|
||||
print('--------------SYNC--------------------')
|
||||
main_sync()
|
||||
Executable → Regular
+2
-3
@@ -12,9 +12,9 @@
|
||||
# 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
|
||||
@@ -26,7 +26,6 @@ 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()
|
||||
|
||||
|
||||
@@ -41,7 +40,7 @@ async def main():
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
)
|
||||
session_11 = session_service.create_session(
|
||||
session_11 = await session_service.create_session(
|
||||
app_name=app_name, user_id=user_id_1
|
||||
)
|
||||
|
||||
Regular → Executable
+2
-3
@@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import warnings
|
||||
@@ -42,7 +41,7 @@ async def main():
|
||||
artifact_service=artifact_service,
|
||||
session_service=session_service,
|
||||
)
|
||||
session_11 = session_service.create_session(
|
||||
session_11 = await session_service.create_session(
|
||||
app_name=app_name, user_id=user_id_1
|
||||
)
|
||||
|
||||
@@ -67,7 +66,7 @@ async def main():
|
||||
session_11, 'Roll a die with 100 sides and check if it is prime'
|
||||
)
|
||||
await run_prompt(session_11, 'Roll it again.')
|
||||
await run_prompt(session_11, 'What numbers did I got?')
|
||||
await run_prompt(session_11, 'What numbers did I get?')
|
||||
end_time = time.time()
|
||||
print('------------------------------------')
|
||||
print('End time:', end_time)
|
||||
@@ -1,44 +0,0 @@
|
||||
# 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 google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
|
||||
|
||||
|
||||
async def create_agent():
|
||||
"""Gets tools from MCP Server."""
|
||||
tools, exit_stack = await MCPToolset.from_server(
|
||||
connection_params=StdioServerParameters(
|
||||
command='npx',
|
||||
args=[
|
||||
'-y', # Arguments for the command
|
||||
'@modelcontextprotocol/server-filesystem',
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
agent = LlmAgent(
|
||||
model='gemini-2.0-flash',
|
||||
name='enterprise_assistant',
|
||||
instruction='Help user accessing their file systems',
|
||||
tools=tools,
|
||||
)
|
||||
return agent, exit_stack
|
||||
|
||||
|
||||
root_agent = create_agent()
|
||||
@@ -0,0 +1,8 @@
|
||||
This agent connects to a local MCP server via sse.
|
||||
|
||||
To run this agent, start the local MCP server first by :
|
||||
|
||||
```bash
|
||||
uv run filesystem_server.py
|
||||
```
|
||||
|
||||
+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
+58
@@ -0,0 +1,58 @@
|
||||
# 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 google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import SseServerParams
|
||||
|
||||
_allowed_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
root_agent = LlmAgent(
|
||||
model='gemini-2.0-flash',
|
||||
name='enterprise_assistant',
|
||||
instruction=f"""\
|
||||
Help user accessing their file systems.
|
||||
|
||||
Allowed directory: {_allowed_path}
|
||||
""",
|
||||
tools=[
|
||||
MCPToolset(
|
||||
connection_params=SseServerParams(
|
||||
url='http://localhost:3000/sse',
|
||||
headers={'Accept': 'text/event-stream'},
|
||||
),
|
||||
# don't want agent to do write operation
|
||||
# you can also do below
|
||||
# tool_filter=lambda tool, ctx=None: tool.name
|
||||
# not in [
|
||||
# 'write_file',
|
||||
# 'edit_file',
|
||||
# 'create_directory',
|
||||
# 'move_file',
|
||||
# ],
|
||||
tool_filter=[
|
||||
'read_file',
|
||||
'read_multiple_files',
|
||||
'list_directory',
|
||||
'directory_tree',
|
||||
'search_files',
|
||||
'get_file_info',
|
||||
'list_allowed_directories',
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,80 @@
|
||||
# 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 os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# Create an MCP server with a name
|
||||
mcp = FastMCP("Filesystem Server", host="localhost", port=3000)
|
||||
|
||||
|
||||
# Add a tool to read file contents
|
||||
@mcp.tool(description="Read contents of a file")
|
||||
def read_file(filepath: str) -> str:
|
||||
"""Read and return the contents of a file."""
|
||||
with open(filepath, "r") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
# Add a tool to list directory contents
|
||||
@mcp.tool(description="List contents of a directory")
|
||||
def list_directory(dirpath: str) -> list:
|
||||
"""List all files and directories in the given directory."""
|
||||
return os.listdir(dirpath)
|
||||
|
||||
|
||||
# Add a tool to get current working directory
|
||||
@mcp.tool(description="Get current working directory")
|
||||
def get_cwd() -> str:
|
||||
"""Return the current working directory."""
|
||||
return str(Path.cwd())
|
||||
|
||||
|
||||
# Graceful shutdown handler
|
||||
async def shutdown(signal, loop):
|
||||
"""Cleanup tasks tied to the service's shutdown."""
|
||||
print(f"\nReceived exit signal {signal.name}...")
|
||||
|
||||
# Get all running tasks
|
||||
tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
|
||||
|
||||
# Cancel all tasks
|
||||
for task in tasks:
|
||||
task.cancel()
|
||||
|
||||
print(f"Cancelling {len(tasks)} outstanding tasks")
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
# Stop the loop
|
||||
loop.stop()
|
||||
print("Shutdown complete!")
|
||||
|
||||
|
||||
# Main entry point with graceful shutdown handling
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# The MCP run function ultimately uses asyncio.run() internally
|
||||
mcp.run(transport="sse")
|
||||
except KeyboardInterrupt:
|
||||
print("\nServer shutting down gracefully...")
|
||||
# The asyncio event loop has already been stopped by the KeyboardInterrupt
|
||||
print("Server has been shut down.")
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {e}")
|
||||
sys.exit(1)
|
||||
finally:
|
||||
print("Thank you for using the Filesystem MCP Server!")
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user