|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from google.adk import Agent |
| 16 | +from google.adk.tools import request_input |
| 17 | +from google.genai import types |
| 18 | +from pydantic import BaseModel |
| 19 | +from pydantic import Field |
| 20 | + |
| 21 | + |
| 22 | +class SupportTicket(BaseModel): |
| 23 | + """Details of the IT support ticket to be created.""" |
| 24 | + |
| 25 | + title: str = Field(description="A brief summary of the issue.") |
| 26 | + description: str = Field(description="Detailed explanation of the problem.") |
| 27 | + priority: str = Field( |
| 28 | + default="MEDIUM", |
| 29 | + description="Ticket priority: LOW, MEDIUM, HIGH, or CRITICAL.", |
| 30 | + ) |
| 31 | + category: str = Field( |
| 32 | + description=( |
| 33 | + "Issue category, e.g., billing, technical, account, or database." |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +def create_support_ticket(ticket: SupportTicket) -> dict[str, str]: |
| 39 | + """Create a support ticket in the IT ticketing system.""" |
| 40 | + return { |
| 41 | + "status": "success", |
| 42 | + "message": ( |
| 43 | + f"Successfully created ticket '{ticket.title}'" |
| 44 | + f" [Category: {ticket.category}, Priority: {ticket.priority}]." |
| 45 | + ), |
| 46 | + "ticket_id": "INC-98471", |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | +root_agent = Agent( |
| 51 | + name="support_assistant_agent", |
| 52 | + instruction=""" |
| 53 | + You are a helpful IT support assistant responsible for creating support tickets. |
| 54 | + When the user requests to create or file a ticket: |
| 55 | + 1. Identify which ticket details (title, description, priority, category) are already provided in the conversation. |
| 56 | + 2. If any mandatory details are missing, call the `request_input` tool. |
| 57 | + 3. When calling `request_input`, you must construct a dynamic JSON `response_schema` (type: "object") that ONLY requests the missing details, and specify a helpful message explaining what is needed. |
| 58 | + 4. Once all details are gathered, call `create_support_ticket` with the complete SupportTicket details. |
| 59 | + """, |
| 60 | + tools=[create_support_ticket, request_input], |
| 61 | + generate_content_config=types.GenerateContentConfig(temperature=0.1), |
| 62 | +) |
0 commit comments