Mengonfigurasi Agen dengan Plugin Kernel Semantik (Eksperimental)
Peringatan
Kerangka Kerja Agen Kernel Semantik bersifat eksperimental, masih dalam pengembangan dan dapat berubah.
Fungsi dan Plugin dalam Kernel Semantik
Pemanggilan fungsi adalah alat canggih yang memungkinkan pengembang untuk menambahkan fungsionalitas kustom dan memperluas kemampuan aplikasi AI. Arsitektur Plugin Kernel Semantik menawarkan kerangka kerja fleksibel untuk mendukung Pemanggilan Fungsi. Untuk Agen, mengintegrasikan Plugin dan Pemanggilan Fungsi dibangun di atas fitur Semantic Kernel dasar ini.
Setelah dikonfigurasi, agen akan memilih kapan dan cara memanggil fungsi yang tersedia, seperti halnya dalam penggunaan apa pun di luar Kerangka Kerja Agen.
Agen saat ini tidak tersedia di Java.
Menambahkan Plugin ke Agen
Plugin apa pun yang tersedia untuk Agen dikelola dalam instans Kernel masing-masing. Penyiapan ini memungkinkan setiap Agen untuk mengakses fungsionalitas yang berbeda berdasarkan peran spesifiknya.
Plugin dapat ditambahkan ke Kernel baik sebelum atau sesudah Agen dibuat. Proses inisialisasi Plugin mengikuti pola yang sama yang digunakan untuk implementasi Kernel Semantik apa pun, memungkinkan konsistensi dan kemudahan penggunaan dalam mengelola kemampuan AI.
Catatan: Untuk Agen Penyelesaian Obrolan, mode panggilan fungsi harus diaktifkan secara eksplisit. Buka agen Asisten AI selalu didasarkan pada panggilan fungsi otomatis.
// Factory method to product an agent with a specific role.
// Could be incorporated into DI initialization.
ChatCompletionAgent CreateSpecificAgent(Kernel kernel, string credentials)
{
// Clone kernel instance to allow for agent specific plug-in definition
Kernel agentKernel = kernel.Clone();
// Initialize plug-in from type
agentKernel.CreatePluginFromType<StatelessPlugin>();
// Initialize plug-in from object
agentKernel.CreatePluginFromObject(new StatefulPlugin(credentials));
// Create the agent
return
new ChatCompletionAgent()
{
Name = "<agent name>",
Instructions = "<agent instructions>",
Kernel = agentKernel,
Arguments = new KernelArguments(
new OpenAIPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
})
};
}
# Create the instance of the Kernel
kernel = Kernel()
# Define the service ID
service_id = "<service ID>"
# Add the chat completion service to the Kernel
kernel.add_service(AzureChatCompletion(service_id=service_id))
# Get the AI Service settings for the specified service_id
settings = kernel.get_prompt_execution_settings_from_service_id(service_id=service_id)
# Configure the function choice behavior to auto invoke kernel functions
settings.function_choice_behavior = FunctionChoiceBehavior.Auto()
# Add the Plugin to the Kernel
kernel.add_plugin(SamplePlugin(), plugin_name="<plugin name>")
# Create the agent
agent = ChatCompletionAgent(
service_id=service_id,
kernel=kernel,
name=<agent name>,
instructions=<agent instructions>,
execution_settings=settings,
)
Agen saat ini tidak tersedia di Java.
Menambahkan Fungsi ke Agen
Plugin adalah pendekatan paling umum untuk mengonfigurasi Panggilan Fungsi. Namun, fungsi individu juga dapat disediakan secara independen termasuk fungsi prompt.
// Factory method to product an agent with a specific role.
// Could be incorporated into DI initialization.
ChatCompletionAgent CreateSpecificAgent(Kernel kernel)
{
// Clone kernel instance to allow for agent specific plug-in definition
Kernel agentKernel = kernel.Clone();
// Initialize plug-in from a static function
agentKernel.CreateFunctionFromMethod(StatelessPlugin.AStaticMethod);
// Initialize plug-in from a prompt
agentKernel.CreateFunctionFromPrompt("<your prompt instructiosn>");
// Create the agent
return
new ChatCompletionAgent()
{
Name = "<agent name>",
Instructions = "<agent instructions>",
Kernel = agentKernel,
Arguments = new KernelArguments(
new OpenAIPromptExecutionSettings()
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
})
};
}
# Create the instance of the Kernel
kernel = Kernel()
# Define the service ID
service_id = "<service ID>"
# Add the chat completion service to the Kernel
kernel.add_service(AzureChatCompletion(service_id=service_id))
# Get the AI Service settings for the specified service_id
settings = kernel.get_prompt_execution_settings_from_service_id(service_id=service_id)
# Configure the function choice behavior to auto invoke kernel functions
settings.function_choice_behavior = FunctionChoiceBehavior.Auto()
# Add the Plugin to the Kernel
kernel.add_plugin(SamplePlugin(), plugin_name="<plugin name>")
# Create the agent
agent = ChatCompletionAgent(
service_id=service_id,
kernel=kernel,
name=<agent name>,
instructions=<agent instructions>,
execution_settings=settings,
)
Agen saat ini tidak tersedia di Java.
Batasan untuk Panggilan Fungsi Agen
Saat langsung memanggilAgen Penyelesaian Obrolan, semua Perilaku Pilihan Fungsi didukung. Namun, saat menggunakan Asisten AI Terbuka atau Obrolan Agen, hanya Panggilan Fungsi Otomatis yang saat ini tersedia.
Panduan cara kerja
Untuk contoh end-to-end untuk menggunakan panggilan fungsi, lihat: