Agents configureren met Semantische kernelinvoegtoepassingen (experimenteel)
Waarschuwing
Het Semantic Kernel Agent Framework is experimenteel, nog steeds in ontwikkeling en kan worden gewijzigd.
Functies en invoegtoepassingen in Semantische kernel
Functie-aanroepen is een krachtig hulpprogramma waarmee ontwikkelaars aangepaste functionaliteiten kunnen toevoegen en de mogelijkheden van AI-toepassingen kunnen uitbreiden. De architectuur van de Semantic Kernel Plugin biedt een flexibel framework ter ondersteuning van functiegesprekken. Voor een agent is de integratie van invoegtoepassingen en functieaanroepen gebaseerd op deze fundamentele Semantische kernelfunctie.
Zodra deze is geconfigureerd, kiest een agent wanneer en hoe een beschikbare functie moet worden aangeroepen, zoals in elk gebruik buiten het Agent Framework.
Agents zijn momenteel niet beschikbaar in Java.
Invoegtoepassingen toevoegen aan een agent
Elke invoegtoepassing die beschikbaar is voor een agent wordt beheerd binnen het respectieve kernelexemplaren. Met deze instelling kan elke agent toegang krijgen tot verschillende functies op basis van de specifieke rol.
Invoegtoepassingen kunnen worden toegevoegd aan de kernel voor of nadat de agent is gemaakt. Het proces van initialiseren van invoegtoepassingen volgt dezelfde patronen die worden gebruikt voor elke Semantische kernel-implementatie , waardoor consistentie en gebruiksgemak mogelijk zijn bij het beheren van AI-mogelijkheden.
Opmerking: Voor een agent voor chatvoltooiing moet de modus voor het aanroepen van functies expliciet zijn ingeschakeld. Open AI Assistant-agent is altijd gebaseerd op het automatisch aanroepen van functies.
// 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,
)
Agents zijn momenteel niet beschikbaar in Java.
Functies toevoegen aan een agent
Een invoegtoepassing is de meest voorkomende methode voor het configureren van functie-aanroepen. Afzonderlijke functies kunnen echter ook onafhankelijk worden geleverd, inclusief promptfuncties.
// 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,
)
Agents zijn momenteel niet beschikbaar in Java.
Beperkingen voor het aanroepen van agentfuncties
Wanneer u rechtstreeks eenchatvoltooiingsagent aanroept, worden alle functiekeuzegedragen ondersteund. Wanneer u echter een Open AI Assistant of Agent Chat gebruikt, is momenteel alleen automatische functieaanroepen beschikbaar.
Uitleg:
Zie voor een end-to-end-voorbeeld voor het gebruik van functieaanroepen: