Web Search를 사용하면 에이전트가 웹에서 up-to날짜 정보를 검색할 수 있습니다. 이 도구를 사용하면 에이전트가 현재 이벤트에 대한 질문에 답변하고, 설명서를 찾고, 학습 데이터 이외의 정보에 액세스할 수 있습니다.
비고
웹 검색 가용성은 기본 에이전트 공급자에 따라 달라집니다. 공급자별 지원은 공급자 개요를 참조하세요.
다음 예제에서는 웹 검색 도구를 사용하여 에이전트를 만드는 방법을 보여줍니다.
using System;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
// Requires: dotnet add package Microsoft.Agents.AI.Foundry --prerelease
var endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4-mini";
// Create an agent with hosted web search.
AIAgent agent = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
.AsAIAgent(
model: deploymentName,
instructions: "You are a helpful assistant that can search the web for current information.",
tools: [new HostedWebSearchTool()]);
Console.WriteLine(await agent.RunAsync("What is the current weather in Seattle?"));
경고
DefaultAzureCredential 은 개발에 편리하지만 프로덕션 환경에서 신중하게 고려해야 합니다. 프로덕션 환경에서는 특정 자격 증명(예: ManagedIdentityCredential)을 사용하여 대기 시간 문제, 의도하지 않은 자격 증명 검색 및 대체 메커니즘의 잠재적인 보안 위험을 방지하는 것이 좋습니다.
다음 예제에서는 웹 검색 도구를 사용하여 에이전트를 만드는 방법을 보여줍니다.
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
"""
OpenAI Responses Client with Web Search Example
This sample demonstrates using get_web_search_tool() with OpenAI Responses Client
for direct real-time information retrieval and current data access.
"""
async def main() -> None:
client = OpenAIChatClient()
# Create web search tool with location context
web_search_tool = client.get_web_search_tool(
user_location={"city": "Seattle", "country": "US"},
)
agent = Agent(
client=client,
instructions="You are a helpful assistant that can search the web for current information.",
tools=[web_search_tool],
)
message = "What is the current weather? Do not ask for my current location."
stream = False
print(f"User: {message}")
if stream:
print("Assistant: ", end="")
async for chunk in agent.run(message, stream=True):
if chunk.text:
print(chunk.text, end="")
print("")
else:
response = await agent.run(message)
print(f"Assistant: {response}")
if __name__ == "__main__":
asyncio.run(main())
웹 검색
이 형식은 hostedtool.WebSearch 지원하는 공급자를 사용할 때 서버 쪽 웹 검색을 사용하도록 설정합니다.
import "github.com/microsoft/agent-framework-go/tool/hostedtool"
webSearch := &hostedtool.WebSearch{}
a := foundryprovider.NewAgent(endpoint, token, foundryprovider.ModelDeployment(model), foundryprovider.AgentConfig{
Config: agent.Config{
Tools: []tool.Tool{webSearch},
},
})
비고
웹 검색은 호스트된 도구입니다. 검색은 로컬이 아닌 AI 서비스에 의해 수행됩니다.
Harness 에이전트에서 웹 검색 사용
일반 에이전트의 경우 앞에서 설명한 대로 에이전트의 도구에 추가 HostedWebSearchTool 합니다.
HarnessAgent 기본적으로 하나를 HostedWebSearchTool 추가하므로 도구 등록이 필요하지 않습니다.
using Microsoft.Agents.AI;
AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
ChatOptions = new()
{
Instructions = "Use web search for current information and cite the sources you used.",
},
});
선택한 공급자가 호스트된 웹 검색을 지원하지 않거나 공급자별 검색 도구를 직접 ChatOptions.Tools등록하려는 경우를 설정합니다DisableWebSearch = true. 기본값을 사용하지 않도록 설정하지 않고 고유한 웹 검색 도구를 추가하면 에이전트가 두 도구를 모두 받습니다.
웹 검색은 모델 공급자에 의해 호스팅됩니다. Harness에서 관리할 로컬 검색 클라이언트 수명 주기가 없습니다. 가용성, 지원되는 모델, 검색 매개 변수, 데이터 상주 및 청구는 공급자에 IChatClient 따라 달라집니다. 지원되지 않는 클라이언트는 요청이 전송될 때 호스트된 도구를 거부할 수 있습니다.
검색 쿼리 및 결과를 외부 신뢰 경계를 넘는 데이터로 처리합니다. 쿼리에 비밀을 포함하지 않고 검색된 페이지를 간접 프롬프트 삽입을 포함할 수 있는 신뢰할 수 없는 콘텐츠로 처리합니다. 작업을 수행하기 전에 중요한 클레임 및 인용을 확인합니다.
HarnessAgent 는 패키지에서 Microsoft.Agents.AI.Harness 사용할 수 있습니다.
일반 에이전트의 경우 앞에서 설명한 대로 반환된 도구를 호출 client.get_web_search_tool(...) 하고 Agent전달합니다.
create_harness_agent클라이언트가 구현SupportsWebSearchTool할 때 기본적으로 인수가 없는 호출client.get_web_search_tool():
from agent_framework import create_harness_agent
agent = create_harness_agent(client=client)
클라이언트가 구현 SupportsWebSearchTool하지 않으면 팩터리는 경고를 기록하고 웹 검색 없이 계속합니다.
disable_web_search=True 자동 등록 및 경고를 표시하지 않습니다.
공급자별 설정을 전달하려면 기본값을 사용하지 않도록 설정하고 구성된 도구를 명시적으로 등록합니다.
agent = create_harness_agent(
client=client,
disable_web_search=True,
tools=[
client.get_web_search_tool(
user_location={"city": "Seattle", "country": "US"},
search_context_size="medium",
)
],
)
공급자는 호스트 검색 실행 및 수명 주기를 소유합니다. 지원되는 매개 변수, 모델, 데이터 처리 및 청구는 클라이언트 구현에 따라 달라집니다. 쿼리에 비밀을 배치하지 말고, 검색된 콘텐츠를 신뢰할 수 없는 입력으로 처리하고, 조치를 취하기 전에 중요한 클레임 및 인용을 확인합니다.
create_harness_agent 는 릴리스됩니다 agent-framework-core. 웹 검색은 구현 SupportsWebSearchTool하는 클라이언트를 통해서만 사용할 수 있습니다.
패키지된 Go Harness는 현재 사용할 수 없습니다. 앞에서 설명한 것처럼 일반 Go 에이전트에 추가 hostedtool.WebSearch 합니다.