Skip to content

Conversation

@heyitsaamir
Copy link
Collaborator

@heyitsaamir heyitsaamir commented Nov 22, 2025

We wrap our AI functions such that we can call the AI plugins etc.
But if there are no parameters, we call the function like foo(). However, the wrapped function always has 1 positional argument. So python throws. This fixes that bug.

PR Dependency Tree

This tree was auto-generated by Charcoal

Copilot AI review requested due to automatic review settings November 22, 2025 07:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where AI functions with no parameters would fail when wrapped with plugin hooks. The issue occurred because the wrapped function always expected a positional argument (params), but functions with parameter_schema=None are called without arguments, causing Python to throw a TypeError.

Key Changes

  • Modified _wrap_function_handler to accept parameter_schema parameter and return a no-argument lambda wrapper when parameter_schema is None
  • Added comprehensive test coverage for no-parameter functions with plugins
  • Fixed unrelated documentation error in HttpPlugin example

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/ai/src/microsoft/teams/ai/chat_prompt.py Added parameter_schema parameter to _wrap_function_handler and implemented lambda wrapper for no-parameter functions to fix the bug
packages/ai/tests/test_chat_prompt.py Added new test case test_function_with_no_parameters_wrapped_with_plugins to verify the fix works correctly with plugins
packages/apps/src/microsoft/teams/apps/http_plugin.py Removed invalid app_id parameter from documentation example (unrelated documentation fix)
Comments suppressed due to low confidence (1)

packages/ai/src/microsoft/teams/ai/chat_prompt.py:210

  • The docstring is missing documentation for the newly added parameter_schema parameter. Please add it to the Args section:
Args:
    original_handler: The original function handler to wrap
    function_name: Name of the function for plugin identification
    parameter_schema: Type schema for function parameters, or None if function has no parameters

Returns:
    Wrapped handler that includes plugin hook execution
        """
        Wrap a function handler with plugin before/after hooks.

        Creates a new handler that executes plugin hooks before and after
        the original function, allowing plugins to modify parameters and results.

        Args:
            original_handler: The original function handler to wrap
            function_name: Name of the function for plugin identification

        Returns:
            Wrapped handler that includes plugin hook execution
        """

@heyitsaamir heyitsaamir merged commit 2aadc91 into main Nov 24, 2025
12 checks passed
@heyitsaamir heyitsaamir deleted the aamirj/fixWrapped branch November 24, 2025 17:46
@heyitsaamir heyitsaamir mentioned this pull request Dec 9, 2025
heyitsaamir added a commit that referenced this pull request Dec 9, 2025
## Release 2.0.0a7

### Changes

- update react and react-dom to 19.2.1 (#233)
- Move to microsoft_teams namespace (#226)
- Simplify setting http response after activity processing  (#218)
- Add TeamsChannelAccount type for Teams-specific APIs (#230)
- Updating mcpplugin reference in README.md (#229)
- Bring back bot builder example (#225)
- Fix choices_data alias to use "choices.data" instead of "choicesData"
(#224)
- [docs] botbuilder package README fixes (#223)
- Fix calling AI functions with no parameters (#221)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants