-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Python: Bug: Agent as the kernel function doesn't pass arguments #11638
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
Comments
but the kernel function can take multiple parameters , is this issue related with function calling ? |
Hi @HuskyDanny, Thank you for creating the issue! Looks like you are trying to invoke an agent as a kernel function via the kernel, where the function only accepts one argument which is In SK, you need to provide the arguments as key-value pairs through an In the case of the agent as a function, you only need the At this point, when you are using agent as a function, it's really meant to be a fire-and-forget process. Could you share more about your use case on why you need to retain the agent context between calls when it's used as a function? |
I would say it is related to kernel function use for the agent, even though the kernel arguments can have multiple, but the kernel function parameters for agent doens't include the arguments keyword. |
Hi @TaoChenOSU , yes your observation is right on. The reason why I want to do this is mainly because I want to manage the agent the same way as the plugin and functions. In my application, I invoke SK capability through kernel, so I want to stick to this pattern. Right now I am seeing the agent as an object passing arounds, I feel it is more clean we manage all things through kernel & name. And my application is more like stateless server so it wants to take extra context for each request, so that why I need to pass the arguments. Speaking of fire & forget, I think even with the arguments, the pattern is still fire & forget just with extra context from outside? May I know why it is designed in this way? |
Please note the below is AI generated for better readability:
Okay, let's break down the problem you're encountering when trying to invoke your
Nl2sqlAgent
as a kernel function while passing custom arguments and a thread object.Context
Agent Creation and Registration (
@semantic_kernel_manager.py
):ChatCompletionAgent
namedNl2sqlAgent
.kernel.add_plugin(agent, "Agents")
.Automatic Kernel Function Creation (
@agent.py
):Agent
base class usesmodel_post_init
to automatically create a kernel function.@kernel_function
and uses the agent'sname
(Nl2sqlAgent
in your case) as the function name within the plugin._as_kernel_function
) only acceptsmessages
andinstructions_override
. It then calls the agent'sget_response
method internally.Attempted Invocation (
@nl2sql.py
):Nl2sql
scenario, you try to invoke the agent usingkernel.invoke
.plugin_name="Agents"
(where you registered the agent) andfunction_name="Nl2sqlAgent"
(the name of the automatically generated function).arguments
(containingquery
,chat_id
,database_type
, etc.) and athread
object to this invocation. You also passmessages=latest_question
.Problem Description
The core issue is a mismatch between the parameters you are trying to pass via
kernel.invoke
and the actual signature of the underlying kernel function (_as_kernel_function
) that gets called.Agent._as_kernel_function
) is designed for simple invocation and only acceptsmessages
(the user input) and an optionalinstructions_override
.kernel.invoke(..., arguments=arguments, thread=agent_thread, messages=...)
, you are passing parameters (arguments
object,thread
object) that the target function (_as_kernel_function
) is not defined to accept. The kernel's invocation mechanism doesn't automatically know how to map these extra parameters to the agent's internal methods (get_response
orinvoke
) when the agent is called as a kernel function.messages
Usage: Themessages
parameter in thekernel.invoke
call innl2sql.py
is also likely incorrect. The_as_kernel_function
expects the actual message content to be passed to itsmessages
parameter, which usually happens through the primary input mechanism ofkernel.invoke
(often mapping theinput
argument or specific arguments defined in the function signature), not through a separatemessages
keyword argument tokernel.invoke
itself.In essence, you are trying to use the kernel's function invocation system (
kernel.invoke
) to pass complex objects (thread
,KernelArguments
) to a function that was automatically generated with a much simpler signature, only intended to handle basic message input. This direct invocation path doesn't support passing the necessarythread
context or the detailedKernelArguments
required by yourNl2sqlAgent
's logic when interacting via its native methods.------ User question:
So the final arugment I have is only having the messages as the parameters:
My question is I want to unify the way we call either plugin, agent or function through kernel in my project management, is my attempt aligned with the practices in SK? If so, can we let the agent accept the reserved arguments? Otherwise, my agent cannot continue the previous context.
The text was updated successfully, but these errors were encountered: