-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Feature: Function calling w/ Context #9135
Comments
@brandonh-msft you could try create an Auto Function Invocation Filter, this will give you access to the function that is being called and also the associated Chat History, see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Filtering/AutoFunctionInvocationFiltering.cs, you could pass the ImageContent via KernelArguments for your specific function. Let me know how this goes. |
I was with you until "pass the ImageContent via KernelArguments for your specific function" When observing
It seems to me like we need a pattern akin to Azure Functions' Thanks |
Here's what I came up with, would love your thoughts: Filter: internal class ContextPopulateInvocationFilter : IAutoFunctionInvocationFilter
{
private const string FunctionContextKey = "__functionContext";
public Task OnAutoFunctionInvocationAsync(AutoFunctionInvocationContext context, Func<AutoFunctionInvocationContext, Task> next)
{
if (context.Arguments is not null)
{
context.Arguments[FunctionContextKey] = context;
}
return next(context);
}
} Function registration: _kernel.CreateFunctionFromMethod(async (Guid conversationId, AutoFunctionInvocationContext __functionContext) => {
...
}, parameters: [new ("conversationId") { IsRequired = true, ParameterType = typeof(Guid), Description = "The ID of the Conversation as specified by the initial context to the system" }]); I have access to the entirety of the invocation context in this manner. Would there be any unintended side effects of this approach? The biggest caveat is that I am dependent upon |
The above approach resulted in me getting a serialization error on |
So, adding the whole Chat History resulted in recursive function invocations - I'm guessing because the history included items that requested tool calls. So, instead of passing the whole thing I simply pulled out all assistant and user messages that didn't have tool calls requested. This seems to have done the trick. If I need anything else from the Context, I'll have to manually add it to arguments as well. If we could get Context to be serializable (not hit the cancellationToken issue) or create a purpose-built context for this, it seems that'd be much more ideal. |
This issue is stale because it has been open for 90 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
Scenario
Today, it seems the only things I can pass to a function call are JSON-serializable objects. However, in this scenario, I can send the LLM the image data via
ImageContent
message items but the LLM can only come back with, say, a filename that I surround this content with - not the content itself. This means that even if my Agent Function takesBinaryData
as an input, the LLM doesn't provide it in its function call request. It can provide something like "Filename: X.png" which I could correlate back to the user's input, though, but I am unable to get back to that input to use it in the actual call to the agent.So, enabling some way for me to get back to the original message which triggered the function call request is necessary for this scenario. I'm thinking something along the lines of an auto-injected parameter to the function, if the developer provides it on the signature (a la
CancellationToken
)The text was updated successfully, but these errors were encountered: