1"use strict";(self.webpackChunkinnovation_labs=self.webpackChunkinnovation_labs||[]).push([[451],{94912:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>g,frontMatter:()=>a,metadata:()=>i,toc:()=>c});const i=JSON.parse('{"id":"examples/integrations/google/google-gemini-image","title":"Google Gemini Image Generation Example","description":"---","source":"@site/docs/examples/integrations/google/google-gemini-image.md","sourceDirName":"examples/integrations/google","slug":"/examples/integrations/google/google-gemini-image","permalink":"/resources/docs/next/examples/integrations/google/google-gemini-image","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"google-gemini-image","title":"Google Gemini Image Generation Example"},"sidebar":"tutorialSidebar","previous":{"title":"Google Gemini Pro Example","permalink":"/resources/docs/next/examples/integrations/google/google-gemini-pro"},"next":{"title":"Stripe Payment Agent","permalink":"/resources/docs/next/examples/integrations/stripe-integration"}}');var s=t(74848),r=t(28453);const a={id:"google-gemini-image",title:"Google Gemini Image Generation Example"},o="Google Gemini Image Generation Agent Example",l={},c=[{value:"Prerequisites",id:"prerequisites",level:2},{value:"Project Setup",id:"project-setup",level:2},{value:"1. Create Project Directory",id:"1-create-project-directory",level:3},{value:"2. Create Required Files",id:"2-create-required-files",level:3},{value:"Implementation",id:"implementation",level:2},{value:"Complete Agent Implementation",id:"complete-agent-implementation",level:3},{value:"Understanding ResourceContent",id:"understanding-resourcecontent",level:3},{value:"TextContent (Used for Text Messages)",id:"textcontent-used-for-text-messages",level:4},{value:"ResourceContent (Used for Images & Files)",id:"resourcecontent-used-for-images--files",level:4},{value:"ExternalStorage for Images",id:"externalstorage-for-images",level:3},{value:"Configuration Files",id:"configuration-files",level:2},{value:"Requirements File",id:"requirements-file",level:3},{value:"Environment Variables",id:"environment-variables",level:3},{value:"Getting Your API Keys",id:"getting-your-api-keys",level:2},{value:"1. Google AI API Key",id:"1-google-ai-api-key",level:3},{value:"2. Agentverse API Key",id:"2-agentverse-api-key",level:3},{value:"Installation & Running",id:"installation--running",level:2},{value:"1. Install Dependencies",id:"1-install-dependencies",level:3},{value:"2. Configure Environment",id:"2-configure-environment",level:3},{value:"3. Run the Agent",id:"3-run-the-agent",level:3},{value:"4. Register Your Agent on Agentverse",id:"4-register-your-agent-on-agentverse",level:3},{value:"Adding a README to your Agent",id:"adding-a-readme-to-your-agent",level:2},{value:"Testing Your Agent",id:"testing-your-agent",level:2},{value:"1. Test via Agentverse Chat Interface",id:"1-test-via-agentverse-chat-interface",level:3},{value:"2. Query from ASI LLM",id:"2-query-from-asi-llm",level:3},{value:"Add Conversation History",id:"add-conversation-history",level:3},{value:"Additional Resources",id:"additional-resources",level:2},{value:"Complete Code Repository",id:"complete-code-repository",level:2}];function d(e){const n={a:"a",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",hr:"hr",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"google-gemini-image-generation-agent-example",children:"Google Gemini Image Generation Agent Example"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsxs)(n.p,{children:["This guide demonstrates how to create a ",(0,s.jsx)(n.strong,{children:"mailbox agent"})," that integrates with Google's Gemini 2.5 Flash Image model using the chat protocol. We'll build an agent that can generate images from text prompts and communicate with ASI",":One"," LLM and other agents through natural language, leveraging Gemini's powerful image generation capabilities."]}),"\n",(0,s.jsx)(n.h2,{id:"prerequisites",children:"Prerequisites"}),"\n",(0,s.jsx)(n.p,{children:"Before you begin, ensure you have:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Python 3.10 or higher installed"}),"\n",(0,s.jsxs)(n.li,{children:["A ",(0,s.jsx)(n.a,{href:"https://aistudio.google.com/apikey",children:"Google AI API key"})," for accessing Gemini models"]}),"\n",(0,s.jsxs)(n.li,{children:["An ",(0,s.jsx)(n.a,{href:"https://agentverse.ai/profile/api-keys",children:"Agentverse API key"})," for external storage"]}),"\n",(0,s.jsxs)(n.li,{children:["Understanding of the ",(0,s.jsx)(n.a,{href:"/docs/agent-communication/agent-chat-protocol",children:"Chat Protocol"})," concepts"]}),"\n",(0,s.jsxs)(n.li,{children:["Basic familiarity with ",(0,s.jsx)(n.a,{href:"/docs/agent-creation/uagent-creation#mailbox-agents",children:"Mailbox Agents"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"project-setup",children:"Project Setup"}),"\n",(0,s.jsx)(n.h3,{id:"1-create-project-directory",children:"1. Create Project Directory"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"mkdir gemini-image-agent\ncd gemini-image-agent\n"})}),"\n",(0,s.jsx)(n.h3,{id:"2-create-required-files",children:"2. Create Required Files"}),"\n",(0,s.jsx)(n.p,{children:"You'll need three files:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"agent.py"})," - Main agent implementation"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:".env"})," - Environment variables and API keys"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"requirements.txt"})," - Python dependencies"]}
1),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"implementation",children:"Implementation"}),"\n",(0,s.jsx)(n.h3,{id:"complete-agent-implementation",children:"Complete Agent Implementation"}),"\n",(0,s.jsxs)(n.p,{children:["Create ",(0,s.jsx)(n.code,{children:"agent.py"})," with the following code:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-python",metastring:"title='agent.py'",children:'from __future__ import annotations\n\nfrom uuid import uuid4\nfrom datetime import datetime, timezone\nfrom typing import Any\nimport os\n\nfrom uagents import Agent, Context, Protocol\nfrom uagents_core.contrib.protocols.chat import (\n ChatAcknowledgement,\n ChatMessage,\n EndSessionContent,\n StartSessionContent,\n TextContent,\n MetadataContent,\n Resource,\n ResourceContent,\n chat_protocol_spec,\n)\nfrom io import BytesIO\n\ntry:\n from google import genai\nexcept Exception as e:\n raise RuntimeError("google-genai is required. Please install \'google-genai\'.") from e\n\nfrom uagents_core.storage import ExternalStorage\n\n\ndef create_text_chat(text: str, end_session: bool = False) -> ChatMessage:\n """Helper to create text-based chat messages"""\n content: list[Any] = [TextContent(type="text", text=text)]\n if end_session:\n content.append(EndSessionContent(type="end-session"))\n return ChatMessage(timestamp=datetime.now(timezone.utc), msg_id=uuid4(), content=content)\n\n\n# Agent configuration from environment\nAGENT_NAME = "gemini_image_agent"\nAGENT_PORT = int(os.getenv("GEMINI_AGENT_PORT", "8042"))\nAGENT_SEED = "gemini image generation agent"\n\n\nchat_proto = Protocol(spec=chat_protocol_spec)\n\n# Agentverse ExternalStorage config\nAGENTVERSE_URL = os.getenv("AGENTVERSE_URL", "https://agentverse.ai")\nSTORAGE_URL = f"{AGENTVERSE_URL}/v1/storage"\n\n\ndef _get_gemini_client() -> "genai.Client":\n """Initialize Gemini client with API key from environment"""\n api_key = os.getenv("GOOGLE_API_KEY")\n if api_key:\n return genai.Client(api_key=api_key)\n return genai.Client()\n\n\ndef generate_image(prompt: str) -> tuple[bytes, str | None]:\n """Generate image using Gemini 2.5 Flash Image model"""\n client = _get_gemini_client()\n resp = client.models.generate_content(\n model="gemini-2.5-flash-image",\n contents=[prompt],\n )\n # Extract image data from response\n for cand in getattr(resp, "candidates", []) or []:\n content = getattr(cand, "content", None)\n if not content:\n continue\n for part in getattr(content, "parts", []) or []:\n inline = getattr(part, "inline_data", None)\n if inline is not None and getattr(inline, "data", None):\n data = inline.data\n mime_type = getattr(inline, "mime_type", None)\n return data, mime_type\n raise RuntimeError("No inline image returned by Gemini.")\n\n\ndef _convert_image_if_needed(image_bytes: bytes, mime_type: str | None) -> tuple[bytes, str]:\n """\n Convert non-PNG/JPEG images (e.g., WEBP) to PNG for broad compatibility.\n Keeps PNG/JPEG as-is. Returns (bytes, mime_type).\n """\n mt = (mime_type or "image/png").lower().split(";")[0]\n if mt in ("image/png", "image/jpeg", "image/jpg"):\n # Normalize jpg to jpeg\n return image_bytes, ("image/jpeg" if mt == "image/jpg" else mt)\n try:\n from PIL import Image\n with BytesIO(image_bytes) as bio:\n img = Image.open(bio)\n # Use PNG to preserve transparency if present\n out = BytesIO()\n img.save(out, format="PNG")\n return out.getvalue(), "image/png"\n except Exception:\n # Fallback to original\n return image_bytes, mt\n\n\n@chat_proto.on_message(ChatMessage)\nasync def handle_message(ctx: Context, sender: str, msg: ChatMessage):\n """Handle incoming chat messages and generate images"""\n \n # Send acknowledgement\n await ctx.send(\n sender,\n ChatAcknowledgement(timestamp=datetime.now(timezone.utc), acknowledged_msg_id=m
1sg.msg_id),\n )\n\n for item in msg.content:\n # Handle session start - advertise capabilities\n if isinstance(item, StartSessionContent):\n await ctx.send(\n sender,\n ChatMessage(\n timestamp=datetime.now(timezone.utc),\n msg_id=uuid4(),\n content=[MetadataContent(type="metadata", metadata={"attachments": "true"})],\n ),\n )\n continue\n\n # Handle text prompts for image generation\n if isinstance(item, TextContent):\n prompt = (item.text or "").strip()\n if not prompt:\n await ctx.send(sender, create_text_chat(\n "Please provide a prompt to generate an image.", \n end_session=True\n ))\n return\n\n ctx.logger.info(f"Gemini image request from {sender}: {prompt}")\n \n # Send status update\n await ctx.send(sender, create_text_chat("Generating your image now\u2026"))\n\n # Generate image with Gemini\n try:\n image_bytes, mime_type = generate_image(prompt)\n except Exception as e:\n ctx.logger.error(f"Gemini client error: {e}")\n await ctx.send(sender, create_text_chat(\n "Sorry, the image API failed. Please try again later.", \n end_session=True\n ))\n return\n\n if not image_bytes:\n await ctx.send(sender, create_text_chat(\n "Model did not return an image.", \n end_session=True\n ))\n return\n\n # Convert to compatible format if needed\n image_bytes, content_type = _convert_image_if_needed(image_bytes, mime_type)\n content_type = (content_type or "image/png").split(";")[0].lower()\n\n # Upload to Agentverse ExternalStorage\n try:\n api_token = os.getenv("AGENTVERSE_API_KEY")\n if api_token:\n storage = ExternalStorage(api_token=api_token, storage_url=STORAGE_URL)\n else:\n storage = ExternalStorage(identity=ctx.agent.identity, storage_url=STORAGE_URL)\n\n # Create asset in storage\n asset_id = storage.create_asset(\n name=str(ctx.session),\n content=image_bytes,\n mime_type=content_type,\n )\n # Set permissions so sender can view it\n storage.set_permissions(asset_id=asset_id, agent_address=sender)\n\n # Send image as ResourceContent\n await ctx.send(\n sender,\n ChatMessage(\n timestamp=datetime.now(timezone.utc),\n msg_id=uuid4(),\n content=[\n ResourceContent(\n type="resource",\n resource_id=asset_id,\n resource=Resource(\n uri=f"agent-storage://{STORAGE_URL}/{asset_id}",\n metadata={"mime_type": content_type, "role": "generated-image"},\n ),\n ),\n EndSessionContent(type="end-session"),\n ],\n ),\n )\n return\n except Exception as e:\n ctx.logger.error(f"ExternalStorage upload failed: {e}")\n await ctx.send(sender, create_text_chat(\n "Failed to publish image. Please try again.", \n end_session=True\n ))\n return\n\n # Ignore other content types\n continue\n\n\n@chat_proto.on_message(ChatAcknowledgement)\nasync def handle_acknowledgement(ctx: Context, sender: str, msg: ChatAcknowledgement):\n """Handle message acknowledgements"""\n ctx.logger.info(f"Got a chat acknowledgement from {sender}: {msg}")\n\n\n# Include the chat protocol\nagent.include(chat_proto, publish_manifest=True)\n\n\nif __name__ == "__main__":\n agent.run()\n'})}),"\n",(0,s.jsx)(n.h3,{id:"understanding-resourcecontent",children:"Understanding ResourceContent"}),"\n",(0,s.jsxs)(n.p,{children:["Unlike the text-based Gemini Pro agent that uses ",(0,s.jsx)(n.code,{children:"TextContent"}),", this image generation agent uses ",(0,s.jsx)(n.strong,{children:(0,s.jsx)(n.code,{children:"ResourceContent"})})," to send generated images. Here's the key difference:"]}),"\n",(0,s.jsx)(n.h4,{id:"textcontent-used-for-text-messages",children:"TextContent (Used for Text Messages)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-python",children:'# Sending text responses\nTextContent(type="text", text="Hello, world!")\n'})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Use cases:"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Plain text responses"}),"\n",(0,s.jsx)(n.li,{children:"Conversation messages"}),"\n",(0,s.jsx)(n.li,{children:"Status updates"}),"\n"]}),"\n",(0,s.jsx)(n.h4,{id:"resourcecontent-used-for-images--files",children:"ResourceContent (Used for Images & Files)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-python",children:'# Sending image responses\nResourceContent(\n type="resource",\n resource_id=asset_id, # ID from ExternalStorage\n resource=Resource(\n uri=f"agent-storage://{STORAGE_URL}/{asset_id}",\n metadata={"mime_type": "image/png", "role": "generated-image"}\n )\n)\n'})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Use cases:"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Images (generated or uploaded)"}),"\n",(0,s.jsx)(n.li,{children:"Files and documents"}),"\n",(0,s.jsx)(n.li,{children:"Audio/video content"}),"\n",(0,s.jsx)(n.li,{children:"Any binary data"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Why ResourceContent for Images?"})}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Efficient"}),": Images are stored once and referenced by ID, not duplicated in every message"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Secure"}),": Permissions control who can access the resource"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Compatible"}),": Works seamlessly with ASI",":One"," and other agents"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Metadata"}),": Can include MIME type, role, and other information"]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"externalstorage-for-images",children:"Exter
1nalStorage for Images"}),"\n",(0,s.jsxs)(n.p,{children:["The agent uses Agentverse's ",(0,s.jsx)(n.strong,{children:"ExternalStorage"})," service to store and share images:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-python",children:'# Initialize storage\nstorage = ExternalStorage(api_token=api_token, storage_url=STORAGE_URL)\n\n# Upload image\nasset_id = storage.create_asset(\n name=str(ctx.session),\n content=image_bytes,\n mime_type="image/png"\n)\n\n# Set permissions (important!)\nstorage.set_permissions(asset_id=asset_id, agent_address=sender)\n'})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Key points:"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Images are uploaded to Agentverse storage"}),"\n",(0,s.jsxs)(n.li,{children:["Each image gets a unique ",(0,s.jsx)(n.code,{children:"asset_id"})]}),"\n",(0,s.jsx)(n.li,{children:"Permissions must be set so recipients can view the image"}),"\n",(0,s.jsxs)(n.li,{children:["The URI follows the format: ",(0,s.jsx)(n.code,{children:"agent-storage://{STORAGE_URL}/{asset_id}"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"configuration-files",children:"Configuration Files"}),"\n",(0,s.jsx)(n.h3,{id:"requirements-file",children:"Requirements File"}),"\n",(0,s.jsxs)(n.p,{children:["Create ",(0,s.jsx)(n.code,{children:"requirements.txt"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-text",metastring:"title='requirements.txt'",children:"uagents==0.25.5\nuagents-core==0.4.9\ngoogle-genai>=0.3.0\npython-dotenv>=1.0.1\nPillow>=10.0.0\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Package purposes:"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"uagents"})," - Core agent framework"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"uagents-core"})," - Chat protocol and storage utilities"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"google-genai"})," - Google Gemini API client"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"python-dotenv"})," - Load environment variables from .env file"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"Pillow"})," - Image format conversion (WEBP \u2192 PNG)"]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"environment-variables",children:"Environment Variables"}),"\n",(0,s.jsxs)(n.p,{children:["Create ",(0,s.jsx)(n.code,{children:".env"})," file with your API keys:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",metastring:"title='.env'",children:"# Google Gemini API Key\n# Obtain from: https://aistudio.google.com/apikey\nGOOGLE_API_KEY=your_google_api_key_here\n\n# Agentverse API Key (Required for ExternalStorage)\n# Obtain from: https://agentverse.ai/profile/api-keys\nAGENTVERSE_API_KEY=your_agentverse_api_key_here\n\n# Agentverse URL (optional, defaults to https://agentverse.ai)\nAGENTVERSE_URL=https://agentverse.ai\n\n# Agent Configuration (optional)\nGEMINI_AGENT_PORT=8042\nAGENT_NAME=gemini_image_agent\nAGENT_SEED=gemini image generation agent\n"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Important:"})," Never commit your ",(0,s.jsx)(n.code,{children:".env"})," file to version control! Add it to ",(0,s.jsx)(n.code,{children:".gitignore"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'echo ".env" >> .gitignore\n'})}),"\n",(0,s.jsx)(n.h2,{id:"getting-your-api-keys",children:"Getting Your API Keys"}),"\n",(0,s.jsx)(n.h3,{id:"1-google-ai-api-key",children:"1. Google AI API Key"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["Visit ",(0,s.jsx)(n.a,{href:"https://aistudio.google.com/apikey",children:"Google AI Studio"})]}),"\n",(0,s.jsx)(n.li,{children:"Sign in with your Google account"}),"\n",(0,s.jsxs)(n.li,{children:["Click ",(0,s.jsx)(n.strong,{children:'"Create API Key"'})]}),"\n",(0,s.jsxs)(n.li,{children:["Copy the key and add it to your ",(0,s.jsx)(n.code,{children:".env"})," file as ",(0,s.jsx)(n.code,{children:"GOOGLE_API_KEY"})]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"2-agentverse-api-key",children:"2. Agentverse API Key"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Why is this needed?"})," Mailbox agents need an API key to authenticate with Agentverse ExternalStorage for uploading and sharing images."]}),"\n",(0,s.jsxs)(n.p,{children:["To get your Agentverse API key, follow the detailed guide here: ",(0,s.jsx)(n.a,{href:"/docs/agentverse/agentverse-api-key",children:"How to get Agentverse API Key"})]}),"\n",(0,s.jsxs)(n.p,{children:["Once you have your API key, add it to your ",(0,s.jsx)(n.code,{children:".env"})," file as ",(0,s.jsx)(n.code,{children:"AGENTVERSE_API_KEY"}),"."]}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Note:"})," Hosted agents on Agentverse can use their agent identity for storage instead of an API key. Mailbox agents running locally require an explicit API key."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"installation--running",children:"Installation & Running"}),"\n",(0,s.jsx)(n.h3,{id:"1-install-dependencies",children:"1. Install Dependencies"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pip install -r requirements.txt\n"})}),"\n",(0,s.jsx)(n.h3,{id:"2-configure-environment",children:"2. Configure Environment"}),"\n",(0,s.jsxs)(n.p,{children:["Make sure your ",(0,s.jsx)(n.code,{children:".env"})," file is set up with both API keys:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"# Verify your .env file\ncat .env\n"})}),"\n",(0,s.jsx)(n.h3,{id:"3-run-the-agent",children:"3. Run the Agent"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"python agent.py\n"})}),"\n",(0,s.jsx)(n.p,{children:"You should see output like:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"xyv@Fetchs-MacBook-Pro gemini-image-agent % python3 agent.py\nINFO: [gemini_image_agent]: Starting agent with address: agent1qdzf55y0at40rezdtlhgzf4q67ym6xz0lh0c82j798q5eescxh2f6nh2vj5\nINFO: [gemini_image_agent]: Agent inspector available at https://agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8042&address=agent1qdzf55y0at40rezdtlhgzf4q67ym6xz0lh0c82j798q5eescxh2f6nh2vj5\nINFO: [gemini_image_agent]: Starting server on http://0.0.0.0:8042 (Press CTRL+C to quit)\nINFO: [gemini_image_agent]: Starting mailbox client for https://agentverse.ai\nINFO: [gemini_image_agent]: Mailbox access token acquired\nINFO: [gemini_image_agent]: Manifest published successfully: AgentChatProtocol\nINFO: [uagents.registration]: Registration on Almanac API successful\nINFO: [uagents.registration]: Almanac contract registration is up to date!\n"})}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Note:"})," The agent connects to the mailbox service automatically when ",(0,s.jsx)(n.code,{children:"mailbox=True"})," is set. This allows your local agent to receive messages from other agents and ASI",":One",". For more details on mailbox connectivity, see ",(0,s.jsx)(n.a,{href:"/docs/agent-creation/uagent-creation#mailbox-agents",children:"Mailbox Agents"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"4-register-your-agent-on-agentverse",children:"4. Register Your Agent on Agentverse"}),"\n",(0,s.jsx)(n.p,{children:"To make your agent discoverable by ASI:One:"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsx)(n.li,{children:"Keep your agent running locally"}),"\n",(0,s.jsx)(n.li,{children:"Visit the Agent inspector link shown in the output above"}),"\n",(0,s.jsx)(n.li,{children:"Connect your agent on Agentverse"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.img,{alt:"Local Agent Registration",src:t(33561).A+"",width:"3302",height:"1562"})}),"\n",(0,s.jsx)(n.h2,{id:"adding-a-readme-to-your-agent",children:"Adding a README to your Agent"}),"\n",(0,s.jsxs)(n.p,{children:["A well-written README helps make your agent easily discoverable by ASI",":One"," LLM and other agents. Once your agent is registered on Agentverse, follow these steps to add or edit your agent's README:"]}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Navigate to your agent's profile page on Agentverse"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Click the Edit button next to Readme.md"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Add a comprehensive description:"})}),"\n",(0,s.jsx)(n.p,{children:"In the Readme.md editor, add a detailed description of your agent. Include:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Purpose"}),": What your agent does (image generation from text)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Functionalities"}),": Key capabilities (image types, styles supported)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Usage guidelines"}),": How to interact with the agent (prompt best practices)"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Technical specifications"}),": Model used (Gemini 2.5 Flash Image), protocols, storage"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Examples"}),": Sample prompts and use cases"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Example sections to include:"})}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Image types: photorealistic, artistic, logos, scenes, abstract art"}),"\n",(0,s.jsx)(n.li,{children:"Best practices: Be specific, include style information, specify technical details"}),"\n",(0,s.jsx)(n.li,{children:'Example prompts: "A sunset over mountain peaks", "A minimalist tech logo", etc.'}),"\n",(0,s.jsx)(n.li,{children:"Use cases: Marketing, creative projects, social media content"}),"\n",(0,s.jsx)(n.li,{children:"Response time: 5-15 seconds typical"}),"\n",(0,s.jsx)(n.li,{children:"Limitations: One image per request, follows content policy"}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["A good description helps ASI",":One"," LLM understand when to select your agent for image generation tasks. Please refer to the ",(0,s.jsx)(n.a,{href:"/docs/agentverse/searching#importance-of-good-readme",children:"Importance of Good Readme"})," section for more details."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Make sure that your agent is enabled with Agent Chat Protocol v0.3.0"})}),"\n",(0,s.jsx)(n.p,{children:"Verify that the chat protocol is properly configured and the agent is using the latest protocol version."}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"testing-your-agent",children:"Testing Your Agent"}),"\n",(0,s.jsx)(n.h3,{id:"1-test-via-agentverse-chat-interface",children:"1. Test via Agentverse Chat Interface"}),"\n",(0,s.jsx)(n.p,{children:"Once your agent is running and registered:"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsx)(n.li,{children:"Go to your agent's page on Agentverse"}),"\n",(0,s.jsxs)(n.li,{children:["Click ",(0,s.jsx)(n.strong,{children:'"Chat with Agent"'})," button"]}),"\n",(0,s.jsxs)(n.li,{children:["Send a prompt like: ",(0,s.jsx)(n.code,{children:'"Generate an image of a sunset over mountains"'})]}),"\n",(0,s.jsx)(n.li,{children:"Wait for the image to generate and display"}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.img,{alt:"Agentverse Chat Test",src:t(42569).A+"",width:"2994",height:"1664"})}),"\n",(0,s.jsxs)(n.h3,{id:"2-query-from-asi-llm",children:["2. Query from ASI",":One"," LLM"]}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["Login to ASI",":One"," LLM:"]})}),"\n",(0,s.jsxs)(n.p,{children:["Visit ",(0,s.jsxs)(n.a,{href:"https://asi1.ai/",children:["ASI",":One"]})," and log in with your Google Account or ASI",":One"," Wallet"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Toggle the Agents switch:"})}),"\n",(0,s.jsxs)(n.p,{children:['Enable the "Agents" toggle to allow ASI',":One"," to connect with Agentverse agents"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Use your agent's handle:"})}),"\n",(0,s.jsxs)(n.p,{children:["Type ",(0,s.jsx)(n.code,{children:"@gemini-image-agent"})," (or your agent's handle) followed by your prompt:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"@gemini-image-agent Create a photorealistic image of a golden retriever puppy playing in a garden\n"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"View the generated image:"})}),"\n",(0,s.jsxs)(n.p,{children:["Your agent will process the request, generate the image with Gemini, and send it back through ASI",":One"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.img,{alt:"ASI Image Test",src:t(77397).A+"",width:"3456",height:"2234"})}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Note:"})," Make sure your agent is running locally and connected to the mailbox. If ASI",":One"," can't reach your agent, verify that:"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Your agent is running (",(0,s.jsx)(n.code,{children:"python agent.py"}),")"]}),"\n",(0,s.jsx)(n.li,{children:'It\'s registered on Agentverse under "Local Agents"'}),"\n",(0,s.jsx)(n.li,{children:"Your firewall isn't blocking the agent port"}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"add-conversation-history",children:"Add Conversation History"}),"\n",(0,s.jsx)(n.p,{children:"Store previous requests to maintain context:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-python",children:'@agent.on_event("startup")\nasync def startup(ctx: Context):\n ctx.storage.set("image_history", {})\n\n# In handle_message, track history:\nhistory = ctx.storage.get("image_history") or {}\nhistory[sender] = history.get(sender, []) + [prompt]\nctx.storage.set("image_history", history)\n'})}),"\n",(0,s.jsx)(n.h2,{id:"additional-resources",children:"Additional Resources"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs",children:"Google Gemini Documentation"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://github.com/fetchai/uAgents",children:"Fetch.ai Agent Framework"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"/docs/agent-communication/agent-chat-protocol",children:"Chat Protocol Specification"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"/docs/agent-creation/uagent-creation#mailbox-agents",children:"Mailbox Agents Guide"})}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"complete-code-repository",children:"Complete Code Repository"}),"\n",(0,s.jsx)(n.p,{children:"For the complete working example with all files, visit:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://github.com/fetchai/innovation-lab-examples/tree/main/gemini-quickstart/02-imagen-agent",children:"Gemini Image Agent Example"})}),"\n"]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Happy image generating! \ud83c\udfa8"})}),"\n",(0,s.jsxs)(n.p,{children:["If you have questions or run into issues, reach out to the Fetch.ai community on ",(0,s.jsx)(n.a,{href:"https://discord.gg/fetchai",children:"Discord"})," or ",(0,s.jsx)(n.a,{href:"https://t.me/fetch_ai",children:"Telegram"}),"."]})]})}function g(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},33561:(e,n,t)=>{t.d(n,{A:()=>i});const i=t.p+"assets/images/gemini-image-local-agent-register-e051451f696f2287727708a1dd6c610c.png"},42569:(e,n,t)=>{t.d(n,{A:()=>i});const i=t.p+"assets/images/gemini-image-test-agentverse-853831f1f463aba32ed12e16851b9450.png"},77397:(e,n,t)=>{t.d(n,{A:()=>i});const i=t.p+"assets/images/gemini-image-test-asi-one-a87b0c6c053243eec532d79cbf5b4035.png"},28453:(e,n,t)=>{t.d(n,{R:()=>a,x:()=>o});var i=
1t(96540);const s={},r=i.createContext(s);function a(e){const n=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),i.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.