Generative AI

Coding guide to create an Agentic Audic Asychronous Tichetant Assistant using Pydantai agents, Pydantic V2, and SQLITE DATHABASE

In this lesson, we will build a helper to keep the last tickets enabled by Agentic AI using the Pydacantia library. We will define our Data laws with Pydantic V2 models, store tickets in the Memory database of Memory, and generate separate identifier in Python's UUID Module. After the scenes, two agents, some of the testing status, Google Gla Google-glo (with Google-Gla (Gla-Gla (Gla-Gla The result is a pure, safe work, can run immediately to Colob.

!pip install --upgrade pip
!pip install pydantic-ai

First, these two commands renew your PIP installer in the latest version, bring new features and security pieces, and enter Pydaticai. The library gives the power to explain the Agents for an Agents and the Safe Agents and the integration of the Pydantic Models and LLMS.

import os
from getpass import getpass


if "GEMINI_API_KEY" not in os.environ:
    os.environ["GEMINI_API_KEY"] = getpass("Enter your Google Gemini API key: ")

We examine whether the nature of Gemini_ap_key variable is already set. If not, we move you safely (without echo) to enter your Google Gemini Gemini key at the initiation, and save it to Os.environ for your Agentic AI calls.

!pip install nest_asyncio

We include Nest_asyncio package, which allows you to place an existing asyencio event to call async activities (or use async

import sqlite3
import uuid
from dataclasses import dataclass
from typing import Literal


from pydantic import BaseModel, Field
from pydantic_ai import Agent, RunContext

We bring our Memory's In-Memory Database Database and the UUID to produce unique device IDs, useful use and contact with the PHDACICAIDE PLACE AND CONSIDER.

conn = sqlite3.connect(":memory:")
conn.execute("""
CREATE TABLE tickets (
    ticket_id TEXT PRIMARY KEY,
    summary   TEXT NOT NULL,
    severity  TEXT NOT NULL,
    department TEXT NOT NULL,
    status    TEXT NOT NULL
)
""")
conn.commit()

We set up the SQLILE database of the Memory SQLITE and specify the table tickets in ticket_id columns, light, department, and format, and you have a ticket management store.

@dataclass
class TicketingDependencies:
    """Carries our DB connection into system prompts and tools."""
    db: sqlite3.Connection


class CreateTicketOutput(BaseModel):
    ticket_id: str = Field(..., description="Unique ticket identifier")
    summary: str   = Field(..., description="Text summary of the issue")
    severity: Literal["low","medium","high"] = Field(..., description="Urgency level")
    department: str = Field(..., description="Responsible department")
    status: Literal["open"] = Field("open", description="Initial ticket status")


class TicketStatusOutput(BaseModel):
    ticket_id: str = Field(..., description="Unique ticket identifier")
    status: Literal["open","in_progress","resolved"] = Field(..., description="Current ticket status")

Here, describing ticketleskies agree with the DACKass conforming to the SQLITE Connection for each agent call, and announces the Pydantic Cell: Credetity, Ticket ID, Ticket ID and its current status). These models forced a clear building, guaranteed for all our return agents, make sure you always find well done data.

create_agent = Agent(
    "google-gla:gemini-2.0-flash",
    deps_type=TicketingDependencies,
    output_type=CreateTicketOutput,
    system_prompt="You are a ticketing assistant. Use the `create_ticket` tool to log new issues."
)


@create_agent.tool
async def create_ticket(
    ctx: RunContext[TicketingDependencies],
    summary: str,
    severity: Literal["low","medium","high"],
    department: str
) -> CreateTicketOutput:
    """
    Logs a new ticket in the database.
    """
    tid = str(uuid.uuid4())
    ctx.deps.db.execute(
        "INSERT INTO tickets VALUES (?,?,?,?,?)",
        (tid, summary, severity, department, "open")
    )
    ctx.deps.db.commit()
    return CreateTicketOutput(
        ticket_id=tid,
        summary=summary,
        severity=severity,
        department=department,
        status="open"
    )

We create PydataI agent name 'Create_agent' that is spam on Google Gemini and is able to our SQLITE (DEX_TYPE = DECREENT_AGEOL_EGOL decorations

status_agent = Agent(
    "google-gla:gemini-2.0-flash",
    deps_type=TicketingDependencies,
    output_type=TicketStatusOutput,
    system_prompt="You are a ticketing assistant. Use the `get_ticket_status` tool to retrieve current status."
)


@status_agent.tool
async def get_ticket_status(
    ctx: RunContext[TicketingDependencies],
    ticket_id: str
) -> TicketStatusOutput:
    """
    Fetches the ticket status from the database.
    """
    cur = ctx.deps.db.execute(
        "SELECT status FROM tickets WHERE ticket_id = ?", (ticket_id,)
    )
    row = cur.fetchone()
    if not row:
        raise ValueError(f"No ticket found for ID {ticket_id!r}")
    return TicketStatusOutput(ticket_id=ticket_id, status=row[0])

We place the second pydatanti agent, the_the_agedent, and using a Google Gemini provider and synchronization of shared tickets. The Async Get_status tool looks for a given ticket_id device on SQLITE DATATUBASE and returns a certified ticket, or suggested an error if the ticket is not available.

deps = TicketingDependencies(db=conn)


create_result = await create_agent.run(
    "My printer on 3rd floor shows a paper jam error.", deps=deps
)


print("Created Ticket →")
print(create_result.output.model_dump_json(indent=2))


tid = create_result.output.ticket_id
status_result = await status_agent.run(
    f"What's the status of ticket {tid}?", deps=deps
)


print("Ticket Status →")
print(status_result.output.model_dump_json(indent=2))

Finally, we start to move your SQLITE connection to a DEPs, and ask to create a new ticket for a quick environment, printing certified ticket data such as JSON. Then it takes a restored Ticket_id, questions the situation_a current ticket situation, and printed the situation in JSONE.

In conclusion, you have seen how Agentic Ai Nydacantai worked to use the full service process, from the new edition of their live status, all controlled in pregnancy. Our Psydan V2 use of tickets are like a schema which you explain, while SQLITE provides long backend that is easy to replace any details. With these tools in the area, you can expand the assistant, including the activities of the new agent, including the Ai Like Openaai: GPT-4O, or linking the formal and reliable.


Here is the Colab Notebook. Also, don't forget to follow Sane and join ours Telegraph station including LinkedIn Grtopic. Don't forget to join ours 90k + ml subreddit.

🔥 [Register Now] Summit of the Minicon Virtual in Agentic AI: Free Registration + Certificate of Before Hour 4 Hour Court (May 21, 9 AM


Asphazzaq is a Markteach Media Inc. According to a View Business and Developer, Asifi is committed to integrating a good social intelligence. His latest attempt is launched by the launch of the chemistrylife plan for an intelligence, MarktechPost, a devastating intimate practice of a machine learning and deep learning issues that are clearly and easily understood. The platform is adhering to more than two million moon visits, indicating its popularity between the audience.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button