microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.38k stars 3.14k forks source link

New Feature: Anthropic Function Calling #8893

Open andrewldesousa opened 23 hours ago

andrewldesousa commented 23 hours ago

Extend Anthropic connector to support function calling

andrewldesousa commented 23 hours ago

working on this now, will try to open PR this week!

markwallace-microsoft commented 4 hours ago

@andrewldesousa We have new function calling abstractions and a reusable implementation. I've asked @SergeyMenshykh to respond here with details of how to use this. We want to consolidate all of our function calling implementations and these abstractions will make the job of adding this functionality much easier.

SergeyMenshykh commented 2 hours ago

Hi @andrewldesousa, thanks for your contribution to make SK better.

As Mark said, we have the new function calling abstraction that we released this week - https://devblogs.microsoft.com/semantic-kernel/new-function-calling-model-available-in-net-for-semantic-kernel/ and that we plan to develop and use in all SK connectors from now on.

The function call handling and function invocation functionality are encapsulated in the new FunctionCallsProcessor class. Connectors should use this class to obtain function calling configuration and process function calls and invoke funcitons.

After obtaining SK function calling configuration, connectors should map it to AI model specific API configuration model classes as it's done for {Azure}OpenAI connectors - mapping of SK model to OpenAI one.

Additionally, connectors should map AI model-specific API function call model classes to the SK ones and add them to the chat message content Items collection as is done here - map tool calls to function call contents. Similarly, map SK function result contents to AI model-specific API function result model classes as is done here - map function result content to tool chat message.

Please disregard all the code that uses the current function calling model represented by the ToolCallBehavior class when you encounter it in a few other SK connectors. It's there for backward compatibility and should not be migrated to the new SK connectors. Feel free to contact us if you have questions.