Generative AI

Creating Ai agents Agents Augents and Google Gemini: Python Modular Pythar Python Guide

In this lesson, we show how we can use it UAGENTS The framework for building ai-free Ai Planner, which is conducted by an event above Gemini API of Gemini. We will start using the nest_asyncio to enable the logs of these event-placed events, and configure your Gemini API key and configure your GENAI client. Next, we will explain our communication contracts, the question and then affect two logs: Another “Gemini Flash” and another “Customer” of MultimSisting Python and close the event of the event as long as the exchange is completed, UAGends' exchange has been searching for inter-agent messages.

!pip install -q uagents google-genai

We include Ugents framework and the Chynai Client library, providing the tool required to create and use your agencies conducted by AI. Q flag runs silent installation, keeping your publication issue clean. Look Brochure here

import os, time, multiprocessing, asyncio
import nest_asyncio  
from google import genai
from pydantic import BaseModel, Field
from uagents import Agent, Context


nest_asyncio.apply()

We have established our Python National Enspower, System services (OS, Time, MultimCissing, Hidden_Syndo.Aspily ( Look Brochure here

os.environ["GOOGLE_API_KEY"] = "Use Your Own API Key Here"


client = genai.Client()

We here set our key to the world's Gemini API key. Make sure you have replaced your original key, and starts the Genai Client, which will handle all the following applications in Gemino's models. This step guarantees our agency to confirm access to produce API content.

class Question(BaseModel):
    question: str = Field(...)


class Answer(BaseModel):
    answer: str = Field(...)

These pydantic species describe formal message formats will exchange agencies. Question model carries one queue field of questions, and the model of the answers carrying one response field. Using the Pydantic, we receive automatic verification and incoming and outgoing messaging, to ensure that each agent always works with well done data.

ai_agent = Agent(
    name="gemini_agent",
    seed="agent_seed_phrase",
    port=8000,
    endpoint=["
)


@ai_agent.on_event("startup")
async def ai_startup(ctx: Context):
    ctx.logger.info(f"{ai_agent.name} listening on {ai_agent.address}")


def ask_gemini(q: str) -> str:
    resp = client.models.generate_content(
        model="gemini-2.0-flash",
        contents=f"Answer the question: {q}"
    )
    return resp.text


@ai_agent.on_message(model=Question, replies=Answer)
async def handle_question(ctx: Context, sender: str, msg: Question):
    ans = ask_gemini(msg.question)
    await ctx.send(sender, Answer(answer=ans))

In this Block, we keep the UAgements “Gemini_agent” with a different name, seed phrase (by ownership, listening, and HTTP ENDPOINT FOR THE AMESSELTS. We have enrolled the Start Attendable event party where the agent is ready, confirming the appearance of its death. Ask_Pinini wrapped the customer's phone in Genai “Flash”. At the same time, @ AI_EGENT.O_Message.on_Message Hunderler Desericizes Question Messages, Asynchronouth, and Asynchronight send a valid spelling. Look Brochure here

client_agent = Agent(
    name="client_agent",
    seed="client_seed_phrase",
    port=8001,
    endpoint=["
)


@client_agent.on_event("startup")
async def ask_on_start(ctx: Context):
    await ctx.send(ai_agent.address, Question(question="What is the capital of France?"))


@client_agent.on_message(model=Answer)
async def handle_answer(ctx: Context, sender: str, msg: Answer):
    print("📨 Answer from Gemini:", msg.answer)
    # Use a more graceful shutdown
    asyncio.create_task(shutdown_loop())


async def shutdown_loop():
    await asyncio.sleep(1)  # Give time for cleanup
    loop = asyncio.get_event_loop()
    loop.stop()

We set up “Client_Adin” that when we first, we send a question in Gemini_agent, printing the event of an event after event delays after the event after an event delay after an event delay after event delays after an event delay after event delays after an event delay after event after the event delay after event. of an event delay after an event delay after an event delay after event delays after an event delay after an event delay after event delays after an event delay after event delays after a short delay. Look Brochure here

def run_agent(agent):
    agent.run()


if __name__ == "__main__":
    p = multiprocessing.Process(target=run_agent, args=(ai_agent,))
    p.start()
    time.sleep(2)  


    client_agent.run()


    p.join()

Finally, it describes the work of run Run_agent who calls the Jenti.run (), and use the Pythimon Multimageing to introduce Gemini_agent to its process. After giving it a puberty, the client_agent in the main process, blocking until the circuit response is completed, and finally joined the back process to ensure pure closure.

In conclusion, by this UAgents-Gikored Tutorial lesson, we now have a clear Vikerprint to build AI services associated with a well-defined event with the message programs. You have seen how UAgents make control of agent management, registration starting, lifting incoming messages, and sending formal responses, everything except the boilerplate code. From here, you can increase your UAgents setup to include the most complex discussion, multiple messaging, and a powerful agent.


Look The brochure here. All credit for this study goes to research for this project. Also, feel free to follow it Sane and don't forget to join ours 100K + ml subreddit Then sign up for Our newspaper.


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