(I-click ang imahe sa itaas upang mapanood ang video ng araling ito)
Ang AI agent frameworks ay mga software platform na idinisenyo upang gawing mas madali ang paglikha, pag-deploy, at pamamahala ng mga AI agents. Ang mga framework na ito ay nagbibigay sa mga developer ng mga pre-built na bahagi, abstraction, at mga tool na nagpapadali sa pagbuo ng mga kumplikadong AI system.
Tinutulungan ng mga framework na ito ang mga developer na mag-focus sa natatanging aspeto ng kanilang mga aplikasyon sa pamamagitan ng pagbibigay ng mga standardized na solusyon sa mga karaniwang hamon sa pagbuo ng AI agents. Pinapahusay nito ang scalability, accessibility, at efficiency sa paggawa ng mga AI system.
Saklaw ng araling ito ang:
Ang mga layunin ng araling ito ay upang matulungan kang maunawaan:
Ang mga tradisyunal na AI Frameworks ay makakatulong sa iyo na isama ang AI sa iyong mga app at gawing mas mahusay ang mga app na ito sa mga sumusunod na paraan:
Ang AI Agent frameworks ay kumakatawan sa higit pa sa mga tradisyunal na AI frameworks. Ang mga ito ay idinisenyo upang paganahin ang paglikha ng mga intelligent agents na maaaring makipag-ugnayan sa mga user, iba pang agents, at sa kapaligiran upang makamit ang mga tiyak na layunin. Ang mga agents na ito ay maaaring magpakita ng autonomous na pag-uugali, gumawa ng mga desisyon, at umangkop sa mga nagbabagong kondisyon. Tingnan natin ang ilang pangunahing kakayahan na pinapagana ng AI Agent Frameworks:
Sa kabuuan, pinapayagan ng mga agents ang paggawa ng higit pa, ang pagdadala ng automation sa mas mataas na antas, at ang paglikha ng mas intelligent na mga sistema na maaaring umangkop at matuto mula sa kanilang kapaligiran.
Ito ay isang mabilis na umuunlad na landscape, ngunit may ilang mga bagay na karaniwan sa karamihan ng AI Agent Frameworks na makakatulong sa iyo na mabilis na mag-prototype at mag-iterate, tulad ng mga modular na bahagi, collaborative tools, at real-time learning. Tingnan natin ang mga ito:
Ang mga SDK tulad ng Microsoft Semantic Kernel at LangChain ay nag-aalok ng mga pre-built na bahagi tulad ng AI connectors, prompt templates, at memory management.
Paano magagamit ng mga team ang mga ito: Maaaring mabilis na buuin ng mga team ang mga bahaging ito upang makagawa ng functional prototype nang hindi nagsisimula mula sa simula, na nagpapahintulot sa mabilis na eksperimento at iteration.
Paano ito gumagana sa praktika: Maaari kang gumamit ng pre-built parser upang kunin ang impormasyon mula sa input ng user, isang memory module upang mag-imbak at mag-retrieve ng data, at isang prompt generator upang makipag-ugnayan sa mga user, lahat nang hindi kailangang buuin ang mga bahaging ito mula sa simula.
Halimbawa ng code. Tingnan natin ang mga halimbawa kung paano mo magagamit ang isang pre-built AI Connector gamit ang Semantic Kernel Python at .Net na gumagamit ng auto-function calling upang tumugon ang modelo sa input ng user:
# Semantic Kernel Python Example
import asyncio
from typing import Annotated
from semantic_kernel.connectors.ai import FunctionChoiceBehavior
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, AzureChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
from semantic_kernel.functions import kernel_function
from semantic_kernel.kernel import Kernel
# Define a ChatHistory object to hold the conversation's context
chat_history = ChatHistory()
chat_history.add_user_message("I'd like to go to New York on January 1, 2025")
# Define a sample plugin that contains the function to book travel
class BookTravelPlugin:
"""A Sample Book Travel Plugin"""
@kernel_function(name="book_flight", description="Book travel given location and date")
async def book_flight(
self, date: Annotated[str, "The date of travel"], location: Annotated[str, "The location to travel to"]
) -> str:
return f"Travel was booked to {location} on {date}"
# Create the Kernel
kernel = Kernel()
# Add the sample plugin to the Kernel object
kernel.add_plugin(BookTravelPlugin(), plugin_name="book_travel")
# Define the Azure OpenAI AI Connector
chat_service = AzureChatCompletion(
deployment_name="YOUR_DEPLOYMENT_NAME",
api_key="YOUR_API_KEY",
endpoint="https://<your-resource>.azure.openai.com/",
)
# Define the request settings to configure the model with auto-function calling
request_settings = AzureChatPromptExecutionSettings(function_choice_behavior=FunctionChoiceBehavior.Auto())
async def main():
# Make the request to the model for the given chat history and request settings
# The Kernel contains the sample that the model will request to invoke
response = await chat_service.get_chat_message_content(
chat_history=chat_history, settings=request_settings, kernel=kernel
)
assert response is not None
"""
Note: In the auto function calling process, the model determines it can invoke the
`BookTravelPlugin` using the `book_flight` function, supplying the necessary arguments.
For example:
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "BookTravelPlugin-book_flight",
"arguments": "{'location': 'New York', 'date': '2025-01-01'}"
}
}
]
Since the location and date arguments are required (as defined by the kernel function), if the
model lacks either, it will prompt the user to provide them. For instance:
User: Book me a flight to New York.
Model: Sure, I'd love to help you book a flight. Could you please specify the date?
User: I want to travel on January 1, 2025.
Model: Your flight to New York on January 1, 2025, has been successfully booked. Safe travels!
"""
print(f"`{response}`")
# Example AI Model Response: `Your flight to New York on January 1, 2025, has been successfully booked. Safe travels! ✈️🗽`
# Add the model's response to our chat history context
chat_history.add_assistant_message(response.content)
if __name__ == "__main__":
asyncio.run(main())
// Semantic Kernel C# example
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using System.ComponentModel;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
ChatHistory chatHistory = [];
chatHistory.AddUserMessage("I'd like to go to New York on January 1, 2025");
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddAzureOpenAIChatCompletion(
deploymentName: "NAME_OF_YOUR_DEPLOYMENT",
apiKey: "YOUR_API_KEY",
endpoint: "YOUR_AZURE_ENDPOINT"
);
kernelBuilder.Plugins.AddFromType<BookTravelPlugin>("BookTravel");
var kernel = kernelBuilder.Build();
var settings = new AzureOpenAIPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
var chatCompletion = kernel.GetRequiredService<IChatCompletionService>();
var response = await chatCompletion.GetChatMessageContentAsync(chatHistory, settings, kernel);
/*
Behind the scenes, the model recognizes the tool to call, what arguments it already has (location) and (date)
{
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "BookTravelPlugin-book_flight",
"arguments": "{'location': 'New York', 'date': '2025-01-01'}"
}
}
]
*/
Console.WriteLine(response.Content);
chatHistory.AddMessage(response!.Role, response!.Content!);
// Example AI Model Response: Your flight to New York on January 1, 2025, has been successfully booked. Safe travels! ✈️🗽
// Define a plugin that contains the function to book travel
public class BookTravelPlugin
{
[KernelFunction("book_flight")]
[Description("Book travel given location and date")]
public async Task<string> BookFlight(DateTime date, string location)
{
return await Task.FromResult( $"Travel was booked to {location} on {date}");
}
}
Makikita mo mula sa halimbawang ito kung paano mo magagamit ang isang pre-built parser upang kunin ang mahalagang impormasyon mula sa input ng user, tulad ng pinagmulan, destinasyon, at petsa ng isang flight booking request. Ang modular na approach na ito ay nagpapahintulot sa iyo na mag-focus sa high-level logic.
Ang mga framework tulad ng CrewAI, Microsoft AutoGen, at Semantic Kernel ay nagpapadali sa paglikha ng maraming agents na maaaring magtulungan.
Paano magagamit ng mga team ang mga ito: Maaaring magdisenyo ang mga team ng mga agents na may partikular na mga tungkulin at gawain, na nagpapahintulot sa kanila na subukan at pinuhin ang mga collaborative workflows at mapabuti ang kabuuang efficiency ng sistema.
Paano ito gumagana sa praktika: Maaari kang lumikha ng isang team ng agents kung saan ang bawat agent ay may espesyal na tungkulin, tulad ng data retrieval, analysis, o decision-making. Ang mga agents na ito ay maaaring makipag-usap at magbahagi ng impormasyon upang makamit ang isang karaniwang layunin, tulad ng pagsagot sa tanong ng user o pagtapos ng isang gawain.
Halimbawa ng code (AutoGen):
# creating agents, then create a round robin schedule where they can work together, in this case in order
# Data Retrieval Agent
# Data Analysis Agent
# Decision Making Agent
agent_retrieve = AssistantAgent(
name="dataretrieval",
model_client=model_client,
tools=[retrieve_tool],
system_message="Use tools to solve tasks."
)
agent_analyze = AssistantAgent(
name="dataanalysis",
model_client=model_client,
tools=[analyze_tool],
system_message="Use tools to solve tasks."
)
# conversation ends when user says "APPROVE"
termination = TextMentionTermination("APPROVE")
user_proxy = UserProxyAgent("user_proxy", input_func=input)
team = RoundRobinGroupChat([agent_retrieve, agent_analyze, user_proxy], termination_condition=termination)
stream = team.run_stream(task="Analyze data", max_turns=10)
# Use asyncio.run(...) when running in a script.
await Console(stream)
Makikita mo sa nakaraang code kung paano ka makakagawa ng isang gawain na kinabibilangan ng maraming agents na nagtutulungan upang suriin ang data. Ang bawat agent ay gumaganap ng partikular na tungkulin, at ang gawain ay isinasagawa sa pamamagitan ng pag-coordinate ng mga agents upang makamit ang nais na resulta. Sa pamamagitan ng paglikha ng mga dedikadong agents na may espesyal na tungkulin, maaari mong mapabuti ang efficiency at performance ng gawain.
Ang mga advanced na framework ay nagbibigay ng kakayahan para sa real-time na pag-unawa sa konteksto at pag-aangkop.
Paano magagamit ng mga team ang mga ito: Maaaring magpatupad ang mga team ng mga feedback loop kung saan natututo ang mga agents mula sa mga interaksyon at ina-adjust ang kanilang pag-uugali nang dynamic, na nagreresulta sa patuloy na pagpapabuti at refinement ng mga kakayahan.
Paano ito gumagana sa praktika: Maaaring suriin ng mga agents ang feedback ng user, data ng kapaligiran, at mga resulta ng gawain upang i-update ang kanilang knowledge base, ayusin ang mga algorithm ng decision-making, at mapabuti ang performance sa paglipas ng panahon. Ang iterative learning process na ito ay nagbibigay-daan sa mga agents na umangkop sa mga nagbabagong kondisyon at kagustuhan ng user, na nagpapahusay sa kabuuang effectiveness ng sistema.
Maraming paraan upang ihambing ang mga framework na ito, ngunit tingnan natin ang ilang pangunahing pagkakaiba sa kanilang disenyo, kakayahan, at target na mga use case:
Ang AutoGen ay isang open-source framework na binuo ng Microsoft Research’s AI Frontiers Lab. Nakatuon ito sa event-driven, distributed agentic applications, na nagpapagana ng maraming LLMs at SLMs, tools, at advanced multi-agent design patterns.
Ang AutoGen ay binuo sa paligid ng pangunahing konsepto ng agents, na mga autonomous na entity na maaaring makakita ng kanilang kapaligiran, gumawa ng mga desisyon, at kumilos upang makamit ang mga tiyak na layunin. Ang mga agents ay nakikipag-usap sa pamamagitan ng asynchronous na mga mensahe, na nagpapahintulot sa kanila na magtrabaho nang independyente at parallel, na nagpapahusay sa scalability at responsiveness ng sistema.
Ang mga agents ay batay sa actor model. Ayon sa Wikipedia, ang isang actor ay ang pangunahing building block ng concurrent computation. Bilang tugon sa isang mensahe na natanggap nito, ang isang actor ay maaaring: gumawa ng mga lokal na desisyon, lumikha ng higit pang mga actor, magpadala ng higit pang mga mensahe, at tukuyin kung paano tumugon sa susunod na mensahe na natanggap.
Mga Use Case: Pag-automate ng code generation, mga gawain sa pagsusuri ng data, at paggawa ng mga custom agents para sa mga tungkulin sa pagpaplano at pananaliksik.
Narito ang ilang mahahalagang pangunahing konsepto ng AutoGen:
Narito ang isang maikling code snippet kung saan lumikha ka ng sarili mong agent na may Chat capabilities:
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_ext.models.openai import OpenAIChatCompletionClient
class MyAgent(RoutedAgent):
def __init__(self, name: str) -> None:
super().__init__(name)
model_client = OpenAIChatCompletionClient(model="gpt-4o")
self._delegate = AssistantAgent(name, model_client=model_client)
@message_handler
async def handle_my_message_type(self, message: MyMessageType, ctx: MessageContext) -> None:
print(f"{self.id.type} received message: {message.content}")
response = await self._delegate.on_messages(
[TextMessage(content=message.content, source="user")], ctx.cancellation_token
)
print(f"{self.id.type} responded: {response.chat_message.content}")
Sa nakaraang code, ang MyAgent
ay nilikha at nagmana mula sa RoutedAgent
. Mayroon itong message handler na nagpi-print ng nilalaman ng mensahe at pagkatapos ay nagpapadala ng tugon gamit ang AssistantAgent
delegate. Lalo na tandaan kung paano namin itinalaga sa self._delegate
ang isang instance ng AssistantAgent
na isang pre-built agent na maaaring humawak ng chat completions.
Ipaalam natin sa AutoGen ang tungkol sa ganitong uri ng agent at simulan ang programa:
# main.py
runtime = SingleThreadedAgentRuntime()
await MyAgent.register(runtime, "my_agent", lambda: MyAgent())
runtime.start() # Start processing messages in the background.
await runtime.send_message(MyMessageType("Hello, World!"), AgentId("my_agent", "default"))
Sa nakaraang code, ang mga agents ay nakarehistro sa runtime at pagkatapos ay isang mensahe ang ipinadala sa agent na nagresulta sa sumusunod na output:
# Output from the console:
my_agent received message: Hello, World!
my_assistant received message: Hello, World!
my_assistant responded: Hello! How can I assist you today?
Multi agents. Sinusuportahan ng AutoGen ang paglikha ng maraming agents na maaaring magtulungan upang makamit ang mga kumplikadong gawain. Ang mga agents ay maaaring makipag-usap, magbahagi ng impormasyon, at mag-coordinate ng kanilang mga aksyon upang mas mabilis na malutas ang mga problema. Upang lumikha ng isang multi-agent system, maaari kang magtakda ng iba’t ibang uri ng agents na may espesyal na mga tungkulin at papel, tulad ng data retrieval, analysis, decision-making, at user interaction. Tingnan natin kung paano ang ganitong paglikha upang magkaroon tayo ng ideya:
editor_description = "Editor for planning and reviewing the content."
# Example of declaring an Agent
editor_agent_type = await EditorAgent.register(
runtime,
editor_topic_type, # Using topic type as the agent type.
lambda: EditorAgent(
description=editor_description,
group_chat_topic_type=group_chat_topic_type,
model_client=OpenAIChatCompletionClient(
model="gpt-4o-2024-08-06",
# api_key="YOUR_API_KEY",
),
),
)
# remaining declarations shortened for brevity
# Group chat
group_chat_manager_type = await GroupChatManager.register(
runtime,
"group_chat_manager",
lambda: GroupChatManager(
participant_topic_types=[writer_topic_type, illustrator_topic_type, editor_topic_type, user_topic_type],
model_client=OpenAIChatCompletionClient(
model="gpt-4o-2024-08-06",
# api_key="YOUR_API_KEY",
),
participant_descriptions=[
writer_description,
illustrator_description,
editor_description,
user_description
],
),
)
Sa nakaraang code, mayroon tayong GroupChatManager
na nakarehistro sa runtime. Ang manager na ito ang responsable sa pag-coordinate ng mga interaksyon sa pagitan ng iba’t ibang uri ng agents, tulad ng mga writers, illustrators, editors, at users.
Stand-alone runtime. Ito ay isang magandang pagpipilian para sa single-process applications kung saan lahat ng agents ay ipinatupad sa parehong programming language at tumatakbo sa parehong proseso. Narito ang isang ilustrasyon kung paano ito gumagana:
Stand-alone runtime
Application stack
ang mga agents ay nakikipag-usap sa pamamagitan ng mga mensahe sa runtime, at ang runtime ang namamahala sa lifecycle ng mga agents
Distributed agent runtime, ay angkop para sa multi-process applications kung saan ang mga agents ay maaaring ipinatupad sa iba’t ibang programming languages at tumatakbo sa iba’t ibang makina. Narito ang isang ilustrasyon kung paano ito gumagana:
Ang Semantic Kernel ay isang enterprise-ready AI Orchestration SDK. Binubuo ito ng AI at memory connectors, kasama ang isang Agent Framework.
Unahin nating talakayin ang ilang pangunahing bahagi:
AI Connectors: Ito ay isang interface sa mga external AI services at data sources para magamit sa parehong Python at C#.
# Semantic Kernel Python
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
from semantic_kernel.kernel import Kernel
kernel = Kernel()
kernel.add_service(
AzureChatCompletion(
deployment_name="your-deployment-name",
api_key="your-api-key",
endpoint="your-endpoint",
)
)
// Semantic Kernel C#
using Microsoft.SemanticKernel;
// Create kernel
var builder = Kernel.CreateBuilder();
// Add a chat completion service:
builder.Services.AddAzureOpenAIChatCompletion(
"your-resource-name",
"your-endpoint",
"your-resource-key",
"deployment-model");
var kernel = builder.Build();
Narito ang isang simpleng halimbawa kung paano ka makakagawa ng kernel at magdagdag ng chat completion service. Ang Semantic Kernel ay lumilikha ng koneksyon sa isang external AI service, sa kasong ito, Azure OpenAI Chat Completion.
Plugins: Ang mga ito ay naglalaman ng mga function na maaaring gamitin ng isang application. Mayroong parehong ready-made plugins at custom na maaari mong likhain. Ang isang kaugnay na konsepto ay ang “prompt functions.” Sa halip na magbigay ng natural language cues para sa function invocation, ipinapahayag mo ang ilang mga function sa modelo. Batay sa kasalukuyang chat context, maaaring piliin ng modelo na tawagan ang isa sa mga function na ito upang makumpleto ang isang request o query. Narito ang isang halimbawa:
from semantic_kernel.connectors.ai.open_ai.services.azure_chat_completion import AzureChatCompletion
async def main():
from semantic_kernel.functions import KernelFunctionFromPrompt
from semantic_kernel.kernel import Kernel
kernel = Kernel()
kernel.add_service(AzureChatCompletion())
user_input = input("User Input:> ")
kernel_function = KernelFunctionFromPrompt(
function_name="SummarizeText",
prompt="""
Summarize the provided unstructured text in a sentence that is easy to understand.
Text to summarize:
""",
)
response = await kernel_function.invoke(kernel=kernel, user_input=user_input)
print(f"Model Response: {response}")
"""
Sample Console Output:
User Input:> I like dogs
Model Response: The text expresses a preference for dogs.
"""
if __name__ == "__main__":
import asyncio
asyncio.run(main())
var userInput = Console.ReadLine();
// Define semantic function inline.
string skPrompt = @"Summarize the provided unstructured text in a sentence that is easy to understand.
Text to summarize: ";
// create the function from the prompt
KernelFunction summarizeFunc = kernel.CreateFunctionFromPrompt(
promptTemplate: skPrompt,
functionName: "SummarizeText"
);
//then import into the current kernel
kernel.ImportPluginFromFunctions("SemanticFunctions", [summarizeFunc]);
Dito, mayroon kang isang template prompt na skPrompt
na nag-iiwan ng espasyo para sa input ng user, $userInput
. Pagkatapos ay nilikha mo ang kernel function na SummarizeText
at pagkatapos ay ini-import ito sa kernel gamit ang plugin name na SemanticFunctions
. Tandaan ang pangalan ng function na tumutulong sa Semantic Kernel na maunawaan kung ano ang ginagawa ng function at kung kailan ito dapat tawagin.
Native function: Mayroon ding mga native functions na maaaring tawagin ng framework nang direkta upang maisagawa ang gawain. Narito ang isang halimbawa ng ganitong function na kumukuha ng nilalaman mula sa isang file:
public class NativeFunctions {
[SKFunction, Description("Retrieve content from local file")]
public async Task<string> RetrieveLocalFile(string fileName, int maxSize = 5000)
{
string content = await File.ReadAllTextAsync(fileName);
if (content.Length <= maxSize) return content;
return content.Substring(0, maxSize);
}
}
//Import native function
string plugInName = "NativeFunction";
string functionName = "RetrieveLocalFile";
//To add the functions to a kernel use the following function
kernel.ImportPluginFromType<NativeFunctions>();
Memory: Inaabstrakto at pinapasimple ang context management para sa mga AI apps. Ang ideya sa memory ay ito ay isang bagay na dapat malaman ng LLM. Maaari mong i-store ang impormasyong ito sa isang vector store na nagtatapos bilang isang in-memory database o isang vector database o katulad. Narito ang isang halimbawa ng isang nap
Ang mga impormasyon ay iniimbak sa memory collection na SummarizedAzureDocs
. Ito ay isang napakasimpleng halimbawa, ngunit makikita mo kung paano maaaring mag-imbak ng impormasyon sa memorya para magamit ng LLM.
Iyan ang mga pangunahing kaalaman sa Semantic Kernel framework, pero paano naman ang Agent Framework?
Ang Azure AI Agent Service ay isang mas bagong karagdagan, ipinakilala sa Microsoft Ignite 2024. Pinapayagan nito ang pagbuo at pag-deploy ng mga AI agent gamit ang mas flexible na mga modelo, tulad ng direktang pagtawag sa mga open-source LLMs tulad ng Llama 3, Mistral, at Cohere.
Nagbibigay ang Azure AI Agent Service ng mas malakas na mekanismo ng seguridad para sa enterprise at mga pamamaraan ng pag-iimbak ng data, na angkop para sa mga aplikasyon ng enterprise.
Ito ay gumagana agad-agad sa mga multi-agent orchestration frameworks tulad ng AutoGen at Semantic Kernel.
Ang serbisyong ito ay kasalukuyang nasa Public Preview at sumusuporta sa Python at C# para sa pagbuo ng mga agent.
Gamit ang Semantic Kernel Python, maaari tayong lumikha ng Azure AI Agent gamit ang isang user-defined plugin:
import asyncio
from typing import Annotated
from azure.identity.aio import DefaultAzureCredential
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
from semantic_kernel.contents import ChatMessageContent
from semantic_kernel.contents import AuthorRole
from semantic_kernel.functions import kernel_function
# Define a sample plugin for the sample
class MenuPlugin:
"""A sample Menu Plugin used for the concept sample."""
@kernel_function(description="Provides a list of specials from the menu.")
def get_specials(self) -> Annotated[str, "Returns the specials from the menu."]:
return """
Special Soup: Clam Chowder
Special Salad: Cobb Salad
Special Drink: Chai Tea
"""
@kernel_function(description="Provides the price of the requested menu item.")
def get_item_price(
self, menu_item: Annotated[str, "The name of the menu item."]
) -> Annotated[str, "Returns the price of the menu item."]:
return "$9.99"
async def main() -> None:
ai_agent_settings = AzureAIAgentSettings.create()
async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
):
# Create agent definition
agent_definition = await client.agents.create_agent(
model=ai_agent_settings.model_deployment_name,
name="Host",
instructions="Answer questions about the menu.",
)
# Create the AzureAI Agent using the defined client and agent definition
agent = AzureAIAgent(
client=client,
definition=agent_definition,
plugins=[MenuPlugin()],
)
# Create a thread to hold the conversation
# If no thread is provided, a new thread will be
# created and returned with the initial response
thread: AzureAIAgentThread | None = None
user_inputs = [
"Hello",
"What is the special soup?",
"How much does that cost?",
"Thank you",
]
try:
for user_input in user_inputs:
print(f"# User: '{user_input}'")
# Invoke the agent for the specified thread
response = await agent.get_response(
messages=user_input,
thread_id=thread,
)
print(f"# {response.name}: {response.content}")
thread = response.thread
finally:
await thread.delete() if thread else None
await client.agents.delete_agent(agent.id)
if __name__ == "__main__":
asyncio.run(main())
Ang Azure AI Agent Service ay may mga sumusunod na pangunahing konsepto:
Agent. Ang Azure AI Agent Service ay pinagsasama sa Azure AI Foundry. Sa loob ng AI Foundry, ang isang AI Agent ay kumikilos bilang isang “matalinong” microservice na maaaring gamitin upang sumagot ng mga tanong (RAG), magsagawa ng mga aksyon, o ganap na mag-automate ng mga workflow. Nakakamit nito ito sa pamamagitan ng pagsasama ng kapangyarihan ng generative AI models sa mga tool na nagbibigay-daan dito na ma-access at makipag-ugnayan sa mga real-world data sources. Narito ang isang halimbawa ng 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,
)
Sa halimbawang ito, ang isang agent ay nilikha gamit ang modelong gpt-4o-mini
, isang pangalan na my-agent
, at mga tagubilin na You are helpful agent
. Ang agent ay may mga tool at resources upang magsagawa ng mga gawain sa interpretasyon ng code.
Thread at mga mensahe. Ang thread ay isa pang mahalagang konsepto. Ito ay kumakatawan sa isang pag-uusap o interaksyon sa pagitan ng isang agent at isang user. Ang mga thread ay maaaring gamitin upang subaybayan ang progreso ng pag-uusap, mag-imbak ng impormasyon sa konteksto, at pamahalaan ang estado ng interaksyon. Narito ang isang halimbawa ng 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}")
Sa nakaraang code, isang thread ang nilikha. Pagkatapos, isang mensahe ang ipinadala sa thread. Sa pamamagitan ng pagtawag sa create_and_process_run
, ang agent ay hiniling na magsagawa ng gawain sa thread. Sa huli, ang mga mensahe ay kinukuha at ina-log upang makita ang tugon ng agent. Ang mga mensahe ay nagpapakita ng progreso ng pag-uusap sa pagitan ng user at ng agent. Mahalagang maunawaan na ang mga mensahe ay maaaring iba’t ibang uri tulad ng text, image, o file, na ang resulta ng gawain ng agent ay halimbawa isang imahe o text response. Bilang developer, maaari mong gamitin ang impormasyong ito upang iproseso pa ang tugon o ipakita ito sa user.
Integrasyon sa iba pang AI frameworks. Ang Azure AI Agent Service ay maaaring makipag-ugnayan sa iba pang frameworks tulad ng AutoGen at Semantic Kernel, na nangangahulugang maaari kang bumuo ng bahagi ng iyong app sa isa sa mga frameworks na ito at halimbawa gamitin ang Agent Service bilang isang orchestrator o maaari mong buuin ang lahat sa Agent Service.
Mga Gamit: Ang Azure AI Agent Service ay idinisenyo para sa mga aplikasyon ng enterprise na nangangailangan ng secure, scalable, at flexible na AI agent deployment.
Mukhang may maraming pagkakapareho sa pagitan ng mga frameworks na ito, ngunit may ilang pangunahing pagkakaiba sa kanilang disenyo, kakayahan, at target na mga gamit:
Hindi pa rin sigurado kung alin ang pipiliin?
Tingnan natin kung makakatulong kami sa pamamagitan ng pagdaan sa ilang karaniwang mga gamit:
Q: Ako ay nag-eeksperimento, natututo, at bumubuo ng proof-of-concept agent applications, at gusto kong makabuo at makapag-eksperimento nang mabilis
A: Ang AutoGen ay magiging magandang pagpipilian para sa senaryong ito, dahil nakatuon ito sa event-driven, distributed agentic applications at sumusuporta sa advanced multi-agent design patterns.
Q: Ano ang nagpapaganda sa AutoGen kumpara sa Semantic Kernel at Azure AI Agent Service para sa gamit na ito?
A: Ang AutoGen ay partikular na idinisenyo para sa event-driven, distributed agentic applications, na angkop para sa pag-automate ng code generation at data analysis tasks. Nagbibigay ito ng kinakailangang mga tool at kakayahan upang makabuo ng mga kumplikadong multi-agent systems nang mahusay.
Q: Mukhang ang Azure AI Agent Service ay maaaring gumana rin dito, mayroon itong mga tool para sa code generation at iba pa?
A: Oo, ang Azure AI Agent Service ay isang platform service para sa mga agent at may built-in na kakayahan para sa maraming modelo, Azure AI Search, Bing Search, at Azure Functions. Pinapadali nito ang pagbuo ng iyong mga agent sa Foundry Portal at ang pag-deploy ng mga ito sa scale.
Q: Nalilito pa rin ako, bigyan mo na lang ako ng isang opsyon
A: Isang magandang pagpipilian ay buuin ang iyong aplikasyon sa Semantic Kernel muna at pagkatapos ay gamitin ang Azure AI Agent Service upang i-deploy ang iyong agent. Ang diskarte na ito ay nagbibigay-daan sa iyo na madaling i-persist ang iyong mga agent habang ginagamit ang kapangyarihan ng pagbuo ng multi-agent systems sa Semantic Kernel. Bukod dito, ang Semantic Kernel ay may connector sa AutoGen, na nagpapadali sa paggamit ng parehong frameworks nang magkasama.
I-summarize natin ang mga pangunahing pagkakaiba sa isang talahanayan:
Framework | Pokus | Pangunahing Konsepto | Mga Gamit |
---|---|---|---|
AutoGen | Event-driven, distributed agentic applications | Agents, Personas, Functions, Data | Code generation, data analysis tasks |
Semantic Kernel | Pag-unawa at pagbuo ng human-like na text content | Agents, Modular Components, Collaboration | Natural language understanding, content generation |
Azure AI Agent Service | Flexible models, enterprise security, Code generation, Tool calling | Modularity, Collaboration, Process Orchestration | Secure, scalable, at flexible na AI agent deployment |
Ano ang ideal na gamit para sa bawat isa sa mga frameworks na ito?
Ang sagot ay oo, maaari mong direktang i-integrate ang iyong mga kasalukuyang Azure ecosystem tools sa Azure AI Agent Service, lalo na dahil ito ay itinayo upang gumana nang seamless sa iba pang Azure services. Halimbawa, maaari mong i-integrate ang Bing, Azure AI Search, at Azure Functions. Mayroon ding malalim na integrasyon sa Azure AI Foundry.
Para sa AutoGen at Semantic Kernel, maaari mo ring i-integrate sa Azure services, ngunit maaaring kailanganin mong tawagin ang Azure services mula sa iyong code. Isa pang paraan ng integrasyon ay ang paggamit ng Azure SDKs upang makipag-ugnayan sa Azure services mula sa iyong mga agent. Bukod dito, tulad ng nabanggit, maaari mong gamitin ang Azure AI Agent Service bilang isang orchestrator para sa iyong mga agent na binuo sa AutoGen o Semantic Kernel na magbibigay ng madaling access sa Azure ecosystem.
Sumali sa Azure AI Foundry Discord upang makipagtagpo sa iba pang mga nag-aaral, dumalo sa office hours, at makuha ang sagot sa iyong mga tanong tungkol sa AI Agents.
Introduction to AI Agents and Agent Use Cases
Understanding Agentic Design Patterns
Paunawa:
Ang dokumentong ito ay isinalin gamit ang AI translation service na Co-op Translator. Bagama’t sinisikap naming maging tumpak, mangyaring tandaan na ang mga awtomatikong pagsasalin ay maaaring maglaman ng mga pagkakamali o hindi pagkakatugma. Ang orihinal na dokumento sa kanyang katutubong wika ang dapat ituring na opisyal na pinagmulan. Para sa mahalagang impormasyon, inirerekomenda ang propesyonal na pagsasalin ng tao. Hindi kami mananagot sa anumang hindi pagkakaunawaan o maling interpretasyon na dulot ng paggamit ng pagsasaling ito.