Skip to content

Commit c03c058

Browse files
committed
Updates to callout reserved param names with Python function calling.
1 parent 7666b33 commit c03c058

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

  • semantic-kernel/concepts/ai-services/chat-completion/function-calling

semantic-kernel/concepts/ai-services/chat-completion/function-calling/index.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,41 @@ kernel.add_plugin(OrderPizzaPlugin(pizza_service, user_context, payment_service)
207207
> [!NOTE]
208208
> Only functions with the `kernel_function` decorator will be serialized and sent to the model. This allows you to have helper functions that are not exposed to the model.
209209
210+
## Reserved Parameter Names for Auto Function Calling
211+
212+
When using auto function calling in KernelFunctions, certain parameter names are **reserved** and receive special handling. These reserved names allow you to automatically access key objects required for function execution.
213+
214+
### Reserved Names
215+
216+
The following parameter names are reserved:
217+
- `kernel`
218+
- `service`
219+
- `execution_settings`
220+
- `arguments`
221+
222+
### How They Work
223+
224+
During function invocation, the method [`gather_function_parameters`](https://github.com/microsoft/semantic-kernel/blob/main/python/semantic_kernel/functions/kernel_function_from_method.py#L148) inspects each parameter. If the parameter's name matches one of the reserved names, it is populated with specific objects:
225+
226+
- **`kernel`**: Injected with the kernel object.
227+
- **`service`**: Populated with the AI service selected based on the provided arguments.
228+
- **`execution_settings`**: Contains settings pertinent to the function's execution.
229+
- **`arguments`**: Receives the entire set of kernel arguments passed during invocation.
230+
231+
This design ensures that these parameters are automatically managed, eliminating the need for manual extraction or assignment.
232+
233+
### Example Usage
234+
235+
Consider the following example:
236+
237+
```python
238+
class SimplePlugin:
239+
@kernel_function(name="GetWeather", description="Get the weather for a location.")
240+
async def get_the_weather(self, location: str, arguments: KernelArguments) -> str:
241+
# The 'arguments' parameter is reserved and automatically populated with KernelArguments.
242+
return f"Received user input: {location}, the weather is nice!"
243+
```
244+
210245
::: zone-end
211246

212247
::: zone pivot="programming-language-java"

0 commit comments

Comments
 (0)