다음을 통해 공유


어떤 IChatClient을/를 기반으로 한 에이전트

Microsoft Agent Framework는 Microsoft.Extensions.AI.IChatClient 구현을 제공하는 모든 유추 서비스에 대해 에이전트를 생성할 수 있도록 지원합니다. 즉, 로컬로 실행할 수 있는 오픈 소스 모델을 포함하여 에이전트를 만드는 데 사용할 수 있는 매우 광범위한 서비스가 있습니다.

이 문서에서는 Ollama를 예로 사용합니다.

시작하기

필요한 NuGet 패키지를 프로젝트에 추가합니다.

dotnet add package Microsoft.Agents.AI --prerelease

또한 사용하려는 특정 IChatClient 구현에 대한 패키지를 추가해야 합니다. 이 예제에서는 OllamaSharp를 사용합니다.

dotnet add package OllamaSharp

ChatClientAgent 만들기

인터페이스를 기반으로 에이전트를 IChatClient 만들려면 클래스를 ChatClientAgent 사용할 수 있습니다. 클래스는 ChatClientAgent 생성자 매개 변수로 사용합니다 IChatClient .

먼저 Ollama 서비스에 액세스하기 위한 OllamaApiClient를 만듭니다.

using System;
using Microsoft.Agents.AI;
using OllamaSharp;

using OllamaApiClient chatClient = new(new Uri("http://localhost:11434"), "phi3");

OllamaApiClientIChatClient 인터페이스를 구현하므로 이를 사용하여 ChatClientAgent를 만들 수 있습니다.

AIAgent agent = new ChatClientAgent(
    chatClient,
    instructions: "You are good at telling jokes.",
    name: "Joker");

// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));

중요합니다

에이전트를 최대한 활용하려면 대화형 작업에 적합하고 함수 호출을 지원하는 서비스 및 모델을 선택해야 합니다.

에이전트 사용

에이전트는 표준 AIAgent 이며 모든 표준 에이전트 작업을 지원합니다.

에이전트를 실행하고 상호 작용하는 방법에 대한 자세한 내용은 에이전트 시작 자습서 를 참조하세요.

Microsoft Agent Framework는 다음과 호환되는 채팅 클라이언트 구현을 제공하는 모든 유추 서비스에 대한 에이전트 만들기를 ChatClientProtocol지원합니다. 즉, 로컬로 실행할 수 있는 오픈 소스 모델을 포함하여 에이전트를 만드는 데 사용할 수 있는 매우 광범위한 서비스가 있습니다.

시작하기

필요한 Python 패키지를 프로젝트에 추가합니다.

pip install agent-framework --pre

사용하려는 특정 채팅 클라이언트 구현에 대한 패키지를 추가해야 할 수도 있습니다.

# For Azure AI
pip install agent-framework-azure-ai --pre

# For custom implementations
# Install any required dependencies for your custom client

기본 제공 채팅 클라이언트

프레임워크는 다음과 같은 몇 가지 기본 제공 채팅 클라이언트 구현을 제공합니다.

OpenAI 채팅 클라이언트

from agent_framework import ChatAgent
from agent_framework.openai import OpenAIChatClient

# Create agent using OpenAI
agent = ChatAgent(
    chat_client=OpenAIChatClient(model_id="gpt-4o"),
    instructions="You are a helpful assistant.",
    name="OpenAI Assistant"
)

Azure OpenAI 채팅 클라이언트

from agent_framework import ChatAgent
from agent_framework.azure import AzureOpenAIChatClient

# Create agent using Azure OpenAI
agent = ChatAgent(
    chat_client=AzureOpenAIChatClient(
        model_id="gpt-4o",
        endpoint="https://your-resource.openai.azure.com/",
        api_key="your-api-key"
    ),
    instructions="You are a helpful assistant.",
    name="Azure OpenAI Assistant"
)

Azure AI 에이전트 클라이언트

from agent_framework import ChatAgent
from agent_framework.azure import AzureAIAgentClient
from azure.identity.aio import AzureCliCredential

# Create agent using Azure AI
async with AzureCliCredential() as credential:
    agent = ChatAgent(
        chat_client=AzureAIAgentClient(async_credential=credential),
        instructions="You are a helpful assistant.",
        name="Azure AI Assistant"
    )

중요합니다

에이전트를 최대한 활용하려면 대화형 작업에 적합하고 도구를 사용하려는 경우 함수 호출을 지원하는 서비스 및 모델을 선택해야 합니다.

에이전트 사용

에이전트는 모든 표준 에이전트 작업을 지원합니다.

에이전트를 실행하고 상호 작용하는 방법에 대한 자세한 내용은 에이전트 시작 자습서 를 참조하세요.

다음 단계