chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
# Copyright 2026 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
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
# Copyright 2026 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 logging
|
||||
import os
|
||||
|
||||
from google.adk.tools.openapi_tool.auth.auth_helpers import openid_url_to_scheme_credential
|
||||
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset
|
||||
|
||||
credential_dict = {
|
||||
"client_id": os.environ.get("OAUTH_CLIENT_ID"),
|
||||
"client_secret": os.environ.get("OAUTH_CLIENT_SECRET"),
|
||||
}
|
||||
auth_scheme, auth_credential = openid_url_to_scheme_credential(
|
||||
openid_url="http://localhost:5000/.well-known/openid-configuration",
|
||||
credential_dict=credential_dict,
|
||||
scopes=[],
|
||||
)
|
||||
|
||||
|
||||
# Open API spec
|
||||
file_path = "./agent_openapi_tools/openapi.yaml"
|
||||
file_content = None
|
||||
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
file_content = file.read()
|
||||
except FileNotFoundError:
|
||||
# so that the execution does not continue when the file is not found.
|
||||
raise FileNotFoundError(f"Error: The API Spec '{file_path}' was not found.")
|
||||
|
||||
|
||||
# Example with a JSON string
|
||||
openapi_spec_yaml = file_content # Your OpenAPI YAML string
|
||||
openapi_toolset = OpenAPIToolset(
|
||||
spec_str=openapi_spec_yaml,
|
||||
spec_str_type="yaml",
|
||||
auth_scheme=auth_scheme,
|
||||
auth_credential=auth_credential,
|
||||
)
|
||||
|
||||
from google.adk.agents import LlmAgent
|
||||
|
||||
root_agent = LlmAgent(
|
||||
name="hotel_agent",
|
||||
instruction=(
|
||||
"Help user find and book hotels, fetch their bookings using the tools"
|
||||
" provided."
|
||||
),
|
||||
description="Hotel Booking Agent",
|
||||
model=os.environ.get("GOOGLE_MODEL"),
|
||||
tools=[openapi_toolset], # Pass the toolset
|
||||
# ... other agent config ...
|
||||
)
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
# Copyright 2026 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.
|
||||
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Hotel Booker API
|
||||
description: A simple API for managing hotel bookings, with a custom client credentials authentication flow.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://127.0.0.1:8081
|
||||
paths:
|
||||
/hotels:
|
||||
get:
|
||||
summary: Get available hotels
|
||||
description: Retrieves a list of available hotels, optionally filtered by location.
|
||||
security:
|
||||
- BearerAuth: []
|
||||
parameters:
|
||||
- in: query
|
||||
name: location
|
||||
schema:
|
||||
type: string
|
||||
description: The city to filter hotels by (e.g., 'New York').
|
||||
responses:
|
||||
'200':
|
||||
description: Successfully retrieved hotels.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: boolean
|
||||
example: false
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Hotel'
|
||||
message:
|
||||
type: string
|
||||
example: "Successfully retrieved hotels."
|
||||
'401':
|
||||
description: Unauthorized. Invalid or expired token.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
/book:
|
||||
post:
|
||||
summary: Book a room
|
||||
description: Books a room in a specified hotel.
|
||||
security:
|
||||
- BearerAuth: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BookingRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: Booking successful.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: boolean
|
||||
example: false
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
booking_id:
|
||||
type: string
|
||||
example: "HB-1"
|
||||
message:
|
||||
type: string
|
||||
example: "Booking successful!"
|
||||
'400':
|
||||
description: Bad request. Missing information or invalid booking details.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'401':
|
||||
description: Unauthorized. Invalid or expired token.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
/booking_details:
|
||||
get:
|
||||
summary: Get booking details
|
||||
description: Retrieves details for a specific booking by ID or guest name.
|
||||
security:
|
||||
- BearerAuth: []
|
||||
parameters:
|
||||
- in: query
|
||||
name: booking_id
|
||||
schema:
|
||||
type: string
|
||||
description: The custom booking ID (e.g., 'HB-1').
|
||||
- in: query
|
||||
name: guest_name
|
||||
schema:
|
||||
type: string
|
||||
description: The name of the guest to search for (partial and case-insensitive).
|
||||
responses:
|
||||
'200':
|
||||
description: Booking details retrieved successfully.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: boolean
|
||||
example: false
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
custom_booking_id:
|
||||
type: string
|
||||
example: "HB-1"
|
||||
hotel_name:
|
||||
type: string
|
||||
example: "Grand Hyatt"
|
||||
hotel_location:
|
||||
type: string
|
||||
example: "New York"
|
||||
guest_name:
|
||||
type: string
|
||||
example: "John Doe"
|
||||
check_in_date:
|
||||
type: string
|
||||
example: "2025-10-01"
|
||||
check_out_date:
|
||||
type: string
|
||||
example: "2025-10-05"
|
||||
num_rooms:
|
||||
type: integer
|
||||
example: 1
|
||||
total_price:
|
||||
type: number
|
||||
format: float
|
||||
example: 1000.0
|
||||
message:
|
||||
type: string
|
||||
example: "Booking details retrieved successfully."
|
||||
'400':
|
||||
description: Bad request. Missing parameters.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'401':
|
||||
description: Unauthorized. Invalid or expired token.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'404':
|
||||
description: Booking not found.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
components:
|
||||
securitySchemes:
|
||||
BearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: CustomAuthToken
|
||||
schemas:
|
||||
ErrorResponse:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: boolean
|
||||
example: true
|
||||
data:
|
||||
type: object
|
||||
nullable: true
|
||||
message:
|
||||
type: string
|
||||
example: "Invalid access token."
|
||||
Hotel:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
example: 1
|
||||
name:
|
||||
type: string
|
||||
example: "Grand Hyatt"
|
||||
location:
|
||||
type: string
|
||||
example: "New York"
|
||||
available_rooms:
|
||||
type: integer
|
||||
example: 10
|
||||
price_per_night:
|
||||
type: number
|
||||
format: float
|
||||
example: 250.0
|
||||
BookingRequest:
|
||||
type: object
|
||||
properties:
|
||||
hotel_id:
|
||||
type: integer
|
||||
example: 1
|
||||
guest_name:
|
||||
type: string
|
||||
example: "John Doe"
|
||||
check_in_date:
|
||||
type: string
|
||||
format: date
|
||||
example: "2025-10-01"
|
||||
check_out_date:
|
||||
type: string
|
||||
format: date
|
||||
example: "2025-10-05"
|
||||
num_rooms:
|
||||
type: integer
|
||||
example: 1
|
||||
required:
|
||||
- hotel_id
|
||||
- guest_name
|
||||
- check_in_date
|
||||
- check_out_date
|
||||
- num_rooms
|
||||
Reference in New Issue
Block a user