Python 퀵스타트

Python 퀵스타트

MAF로 첫 에이전트를 만드는 건 간단해요. 설치는 pip install agent-framework 한 줄이면 되고, 실험 모듈은 agent-framework-lab을 따로 설치해요.

출처: https://github.com/microsoft/agent-framework

설치 후에는 Azure CLI로 로그인(az login)하고, Microsoft Foundry의 채팅 클라이언트를 만들어 에이전트를 구성하면 돼요. 엔드포인트와 모델 배포명은 환경 변수로 넣거나 생성자에 직접 넘길 수 있어요.

# pip install agent-framework
# Use `az login` to authenticate with Azure CLI
import os
import asyncio
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential


async def main():
    # Initialize a chat agent with Microsoft Foundry
    agent = Agent(
      client=FoundryChatClient(
          credential=AzureCliCredential(),
          # project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
          # model=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
      ),
      name="HaikuAgent",
      instructions="You are an upbeat assistant that writes beautifully.",
    )

    print(await agent.run("Write a haiku about Microsoft Agent Framework."))

if __name__ == "__main__":
    asyncio.run(main())

Agentname은 에이전트를 구분하는 이름이고, instructions는 LLM에 깔리는 시스템 지시예요. .NET에서는 AIProjectClient를 만들어 .AsAIAgent(model: deploymentName, instructions: ..., name: ...)로 같은 일을 할 수 있어요.

참고로 DefaultAzureCredential은 개발에 편리하지만, 운영에서는 레이턴시와 보안을 고려해 특정 자격증명(ManagedIdentityCredential)을 쓰는 게 좋아요.

더 알아보기