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

Python: Bug: The 'get_chat_message_contents' returns with a tool_calls message without calling the plugin's function(s) (intermittently) #8712

Open
samelhousseini opened this issue Sep 13, 2024 · 2 comments
Assignees
Labels
bug Something isn't working filters Anything related to filters python Pull requests for the Python Semantic Kernel

Comments

@samelhousseini
Copy link

samelhousseini commented Sep 13, 2024

Describe the bug
This is an intermittent problem and hard to reproduce with exact steps.

To Reproduce
Steps to reproduce the behavior:
The "chat_completion.get_chat_message_contents" function call sometimes just returns with a tool_calls message but without calling the plugin's functions described in the tool_calls. The chat history indicates that the last message added is a "tool_calls" but no function result message is added afterwards.

Expected behavior
Since there's a tool calls, the expected behavior is that the function call workflow proceeds as expected with a function call and a function result, but then all I get is a tool_calls message from "chat_completion.get_chat_message_contents"

result = (await self.chat_completion.get_chat_message_contents(
                chat_history=self.history,
                settings=self.execution_settings,
                kernel=self.kernel,
                arguments=KernelArguments(),
                temperature=0.2
            ))[0]

When inspecting the results above, the get_chat_message_contents is returning without calling the plugin's functions:

image

Screenshots
Screenshot below showing that the call to get_chat_message_contents just returned with an empty string, because the ChatMessageContent is a function call "tool_calls".

print("Assistant > " + str(result))

And that the call to the filter did not happen.

Platform

  • SK: semantic-kernel 1.8.3 python package
  • OS: Windows
  • IDE: VS Code
  • Language: Python

image

Update:

The following block of code is a temp fix of this problem:

        counter = 0

        while True:
            print(f"-------------- Attempting response {counter}")
            result = (await self.chat_completion.get_chat_message_contents(
                chat_history=self.history,
                settings=self.execution_settings,
                kernel=self.kernel,
                arguments=KernelArguments(),
                temperature=0.2
            ))[0]

            if result.finish_reason == 'tool_calls':
                self.history.add_message(result)
                function_results = []

                for item in result.items:
                    content = await self.kernel.plugins[item.plugin_name].functions[item.function_name].method(**json.loads(item.arguments))
                    print("Content from Function Call - ", content)
                    function_results.append(
                        FunctionResultContent(
                            id=item.id, name=item.name, result=str(content)
                        )
                    )                    
                    
                self.history.add_message(
                    ChatMessageContent(
                        role = AuthorRole.TOOL,
                        items = function_results
                    )
                )
            else:
                break

            counter += 1

            if counter > 25: break

        # Add the message from the agent to the chat history
        self.history.add_message(result)
@samelhousseini samelhousseini added the bug Something isn't working label Sep 13, 2024
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels Sep 13, 2024
@github-actions github-actions bot changed the title Bug: Python - The AUTO_FUNCTION_INVOCATION filter fails to be called (intermittently) Python: Bug: Python - The AUTO_FUNCTION_INVOCATION filter fails to be called (intermittently) Sep 13, 2024
@samelhousseini samelhousseini changed the title Python: Bug: Python - The AUTO_FUNCTION_INVOCATION filter fails to be called (intermittently) Python: Bug: The 'get_chat_message_contents' just returns an empty string without a a function call (intermittently) Sep 16, 2024
@samelhousseini samelhousseini changed the title Python: Bug: The 'get_chat_message_contents' just returns an empty string without a a function call (intermittently) Python: Bug: The 'get_chat_message_contents' returns with a tool_calls message without calling the plugin's function(s) (intermittently) Sep 16, 2024
@moonbox3 moonbox3 added filters Anything related to filters and removed triage labels Sep 16, 2024
@eavanvalkenburg
Copy link
Member

@samelhousseini what are the settings you are using?

@samelhousseini
Copy link
Author

samelhousseini commented Sep 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working filters Anything related to filters python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

No branches or pull requests

4 participants