messages.append(ChatMessage.from_user(message)) response = chat_generator.run(messages=messages) if response and "" in response["replies"][0].content: function_calls = extract_tool_calls(response["replies"][0].content) for function_call in function_calls: # Parse function calling information function_name = function_call["name"] function_args = function_call["arguments"] # Find the corresponding function and call it with the given arguments function_to_call = available_functions[function_name] function_response = function_to_call(**function_args) # Append function response to the messages list using `ChatMessage.from_function` messages.append(ChatMessage.from_function(content=json.dumps(function_response), name=function_name)) response = chat_generator.run(messages=messages)