logo
0
0
WeChat Login
localizeflow[bot]<skytin1004@users.noreply.github.com>
chore(i18n): sync translations with latest source changes (chunk 1/1, 171 changes)

Explorando Frameworks de Agentes de IA

(Clique na imagem acima para ver o vídeo desta aula)

Explore AI Agent Frameworks

AI agent frameworks são plataformas de software projetadas para simplificar a criação, implantação e gerenciamento de agentes de IA. Esses frameworks fornecem aos desenvolvedores componentes pré-construídos, abstrações e ferramentas que agilizam o desenvolvimento de sistemas de IA complexos.

Esses frameworks ajudam os desenvolvedores a se concentrarem nos aspectos únicos de suas aplicações, fornecendo abordagens padronizadas para desafios comuns no desenvolvimento de agentes de IA. Eles aumentam a escalabilidade, acessibilidade e eficiência na construção de sistemas de IA.

Introduction

This lesson will cover:

  • What are AI Agent Frameworks and what do they enable developers to achieve?
  • How can teams use these to quickly prototype, iterate, and improve their agent’s capabilities?
  • What are the differences between the frameworks and tools created by Microsoft (Serviço de Agentes de IA do Azure and the Microsoft Agent Framework)?
  • Can I integrate my existing Azure ecosystem tools directly, or do I need standalone solutions?
  • What is Azure AI Agents service and how is this helping me?

Learning goals

The goals of this lesson are to help you understand:

  • The role of AI Agent Frameworks in AI development.
  • How to leverage AI Agent Frameworks to build intelligent agents.
  • Key capabilities enabled by AI Agent Frameworks.
  • The differences between the Microsoft Agent Framework and Azure AI Agent Service.

What are AI Agent Frameworks and what do they enable developers to do?

Traditional AI Frameworks can help you integrate AI into your apps and make these apps better in the following ways:

  • Personalization: AI can analyze user behavior and preferences to provide personalized recommendations, content, and experiences. Example: Streaming services like Netflix use AI to suggest movies and shows based on viewing history, enhancing user engagement and satisfaction.
  • Automation and Efficiency: AI can automate repetitive tasks, streamline workflows, and improve operational efficiency. Example: Customer service apps use AI-powered chatbots to handle common inquiries, reducing response times and freeing up human agents for more complex issues.
  • Enhanced User Experience: AI can improve the overall user experience by providing intelligent features such as voice recognition, natural language processing, and predictive text. Example: Virtual assistants like Siri and Google Assistant use AI to understand and respond to voice commands, making it easier for users to interact with their devices.

That all sounds great right, so why do we need the AI Agent Framework?

AI Agent frameworks represent something more than just AI frameworks. They are designed to enable the creation of intelligent agents that can interact with users, other agents, and the environment to achieve specific goals. These agents can exhibit autonomous behavior, make decisions, and adapt to changing conditions. Let's look at some key capabilities enabled by AI Agent Frameworks:

  • Agent Collaboration and Coordination: Enable the creation of multiple AI agents that can work together, communicate, and coordinate to solve complex tasks.
  • Task Automation and Management: Provide mechanisms for automating multi-step workflows, task delegation, and dynamic task management among agents.
  • Contextual Understanding and Adaptation: Equip agents with the ability to understand context, adapt to changing environments, and make decisions based on real-time information.

So in summary, agents allow you to do more, to take automation to the next level, to create more intelligent systems that can adapt and learn from their environment.

How to quickly prototype, iterate, and improve the agent’s capabilities?

This is a fast-moving landscape, but there are some things that are common across most AI Agent Frameworks that can help you quickly prototype and iterate namely module components, collaborative tools, and real-time learning. Let's dive into these:

  • Use Modular Components: AI SDKs offer pre-built components such as AI and Memory connectors, function calling using natural language or code plugins, prompt templates, and more.
  • Leverage Collaborative Tools: Design agents with specific roles and tasks, enabling them to test and refine collaborative workflows.
  • Learn in Real-Time: Implement feedback loops where agents learn from interactions and adjust their behavior dynamically.

Use Modular Components

SDKs like the Microsoft Agent Framework offer pre-built components such as AI connectors, tool definitions, and agent management.

How teams can use these: Teams can quickly assemble these components to create a functional prototype without starting from scratch, allowing for rapid experimentation and iteration.

How it works in practice: You can use a pre-built parser to extract information from user input, a memory module to store and retrieve data, and a prompt generator to interact with users, all without having to build these components from scratch.

Example code. Let's look at an example of how you can use the Microsoft Agent Framework with AzureAIProjectAgentProvider to have the model respond to user input with tool calling:

# Exemplo em Python do Microsoft Agent Framework import asyncio import os from typing import Annotated from agent_framework.azure import AzureAIProjectAgentProvider from azure.identity import AzureCliCredential # Defina uma função de ferramenta de exemplo para reservar viagens def book_flight(date: str, location: str) -> str: """Book travel given location and date.""" return f"Travel was booked to {location} on {date}" async def main(): provider = AzureAIProjectAgentProvider(credential=AzureCliCredential()) agent = await provider.create_agent( name="travel_agent", instructions="Help the user book travel. Use the book_flight tool when ready.", tools=[book_flight], ) response = await agent.run("I'd like to go to New York on January 1, 2025") print(response) # Saída de exemplo: Seu voo para Nova York em 1º de janeiro de 2025 foi reservado com sucesso. Boa viagem! ✈️🗽 if __name__ == "__main__": asyncio.run(main())

What you can see from this example is how you can leverage a pre-built parser to extract key information from user input, such as the origin, destination, and date of a flight booking request. This modular approach allows you to focus on the high-level logic.

Leverage Collaborative Tools

Frameworks like the Microsoft Agent Framework facilitate the creation of multiple agents that can work together.

How teams can use these: Teams can design agents with specific roles and tasks, enabling them to test and refine collaborative workflows and improve overall system efficiency.

How it works in practice: You can create a team of agents where each agent has a specialized function, such as data retrieval, analysis, or decision-making. These agents can communicate and share information to achieve a common goal, such as answering a user query or completing a task.

Example code (Microsoft Agent Framework):

# Criando vários agentes que trabalham juntos usando o Microsoft Agent Framework import os from agent_framework.azure import AzureAIProjectAgentProvider from azure.identity import AzureCliCredential provider = AzureAIProjectAgentProvider(credential=AzureCliCredential()) # Agente de Recuperação de Dados agent_retrieve = await provider.create_agent( name="dataretrieval", instructions="Retrieve relevant data using available tools.", tools=[retrieve_tool], ) # Agente de Análise de Dados agent_analyze = await provider.create_agent( name="dataanalysis", instructions="Analyze the retrieved data and provide insights.", tools=[analyze_tool], ) # Executar agentes sequencialmente em uma tarefa retrieval_result = await agent_retrieve.run("Retrieve sales data for Q4") analysis_result = await agent_analyze.run(f"Analyze this data: {retrieval_result}") print(analysis_result)

What you see in the previous code is how you can create a task that involves multiple agents working together to analyze data. Each agent performs a specific function, and the task is executed by coordinating the agents to achieve the desired outcome. By creating dedicated agents with specialized roles, you can improve task efficiency and performance.

Learn in Real-Time

Advanced frameworks provide capabilities for real-time context understanding and adaptation.

How teams can use these: Teams can implement feedback loops where agents learn from interactions and adjust their behavior dynamically, leading to continuous improvement and refinement of capabilities.

How it works in practice: Agents can analyze user feedback, environmental data, and task outcomes to update their knowledge base, adjust decision-making algorithms, and improve performance over time. This iterative learning process enables agents to adapt to changing conditions and user preferences, enhancing overall system effectiveness.

What are the differences between the Microsoft Agent Framework and Azure AI Agent Service?

There are many ways to compare these approaches, but let's look at some key differences in terms of their design, capabilities, and target use cases:

Microsoft Agent Framework (MAF)

The Microsoft Agent Framework provides a streamlined SDK for building AI agents using AzureAIProjectAgentProvider. It enables developers to create agents that leverage Azure OpenAI models with built-in tool calling, conversation management, and enterprise-grade security through Azure identity.

Use Cases: Building production-ready AI agents with tool use, multi-step workflows, and enterprise integration scenarios.

Here are some important core concepts of the Microsoft Agent Framework:

  • Agents. An agent is created via AzureAIProjectAgentProvider and configured with a name, instructions, and tools. The agent can:

    • Process user messages and generate responses using Azure OpenAI models.
    • Call tools automatically based on the conversation context.
    • Maintain conversation state across multiple interactions.

    Here is a code snippet showing how to create an agent:

    import os from agent_framework.azure import AzureAIProjectAgentProvider from azure.identity import AzureCliCredential provider = AzureAIProjectAgentProvider(credential=AzureCliCredential()) agent = await provider.create_agent( name="my_agent", instructions="You are a helpful assistant.", ) response = await agent.run("Hello, World!") print(response)
  • Tools. The framework supports defining tools as Python functions that the agent can invoke automatically. Tools are registered when creating the agent:

    def get_weather(location: str) -> str: """Get the current weather for a location.""" return f"The weather in {location} is sunny, 72\u00b0F." agent = await provider.create_agent( name="weather_agent", instructions="Help users check the weather.", tools=[get_weather], )
  • Multi-Agent Coordination. You can create multiple agents with different specializations and coordinate their work:

    planner = await provider.create_agent( name="planner", instructions="Break down complex tasks into steps.", ) executor = await provider.create_agent( name="executor", instructions="Execute the planned steps using available tools.", tools=[execute_tool], ) plan = await planner.run("Plan a trip to Paris") result = await executor.run(f"Execute this plan: {plan}")
  • Azure Identity Integration. The framework uses AzureCliCredential (or DefaultAzureCredential) for secure, keyless authentication, eliminating the need to manage API keys directly.

Azure AI Agent Service

Azure AI Agent Service is a more recent addition, introduced at Microsoft Ignite 2024. It allows for the development and deployment of AI agents with more flexible models, such as directly calling open-source LLMs like Llama 3, Mistral, and Cohere.

Azure AI Agent Service provides stronger enterprise security mechanisms and data storage methods, making it suitable for enterprise applications.

It works out-of-the-box with the Microsoft Agent Framework for building and deploying agents.

This service is currently in Public Preview and supports Python and C# for building agents.

Using the Azure AI Agent Service Python SDK, we can create an agent with a user-defined tool:

import asyncio from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient # Define funções da ferramenta def get_specials() -> str: """Provides a list of specials from the menu.""" return """ Special Soup: Clam Chowder Special Salad: Cobb Salad Special Drink: Chai Tea """ def get_item_price(menu_item: str) -> str: """Provides the price of the requested menu item.""" return "$9.99" async def main() -> None: credential = DefaultAzureCredential() project_client = AIProjectClient.from_connection_string( credential=credential, conn_str="your-connection-string", ) agent = project_client.agents.create_agent( model="gpt-4o-mini", name="Host", instructions="Answer questions about the menu.", tools=[get_specials, get_item_price], ) thread = project_client.agents.create_thread() user_inputs = [ "Hello", "What is the special soup?", "How much does that cost?", "Thank you", ] for user_input in user_inputs: print(f"# User: '{user_input}'") message = project_client.agents.create_message( thread_id=thread.id, role="user", content=user_input, ) run = project_client.agents.create_and_process_run( thread_id=thread.id, agent_id=agent.id ) messages = project_client.agents.list_messages(thread_id=thread.id) print(f"# Agent: {messages.data[0].content[0].text.value}") if __name__ == "__main__": asyncio.run(main())

Core concepts

Azure AI Agent Service has the following core concepts:

  • Agent. Azure AI Agent Service integrates with Microsoft Foundry. Within AI Foundry, an AI Agent acts as a "smart" microservice that can be used to answer questions (RAG), perform actions, or completely automate workflows. It achieves this by combining the power of generative AI models with tools that allow it to access and interact with real-world data sources. Here's an example of an agent:

    agent = project_client.agents.create_agent( model="gpt-4o-mini", name="my-agent", instructions="You are helpful agent", tools=code_interpreter.definitions, tool_resources=code_interpreter.resources, )

    In this example, an agent is created with the model gpt-4o-mini, a name my-agent, and instructions You are helpful agent. The agent is equipped with tools and resources to perform code interpretation tasks.

  • Thread and messages. The thread is another important concept. It represents a conversation or interaction between an agent and a user. Threads can be used to track the progress of a conversation, store context information, and manage the state of the interaction. Here's an example of a thread:

    thread = project_client.agents.create_thread() message = project_client.agents.create_message( thread_id=thread.id, role="user", content="Could you please create a bar chart for the operating profit using the following data and provide the file to me? Company A: $1.2 million, Company B: $2.5 million, Company C: $3.0 million, Company D: $1.8 million", ) # Ask the agent to perform work on the thread run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id) # Fetch and log all messages to see the agent's response messages = project_client.agents.list_messages(thread_id=thread.id) print(f"Messages: {messages}")

    In the previous code, a thread is created. Thereafter, a message is sent to the thread. By calling create_and_process_run, the agent is asked to perform work on the thread. Finally, the messages are fetched and logged to see the agent's response. The messages indicate the progress of the conversation between the user and the agent. It's also important to understand that the messages can be of different types such as text, image, or file, that is the agents work has resulted in for example an image or a text response for example. As a developer, you can then use this information to further process the response or present it to the user.

  • Integrates with the Microsoft Agent Framework. Azure AI Agent Service works seamlessly with the Microsoft Agent Framework, which means you can build agents using AzureAIProjectAgentProvider and deploy them through the Agent Service for production scenarios.

Use Cases: Azure AI Agent Service is designed for enterprise applications that require secure, scalable, and flexible AI agent deployment.

What's the difference between these approaches?

It does sound like there is overlap, but there are some key differences in terms of their design, capabilities, and target use cases:

  • Microsoft Agent Framework (MAF): Is a production-ready SDK for building AI agents. It provides a streamlined API for creating agents with tool calling, conversation management, and Azure identity integration.
  • Azure AI Agent Service: Is a platform and deployment service in Azure Foundry for agents. It offers built-in connectivity to services like Azure OpenAI, Azure AI Search, Bing Search and code execution.

Still not sure which one to choose?

Use Cases

Let's see if we can help you by going through some common use cases:

Q: I'm building production AI agent applications and want to get started quickly

A: The Microsoft Agent Framework is a great choice. It provides a simple, Pythonic API via AzureAIProjectAgentProvider that lets you define agents with tools and instructions in just a few lines of code.

Q: I need enterprise-grade deployment with Azure integrations like Search and code execution

A: Azure AI Agent Service is the best fit. It's a platform service that provides built-in capabilities for multiple models, Azure AI Search, Bing Search and Azure Functions. It makes it easy to build your agents in the Foundry Portal and deploy them at scale.

Q: I'm still confused, just give me one option

A: Start with the Microsoft Agent Framework to build your agents, and then use Azure AI Agent Service when you need to deploy and scale them in production. This approach lets you iterate quickly on your agent logic while having a clear path to enterprise deployment.

Let's summarize the key differences in a table:

FrameworkFocusCore ConceptsUse Cases
Microsoft Agent FrameworkStreamlined agent SDK with tool callingAgents, Tools, Azure IdentityBuilding AI agents, tool use, multi-step workflows
Azure AI Agent ServiceFlexible models, enterprise security, Code generation, Tool callingModularity, Collaboration, Process OrchestrationSecure, scalable, and flexible AI agent deployment

Can I integrate my existing Azure ecosystem tools directly, or do I need standalone solutions?

A resposta é sim: você pode integrar suas ferramentas existentes do ecossistema Azure diretamente com o Azure AI Agent Service, especialmente porque ele foi construído para funcionar perfeitamente com outros serviços do Azure. Por exemplo, você pode integrar o Bing, o Azure AI Search e o Azure Functions. Também há integração profunda com o Microsoft Foundry.

O Microsoft Agent Framework também se integra com serviços do Azure por meio de AzureAIProjectAgentProvider e da identidade do Azure, permitindo que você chame serviços do Azure diretamente de suas ferramentas de agente.

Exemplos de Código

Tem mais perguntas sobre AI Agent Frameworks?

Participe do Microsoft Foundry Discord para conhecer outros aprendizes, participar de horários de atendimento e obter respostas para suas perguntas sobre AI Agents.

Referências

Lição Anterior

Introdução a Agentes de IA e Casos de Uso

Próxima Lição

Entendendo Padrões de Design Agentic


Isenção de responsabilidade: Este documento foi traduzido utilizando o serviço de tradução por IA Co-op Translator. Embora nos esforcemos para garantir a precisão, esteja ciente de que traduções automáticas podem conter erros ou imprecisões. O documento original, em seu idioma nativo, deve ser considerado a fonte autorizada. Para informações críticas, recomenda-se tradução humana profissional. Não nos responsabilizamos por quaisquer mal-entendidos ou interpretações incorretas decorrentes do uso desta tradução.