Skip to content
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

.Net: New Feature: How to pass the object returned by the first call of function calling to the function called the second time? #10669

Open
1754581267 opened this issue Feb 25, 2025 · 4 comments
Assignees
Labels
function_calling .NET Issue or Pull requests regarding .NET code

Comments

@1754581267
Copy link

How to pass the object returned by the first call of function calling to the function called the second time? Similar to: the first function generates a cat, and the second function gets the name of the cat

Image

@1754581267 1754581267 changed the title New Feature: How to pass the object returned by the first call of function calling to the function called the second time? Similar to: the first function generates a cat, and the second function gets the name of the cat New Feature: How to pass the object returned by the first call of function calling to the function called the second time? Feb 25, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code function_calling labels Feb 25, 2025
@github-actions github-actions bot changed the title New Feature: How to pass the object returned by the first call of function calling to the function called the second time? .Net: New Feature: How to pass the object returned by the first call of function calling to the function called the second time? Feb 25, 2025
@markwallace-microsoft
Copy link
Member

@SergeyMenshykh do we have a sample showing how to do this?

@SergeyMenshykh
Copy link
Member

@1754581267, in your second function, do you need to access exactly the same instance returned by the first function, or does it not matter as long as all the properties of the object the second function is called with are equal to the ones returned by the first function?

Please provide the functions and the Cat class signatures along with the value returned by the first function and the argument(s) the second function is called with.

CC: @moonbox3

@SergeyMenshykh SergeyMenshykh moved this to Sprint: Planned in Semantic Kernel Feb 27, 2025
@SergeyMenshykh SergeyMenshykh moved this from Sprint: Planned to Sprint: In Progress in Semantic Kernel Feb 27, 2025
@1754581267
Copy link
Author

The SK I am using is python version. I need to let SK pass the object created in the function call correctly to the function used in the subsequent conversation. Cat is an example. Now the situation is that the parameters received by the subsequent function should be the object, but now it is a string

from semantic_kernel.functions import kernel_function


class Cat:
    name = ""
    age = 0

    def __init__(self):
        self.name = ""
        self.age = 0

    def createCat(self, name: str, age: int) -> object:
        """
        creates a new Cat object
        :param name: 
        :param age: 
        :return: object
        """
        print("Creating cat")
        self.name = name + "159"
        self.age = age

        return self

    def get_name(self, o: object) -> str:
        """
        gets name of the Cat object
        :param o: Cat
        :return:
        """
        print("Getting name", o)
        return o.name
from semantic_kernel.functions import kernel_function

from script.entity.Cat import Cat


class TestPlugin:

    @kernel_function()
    def create_cat(self, name: str, age: int) -> object:
        """
        creates a new Cat object
        :param name:
        :param age:
        :return:
        """
        cat = Cat().createCat(name, age)
        return cat

    @kernel_function()
    def get_name(self, cat: Cat) -> str:
        """
        gets name of the Cat object
        :return: str
        """
        return Cat.get_name(cat)


if __name__ == '__main__':
    cat = TestPlugin().create_cat('test', 12)
    print(cat.get_name())

The conversation is:

  1. create a cat
  2. Get the name of this cat

@1754581267
Copy link
Author

I solved this problem in my own way, but I want to get the official solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function_calling .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: In Progress
Development

No branches or pull requests

3 participants