Google Gemini는 Gemini 개발자 API 또는 꼭짓점 AI를 통해 에이전트 프레임워크 에이전트를 백업할 수 있습니다. 에이전트 프레임워크가 에이전트 정의 및 오케스트레이션을 소유하는 동안 공급자별 클라이언트는 인증 및 Gemini 요청 옵션을 처리합니다.
Important
Google Gemini 및 꼭짓점 AI는 타사 시스템입니다. 애플리케이션 데이터를 보내기 전에 서비스 약관, 데이터 처리, 지역 경계, 모델 액세스 및 사용 비용을 검토합니다.
쌍둥이 자리 설치 IChatClient
.NET 샘플은 공식 Google GenAI 클라이언트 및 커뮤니티 Mscc.GenerativeAI.Microsoft 구현을 보여 줍니다.
dotnet add package Google.GenAI
dotnet add package Mscc.GenerativeAI.Microsoft
dotnet add package Microsoft.Agents.AI --prerelease
Configuration
GOOGLE_GENAI_API_KEY="<google-ai-studio-api-key>"
GOOGLE_GENAI_MODEL="gemini-2.5-flash"
const string JokerInstructions = "You are good at telling jokes.";
const string JokerName = "JokerAgent";
string apiKey = Environment.GetEnvironmentVariable("GOOGLE_GENAI_API_KEY") ?? throw new InvalidOperationException("Please set the GOOGLE_GENAI_API_KEY environment variable.");
string model = Environment.GetEnvironmentVariable("GOOGLE_GENAI_MODEL") ?? "gemini-2.5-flash";
// Using a Google GenAI IChatClient implementation
ChatClientAgent agentGenAI = new(
new Client(vertexAI: false, apiKey: apiKey).AsIChatClient(model),
name: JokerName,
instructions: JokerInstructions);
AgentResponse response = await agentGenAI.RunAsync("Tell me a joke about a pirate.");
Console.WriteLine($"Google GenAI client based agent response:\n{response}");
// Using a community driven Mscc.GenerativeAI.Microsoft package
ChatClientAgent agentCommunity = new(
new GeminiChatClient(apiKey: apiKey, model: model),
name: JokerName,
instructions: JokerInstructions);
response = await agentCommunity.RunAsync("Tell me a joke about a pirate.");
Console.WriteLine($"Community client based agent response:\n{response}");
하나의 구현을 IChatClient 선택하고 Gemini 개발자 API 또는 꼭짓점 AI 인증을 구성합니다.
패키지 설치
pip install agent-framework-gemini --pre
Configuration
Gemini 개발자 API를 사용합니다.
GEMINI_API_KEY="<api-key>"
GEMINI_MODEL="gemini-2.5-flash"
# GOOGLE_API_KEY and GOOGLE_MODEL are also supported.
또는 꼭짓점 AI를 구성합니다.
GOOGLE_GENAI_USE_VERTEXAI="true"
GOOGLE_CLOUD_PROJECT="<project-id>"
GOOGLE_CLOUD_LOCATION="us-central1"
GOOGLE_MODEL="gemini-2.5-flash"
GeminiChatClient 는 스트리밍, 함수 도구, 구조화된 출력, 확장된 사고 및 공급자 호스팅 도구를 지원합니다.
async def non_streaming_example() -> None:
"""Runs the agent and waits for the complete response before printing it."""
print("=== Non-streaming ===")
# 1. Create the agent with the Gemini chat client and local weather tool.
agent = Agent(
client=GeminiChatClient(),
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=[get_weather],
)
# 2. Ask the agent for a single weather lookup and print the final response.
query = "What's the weather like in Karlsruhe, Germany?"
print(f"User: {query}")
result = await agent.run(query)
print(f"Result: {result}\n")
async def streaming_example() -> None:
"""Runs the agent and prints each chunk as it is received."""
print("=== Streaming ===")
# 1. Create the same agent configuration for a streaming tool-call example.
agent = Agent(
client=GeminiChatClient(),
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=[get_weather],
)
# 2. Ask a multi-location question and stream the model output as it arrives.
query = "What's the weather like in Portland and in Paris?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run(query, stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
이 패키지에는 Google Search 접지, Google Maps 접지, 코드 실행, 파일 검색 및 MCP용 공장이 포함됩니다.
Google Search 접지
import asyncio
from agent_framework import Agent
from agent_framework.gemini import GeminiChatClient
from dotenv import load_dotenv
load_dotenv()
async def main() -> None:
"""Run the Google Search grounding example."""
print("=== Google Search grounding ===")
# 1. Create the agent with Gemini and the built-in Google Search grounding tool.
agent = Agent(
client=GeminiChatClient(),
name="SearchAgent",
instructions="You are a helpful assistant. Use Google Search to provide accurate, up-to-date answers.",
tools=[GeminiChatClient.get_web_search_tool()],
)
# 2. Ask a current-events style question and stream the grounded answer.
query = "What is the latest stable release of the .NET SDK?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run(query, stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
if __name__ == "__main__":
asyncio.run(main())
Go SDK는 쌍둥이 자리 유추를 제공합니다 geminiprovider . 공급자별 생성자를 통해 표준을 *agent.Agent 만듭니다.
Tools
| Tool | C# | Python | Go | Notes |
|---|---|---|---|---|
| 함수 도구 | ✅ | ✅ | ✅ | 표준 모델 함수 호출. |
| 도구 승인 | ✅ | ✅ | ✅ | 프레임워크 도구 루프에 의해 적용됩니다. |
| 코드 해석기 | ❌ | ✅ | ❌ |
GeminiChatClient.get_code_interpreter_tool(); |
| 파일 검색 | ❌ | ✅ | ❌ |
GeminiChatClient.get_file_search_tool(); |
| 웹 검색 | ❌ | ✅ | ❌ | 구글 검색을 통해 get_web_search_tool()접지 . |
| Google Maps 접지 | ❌ | ✅ | ❌ |
GeminiChatClient.get_maps_grounding_tool(); |
| 호스트된 MCP 도구 | ❌ | ✅ | ❌ |
GeminiChatClient.get_mcp_tool(); |
| 로컬 MCP 도구 | ✅ | ✅ | ✅ | 애플리케이션 프로세스에서 실행됩니다. |